/** * The docker API allows for identification of a container by name or id. * This method will return the docker container id (which is stored in the * externalId field of the instance) if it is available. If it isn't * available, the instance uuid will be returned, since that is currently * used as the name for docker containers that do not have the docker id * set. * * @param instance * @return A string suitable for identifying a container in the docker API. */ public static String getDockerIdentifier(Instance instance) { return !StringUtils.isEmpty(instance.getExternalId()) ? instance.getExternalId() : instance.getUuid(); } }
private String checkContainerNetwork(String inspectNetMode, Instance instance, Map<String, Object> data) { if (!StringUtils.startsWith(inspectNetMode, NetworkConstants.NETWORK_MODE_CONTAINER)) return null; String[] parts = StringUtils.split(inspectNetMode, ":", 2); String targetContainer = null; if (parts.length == 2) { targetContainer = parts[1]; Instance netFromInstance = instanceDao.getInstanceByUuidOrExternalId(instance.getAccountId(), targetContainer, targetContainer); if (netFromInstance == null) { Event inspectEvent = newInspectEvent(targetContainer, targetContainer); Object inspectObj = callAgentForInspect(data, inspectEvent); Map<String, Object> inspect = CollectionUtils.toMap(inspectObj); String uuid = getRancherUuidLabel(inspect, null); String externalId = inspect.get("Id") != null ? inspect.get("Id").toString() : null; netFromInstance = instanceDao.getInstanceByUuidOrExternalId(instance.getAccountId(), uuid, externalId); } if (netFromInstance != null) { DataAccessor.fields(instance).withKey(FIELD_NETWORK_CONTAINER_ID).set(netFromInstance.getId()); return NetworkConstants.NETWORK_MODE_CONTAINER; } } log.warn("Problem configuring container networking for container [externalId: {}]. Could not find target container: [{}].", instance.getExternalId(), targetContainer); return NetworkConstants.NETWORK_MODE_NONE; }
this.name = instance.getName(); this.uuid = instance.getUuid(); this.external_id = instance.getExternalId(); this.system = instance.getSystem(); Map<String, String> labels = DataAccessor.fields(instance).withKey(InstanceConstants.FIELD_LABELS)
setUserdata(from.getUserdata()); setRegistryCredentialId(from.getRegistryCredentialId()); setExternalId(from.getExternalId()); setNativeContainer(from.getNativeContainer()); setNetworkContainerId(from.getNetworkContainerId());