public Builder toBuilder() { return builder().fromOperatingSystem(this); }
public T fromOperatingSystem(OperatingSystem in) { return this .id(in.getId()) .passwords(in.getPasswords()); } }
public OperatingSystem build() { return new OperatingSystem(id, passwords); }
@Override public Set<OperatingSystem> listImages() { Set<OperatingSystem> result = Sets.newHashSet(); // add allObjects filtered by the available OS Set<SoftwareDescription> allObjects = api.getSoftwareDescriptionApi().getAllObjects(); for (OperatingSystem os : createObjectOptionsSupplier.get().getVirtualGuestOperatingSystems()) { result.addAll(FluentIterable.from(allObjects) .filter(new IsOperatingSystem()) .filter(new HasSameOsReferenceCode(os.getOperatingSystemReferenceCode())) .transform(new SoftwareDescriptionToOperatingSystem(os.getId())) .toSet()); } return result; }
@Test public void testOperatingSystemToImage() { OperatingSystem operatingSystem = OperatingSystem.builder() .id("UBUNTU_12_64") .softwareLicense(SoftwareLicense.builder() .softwareDescription(SoftwareDescription.builder() .version("12.04-64 Minimal for CCI") .referenceCode("UBUNTU_12_64") .longDescription("Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)") .build()) .build()) .build(); Image image = new OperatingSystemToImage().apply(operatingSystem); assertEquals(image.getId(), operatingSystem.getId()); String referenceCode = operatingSystem.getSoftwareLicense().getSoftwareDescription().getReferenceCode(); assertEquals(image.getDescription(), referenceCode); assertTrue(image.getOperatingSystem().getFamily().toString().equalsIgnoreCase("UBUNTU")); assertEquals(image.getOperatingSystem().getVersion(), "12.04"); assertEquals(image.getOperatingSystem().is64Bit(), true); assertEquals(image.getStatus(), Image.Status.AVAILABLE); }
checkNotNull(operatingSystem, "operatingSystem"); final SoftwareLicense defaultSoftwareLicense = SoftwareLicense.builder().softwareDescription(SoftwareDescription.builder().build()).build(); SoftwareLicense softwareLicense = fromNullable(operatingSystem.getSoftwareLicense()).or(defaultSoftwareLicense); Optional<String> optOSReferenceCode = fromNullable(softwareLicense.getSoftwareDescription().getReferenceCode()); Optional<String> optVersion = fromNullable(softwareLicense.getSoftwareDescription().getVersion()); .ids(optOSReferenceCode.or(operatingSystem.getId())) .description(optOSReferenceCode.or(UNRECOGNIZED)) .operatingSystem(os)
@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; } }
@Override public boolean apply(OperatingSystem input) { return input.getId().equals(id); } }, null);
/** * 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))); }
.build(); SoftwareLicense softwareLicense = from.getOperatingSystem().getSoftwareLicense(); String referenceCode = softwareLicense.getSoftwareDescription().getReferenceCode();
@Override public Set<OperatingSystem> listImages() { Set<OperatingSystem> result = Sets.newHashSet(); // add allObjects filtered by the available OS Set<SoftwareDescription> allObjects = api.getSoftwareDescriptionApi().getAllObjects(); for (OperatingSystem os : createObjectOptionsSupplier.get().getVirtualGuestOperatingSystems()) { result.addAll(FluentIterable.from(allObjects) .filter(new IsOperatingSystem()) .filter(new HasSameOsReferenceCode(os.getOperatingSystemReferenceCode())) .transform(new SoftwareDescriptionToOperatingSystem(os.getId())) .toSet()); } return result; }
checkNotNull(operatingSystem, "operatingSystem"); final SoftwareLicense defaultSoftwareLicense = SoftwareLicense.builder().softwareDescription(SoftwareDescription.builder().build()).build(); SoftwareLicense softwareLicense = fromNullable(operatingSystem.getSoftwareLicense()).or(defaultSoftwareLicense); Optional<String> optOSReferenceCode = fromNullable(softwareLicense.getSoftwareDescription().getReferenceCode()); Optional<String> optVersion = fromNullable(softwareLicense.getSoftwareDescription().getVersion()); .ids(optOSReferenceCode.or(operatingSystem.getId())) .description(optOSReferenceCode.or(UNRECOGNIZED)) .operatingSystem(os)
@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; } }
@Override public boolean apply(OperatingSystem input) { return input.getId().equals(id); } }
.getOperatingSystemReferenceCode(), "operatingSystemReferenceCode"); templateObjectBuilder.operatingSystemReferenceCode(operatingSystemReferenceCode) .blockDevices(getBlockDevices(virtualGuest));
public Builder toBuilder() { return builder().fromOperatingSystem(this); }
public T fromOperatingSystem(OperatingSystem in) { return this .id(in.getId()) .passwords(in.getPasswords()); } }
@Override public Set<OperatingSystem> listImages() { Set<OperatingSystem> result = Sets.newHashSet(); // add allObjects filtered by the available OS Set<SoftwareDescription> allObjects = api.getSoftwareDescriptionApi().getAllObjects(); for (OperatingSystem os : createObjectOptionsSupplier.get().getVirtualGuestOperatingSystems()) { result.addAll(FluentIterable.from(allObjects) .filter(new IsOperatingSystem()) .filter(new HasSameOsReferenceCode(os.getOperatingSystemReferenceCode())) .transform(new SoftwareDescriptionToOperatingSystem(os.getId())) .toSet()); } return result; }
checkNotNull(operatingSystem, "operatingSystem"); final SoftwareLicense defaultSoftwareLicense = SoftwareLicense.builder().softwareDescription(SoftwareDescription.builder().build()).build(); SoftwareLicense softwareLicense = fromNullable(operatingSystem.getSoftwareLicense()).or(defaultSoftwareLicense); Optional<String> optOSReferenceCode = fromNullable(softwareLicense.getSoftwareDescription().getReferenceCode()); Optional<String> optVersion = fromNullable(softwareLicense.getSoftwareDescription().getVersion()); .ids(optOSReferenceCode.or(operatingSystem.getId())) .description(optOSReferenceCode.or(UNRECOGNIZED)) .operatingSystem(os)
@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; } }