public static String getInstanceName(Instance instance) { if (instance != null && instance.getRemoved() == null) { return instance.getUuid(); } else { return null; } }
/** * 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(); } }
@Override public Map<String, Object> getOsMetadata(Instance instance, Map<String, Object> metadata) { Map<String, Object> data = new HashMap<>(); data.put("availability_zone", "nova"); data.put("files", Collections.EMPTY_LIST); data.put("public_keys", new HashMap<>()); data.put("meta", new HashMap<>()); data.put("uuid", instance.getUuid()); String hostname = org.apache.commons.lang3.ObjectUtils.toString(metadata.get("hostname"), null); if (hostname != null) { data.put("hostname", hostname); data.put("name", hostname.split("[.]")[0]); } Map<String, Object> keys = CollectionUtils.toMap(metadata.get("public-keys")); for (Map.Entry<String, Object> entry : keys.entrySet()) { Map<String, Object> value = CollectionUtils.toMap(entry.getValue()); String name = entry.getKey(); if (name.contains("=")) { name = name.split("=", 2)[1]; keys.put(name, value.get("openssh-key")); } } return data; }
@Override public boolean matches(AllocationCandidate candidate) { if (candidate.getHost() == null) { return false; } if (op == AffinityOps.SOFT_EQ || op == AffinityOps.EQ) { List<? extends Instance> instances = instanceDao.getNonRemovedInstanceOn(candidate.getHost()); for (Instance instance : instances) { if (containerIdentifier != null && (containerIdentifier.equalsIgnoreCase(instance.getName()) || containerIdentifier.equalsIgnoreCase(instance.getUuid()))) { return true; } } return false; } else { List<? extends Instance> instances = instanceDao.getNonRemovedInstanceOn(candidate.getHost()); for (Instance instance : instances) { if (containerIdentifier != null && (containerIdentifier.equals(instance.getName()) || containerIdentifier.equals(instance.getUuid()))) { return false; } } return true; } }
protected void setSecrets(Instance instance, Map<Object, Object> data) { List<SecretReference> secrets = DataAccessor.fieldObjectList(instance, InstanceConstants.FIELD_SECRETS, SecretReference.class, jsonMapper); if (secrets == null || secrets.isEmpty()) { return; } StorageDriver driver = storageDriverDao.findSecretsDriver(instance.getAccountId()); if (driver == null) { return; } String token = tokenService.generateToken(CollectionUtils.asMap("uuid", instance.getUuid()), new Date(System.currentTimeMillis() + 31556926000L)); try { Volume vol = storageDriverDao.createSecretsVolume(instance, driver, token); create(vol, null); } catch (ProcessCancelException e) { // ignore } }
uuidPart = svc.getUuid().substring(0, 7); } else { uuidPart = instance.getUuid().substring(0, 7);
private ResourceRequest populateResourceRequestFromInstanceForPort(Instance instance, String resourceType, String poolType, String schedulerVersion, List<Port> newPorts) { PortBindingResourceRequest request = new PortBindingResourceRequest(); if (useLegacyPortAllocation(schedulerVersion)) { return null; } request.setResource(resourceType); request.setInstanceId(instance.getId().toString()); request.setResourceUuid(instance.getUuid()); List<PortSpec> portReservation = new ArrayList<>(); for (Port port : newPorts) { PortSpec spec = new PortSpec(); String bindAddress = DataAccessor.fieldString(port, BIND_ADDRESS); if (bindAddress != null) { spec.setIpAddress(bindAddress); } spec.setPrivatePort(port.getPrivatePort()); spec.setPublicPort(port.getPublicPort()); String proto = StringUtils.isEmpty(port.getProtocol()) ? "tcp" : port.getProtocol(); spec.setProtocol(proto); portReservation.add(spec); } if (portReservation.isEmpty()) { return null; } request.setPortRequests(portReservation); request.setType(poolType); return request; }
Account account, InstanceHealthCheck healthCheck) { this.name = instance.getName(); this.uuid = instance.getUuid(); this.external_id = instance.getExternalId(); this.system = instance.getSystem();
request.setResource(resourceType); request.setInstanceId(instance.getId().toString()); request.setResourceUuid(instance.getUuid()); List<PortSpec> portReservation = new ArrayList<>(); for(Port port: objectManager.children(instance, Port.class)) {
setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState());