@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest newGuest = client.getVirtualGuestClient().getVirtualGuest(guest.getId()); boolean hasBackendIp = newGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = newGuest.getPrimaryIpAddress() != null; boolean hasPasswords = newGuest.getOperatingSystem() != null && newGuest.getOperatingSystem().getPasswords().size() > 0; return hasBackendIp && hasPrimaryIp && hasPasswords; } }
.primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) .operatingSystemReferenceCode(in.getOperatingSystemReferenceCode()) .datacenter(in.getDatacenter())
@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest newGuest = client.getVirtualGuestApi().getObject(guest.getId()); boolean hasBackendIp = newGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = newGuest.getPrimaryIpAddress() != null; boolean hasPasswords = newGuest.getOperatingSystem() != null && newGuest.getOperatingSystem().getPasswords().size() > 0; return hasBackendIp && hasPrimaryIp && hasPasswords; } }
.primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) .operatingSystemReferenceCode(in.getOperatingSystemReferenceCode()) .datacenter(in.getDatacenter())
@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest newGuest = client.getVirtualGuestClient().getVirtualGuest(guest.getId()); boolean hasBackendIp = newGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = newGuest.getPrimaryIpAddress() != null; boolean hasPasswords = newGuest.getOperatingSystem() != null && newGuest.getOperatingSystem().getPasswords().size() > 0; return hasBackendIp && hasPrimaryIp && hasPasswords; } }
.primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) .operatingSystemReferenceCode(in.getOperatingSystemReferenceCode()) .datacenter(in.getDatacenter())
@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest virtualGuest = client.getVirtualGuestApi().getVirtualGuest(guest.getId()); boolean hasBackendIp = virtualGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = virtualGuest.getPrimaryIpAddress() != null; boolean hasPasswords = virtualGuest.getOperatingSystem() != null && !virtualGuest.getOperatingSystem().getPasswords().isEmpty(); return virtualGuest.isPrivateNetworkOnly() ? hasBackendIp && hasPasswords : hasBackendIp && hasPrimaryIp && hasPasswords; } }
@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest virtualGuest = client.getVirtualGuestApi().getVirtualGuest(guest.getId()); boolean hasBackendIp = virtualGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = virtualGuest.getPrimaryIpAddress() != null; boolean hasPasswords = virtualGuest.getOperatingSystem() != null && !virtualGuest.getOperatingSystem().getPasswords().isEmpty(); return virtualGuest.isPrivateNetworkOnly() ? hasBackendIp && hasPasswords : hasBackendIp && hasPrimaryIp && hasPasswords; } }
@Override public boolean apply(VirtualGuest guest) { checkNotNull(guest, "virtual guest was null"); VirtualGuest virtualGuest = client.getVirtualGuestApi().getVirtualGuest(guest.getId()); boolean hasBackendIp = virtualGuest.getPrimaryBackendIpAddress() != null; boolean hasPrimaryIp = virtualGuest.getPrimaryIpAddress() != null; boolean hasPasswords = virtualGuest.getOperatingSystem() != null && !virtualGuest.getOperatingSystem().getPasswords().isEmpty(); return virtualGuest.isPrivateNetworkOnly() ? hasBackendIp && hasPasswords : hasBackendIp && hasPrimaryIp && hasPasswords; } }
/** * Builds a Json string suitable for sending to the softlayer api * * @param virtualGuest * @return String */ String buildJson(VirtualGuest virtualGuest) { TemplateObject templateObject = null; String hostname = checkNotNull(virtualGuest.getHostname(), "hostname"); String domain = checkNotNull(virtualGuest.getDomain(), "domain"); int startCpus = checkNotNull(virtualGuest.getStartCpus(), "startCpus"); int maxMemory = checkNotNull(virtualGuest.getMaxMemory(), "maxMemory"); boolean localDiskFlag = checkNotNull(virtualGuest.isLocalDiskFlag(), "localDiskFlag"); String datacenterName = checkNotNull(virtualGuest.getDatacenter().getName(), "datacenterName"); Set<NetworkComponent> networkComponents = getNetworkComponents(virtualGuest); if(virtualGuest.getOperatingSystem() != null) { String operatingSystemReferenceCode = checkNotNull(virtualGuest.getOperatingSystem() .getOperatingSystemReferenceCode(), "operatingSystemReferenceCode"); templateObject = new TemplateObject(hostname, domain, startCpus, maxMemory, true, operatingSystemReferenceCode, null, localDiskFlag, new Datacenter(datacenterName), networkComponents, getBlockDevices(virtualGuest)); } else if(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() != null) { String globalIdentifier = checkNotNull(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() .getGlobalIdentifier(), "blockDeviceTemplateGroup.globalIdentifier"); templateObject = new TemplateObject(hostname, domain, startCpus, maxMemory, true, null, new BlockDeviceTemplateGroup(globalIdentifier), localDiskFlag, new Datacenter(datacenterName), networkComponents, null); } return json.toJson(ImmutableMap.of("parameters", ImmutableList.<TemplateObject> of(templateObject))); }
@Override public Image apply(VirtualGuest from) { checkNotNull(from, "from"); if (from.getOperatingSystem() == null) { return new ImageBuilder().ids(getReferenceCodeOrId(from)) .name(from.getHostname()) .status(Image.Status.UNRECOGNIZED) .operatingSystem(OperatingSystem.builder() .family(OsFamily.UNRECOGNIZED) .version(UNRECOGNIZED) .description(UNRECOGNIZED) .build()) .build(); } else { return operatingSystemToImage.apply(from.getOperatingSystem()); } }
@Override public Image apply(VirtualGuest from) { checkNotNull(from, "from"); if (from.getOperatingSystem() == null) { return new ImageBuilder().ids(getReferenceCodeOrId(from)) .name(from.getHostname()) .status(Image.Status.UNRECOGNIZED) .operatingSystem(OperatingSystem.builder() .family(OsFamily.UNRECOGNIZED) .version(UNRECOGNIZED) .description(UNRECOGNIZED) .build()) .build(); } else { return operatingSystemToImage.apply(from.getOperatingSystem()); } }
@Override public Image apply(VirtualGuest from) { checkNotNull(from, "from"); if (from.getOperatingSystem() == null) { return new ImageBuilder().ids(getReferenceCodeOrId(from)) .name(from.getHostname()) .status(Image.Status.UNRECOGNIZED) .operatingSystem(OperatingSystem.builder() .family(OsFamily.UNRECOGNIZED) .version(UNRECOGNIZED) .description(UNRECOGNIZED) .build()) .build(); } else { return operatingSystemToImage.apply(from.getOperatingSystem()); } }
builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress())); if (from.getOperatingSystem() != null && from.getOperatingSystem().getPasswords() != null && !from.getOperatingSystem().getPasswords().isEmpty()) { Password password = getBestPassword(from.getOperatingSystem().getPasswords(), from); builder.credentials(LoginCredentials.builder().identity(password.getUsername()).credential(password.getPassword()).build());
@Override public NodeAndInitialCredentials<VirtualGuest> createNodeWithGroupEncodedIntoName(String group, String name, Template template) { checkNotNull(template, "template was null"); checkNotNull(template.getOptions(), "template options was null"); checkArgument(template.getOptions().getClass().isAssignableFrom(SoftLayerTemplateOptions.class), "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() .getClass()); String domainName = template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName(); VirtualGuest newGuest = VirtualGuest.builder().domain(domainName).hostname(name).build(); ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId()) .location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template)) .virtualGuests(newGuest).build(); logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name); ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order); VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0); logger.trace("<< virtualGuest(%s)", result.getId()); logger.debug(">> awaiting login details for virtualGuest(%s)", result.getId()); boolean orderInSystem = loginDetailsTester.apply(result); logger.trace("<< virtualGuest(%s) complete(%s)", result.getId(), orderInSystem); checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result, Long.toString(guestLoginDelay)); result = client.getVirtualGuestClient().getVirtualGuest(result.getId()); Password pw = get(result.getOperatingSystem().getPasswords(), 0); return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build()); }
@Override public NodeAndInitialCredentials<VirtualGuest> createNodeWithGroupEncodedIntoName(String group, String name, Template template) { checkNotNull(template, "template was null"); checkNotNull(template.getOptions(), "template options was null"); checkArgument(template.getOptions().getClass().isAssignableFrom(SoftLayerTemplateOptions.class), "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() .getClass()); String domainName = template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName(); VirtualGuest newGuest = VirtualGuest.builder().domain(domainName).hostname(name).build(); ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId()) .location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template)) .virtualGuests(newGuest).build(); logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name); ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order); VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0); logger.trace("<< virtualGuest(%s)", result.getId()); logger.debug(">> awaiting login details for virtualGuest(%s)", result.getId()); boolean orderInSystem = loginDetailsTester.apply(result); logger.trace("<< virtualGuest(%s) complete(%s)", result.getId(), orderInSystem); checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result, Long.toString(guestLoginDelay)); result = client.getVirtualGuestClient().getVirtualGuest(result.getId()); Password pw = get(result.getOperatingSystem().getPasswords(), 0); return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build()); }
.status(Image.Status.AVAILABLE); if(from.getOperatingSystem() == null) { return builder.operatingSystem( OperatingSystem.builder().description("UNRECOGNIZED").build()) .build(); SoftwareLicense softwareLicense = from.getOperatingSystem().getSoftwareLicense(); String referenceCode = softwareLicense.getSoftwareDescription().getReferenceCode();
Password pw = get(result.getOperatingSystem().getPasswords(), 0); return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build());
public T fromVirtualGuest(VirtualGuest in) { return this .accountId(in.getAccountId()) .createDate(in.getCreateDate()) .dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly()) .domain(in.getDomain()) .fullyQualifiedDomainName(in.getFullyQualifiedDomainName()) .hostname(in.getHostname()) .id(in.getId()) .lastVerifiedDate(in.getLastVerifiedDate()) .maxCpu(in.getMaxCpu()) .maxCpuUnits(in.getMaxCpuUnits()) .maxMemory(in.getMaxMemory()) .metricPollDate(in.getMetricPollDate()) .modifyDate(in.getModifyDate()) .notes(in.getNotes()) .privateNetworkOnly(in.isPrivateNetworkOnly()) .startCpus(in.getStartCpus()) .statusId(in.getStatusId()) .uuid(in.getUuid()) .primaryBackendIpAddress(in.getPrimaryBackendIpAddress()) .primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) .datacenter(in.getDatacenter()) .powerState(in.getPowerState()); } }
public T fromVirtualGuest(VirtualGuest in) { return this .accountId(in.getAccountId()) .createDate(in.getCreateDate()) .dedicatedAccountHostOnly(in.isDedicatedAccountHostOnly()) .domain(in.getDomain()) .fullyQualifiedDomainName(in.getFullyQualifiedDomainName()) .hostname(in.getHostname()) .id(in.getId()) .lastVerifiedDate(in.getLastVerifiedDate()) .maxCpu(in.getMaxCpu()) .maxCpuUnits(in.getMaxCpuUnits()) .maxMemory(in.getMaxMemory()) .metricPollDate(in.getMetricPollDate()) .modifyDate(in.getModifyDate()) .notes(in.getNotes()) .privateNetworkOnly(in.isPrivateNetworkOnly()) .startCpus(in.getStartCpus()) .statusId(in.getStatusId()) .uuid(in.getUuid()) .primaryBackendIpAddress(in.getPrimaryBackendIpAddress()) .primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) .datacenter(in.getDatacenter()) .powerState(in.getPowerState()); } }