/** * 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))); }
templateObjectBuilder.operatingSystemReferenceCode(operatingSystemReferenceCode) .blockDevices(getBlockDevices(virtualGuest)); } else if (virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() != null) { String globalIdentifier = checkNotNull(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() .getGlobalIdentifier(), "blockDeviceTemplateGroup.globalIdentifier"); templateObjectBuilder.blockDeviceTemplateGroup(new BlockDeviceTemplateGroup(globalIdentifier));
templateObjectBuilder.operatingSystemReferenceCode(operatingSystemReferenceCode) .blockDevices(getBlockDevices(virtualGuest)); } else if (virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() != null) { String globalIdentifier = checkNotNull(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() .getGlobalIdentifier(), "blockDeviceTemplateGroup.globalIdentifier"); templateObjectBuilder.blockDeviceTemplateGroup(new BlockDeviceTemplateGroup(globalIdentifier));
templateObjectBuilder.operatingSystemReferenceCode(operatingSystemReferenceCode) .blockDevices(getBlockDevices(virtualGuest)); } else if (virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() != null) { String globalIdentifier = checkNotNull(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() .getGlobalIdentifier(), "blockDeviceTemplateGroup.globalIdentifier"); templateObjectBuilder.blockDeviceTemplateGroup(new BlockDeviceTemplateGroup(globalIdentifier));
.activeTransactionCount(in.getActiveTransactionCount()) .localDiskFlag(in.isLocalDiskFlag()) .blockDeviceTemplateGroup(in.getVirtualGuestBlockDeviceTemplateGroup()) .networkComponents(in.getVirtualGuestNetworkComponents());
.dedicatedAccountHostOnlyFlag(in.isDedicatedAccountHostOnly()) .privateNetworkOnlyFlag(in.isPrivateNetworkOnly()) .blockDeviceTemplateGroup(in.getVirtualGuestBlockDeviceTemplateGroup()) .networkComponents(in.getVirtualGuestNetworkComponents()) .tagReferences(in.getTagReferences())
.dedicatedAccountHostOnlyFlag(in.isDedicatedAccountHostOnly()) .privateNetworkOnlyFlag(in.isPrivateNetworkOnly()) .blockDeviceTemplateGroup(in.getVirtualGuestBlockDeviceTemplateGroup()) .networkComponents(in.getVirtualGuestNetworkComponents()) .tagReferences(in.getTagReferences())
.dedicatedAccountHostOnlyFlag(in.isDedicatedAccountHostOnly()) .privateNetworkOnlyFlag(in.isPrivateNetworkOnly()) .blockDeviceTemplateGroup(in.getVirtualGuestBlockDeviceTemplateGroup()) .networkComponents(in.getVirtualGuestNetworkComponents()) .tagReferences(in.getTagReferences())