@Test public void getCreateVMRequestBody() { final String requestBody = createVMBody(nutanixCreateVMInputs, DELIMITER); assertEquals(EXPECTED_CREATE_VM_REQUEST_BODY, requestBody); }
@NotNull public static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter) { String requestBody = EMPTY; final List<String> hostUUIDsList = new ArrayList<>(); ObjectMapper createVMMapper = new ObjectMapper(); CreateVMRequestBody createVMBody = new CreateVMRequestBody(); CreateVMRequestBody.CreateVMData createVMData = createVMBody.new CreateVMData(); createVMData.setName(nutanixCreateVMInputs.getVmName()); createVMData.setDescription(nutanixCreateVMInputs.getDescription()); createVMData.setMemory_mb(Integer.parseInt(nutanixCreateVMInputs.getVmMemorySize()) * 1024); createVMData.setNum_vcpus(Integer.parseInt(nutanixCreateVMInputs.getNumVCPUs())); createVMData.setNum_cores_per_vcpu(Integer.parseInt(nutanixCreateVMInputs.getNumCoresPerVCPU())); createVMData.setTimezone(nutanixCreateVMInputs.getTimeZone()); createVMData.setHypervisor_type(nutanixCreateVMInputs.getHypervisorType()); CreateVMRequestBody.Affinity affinity = createVMBody.new Affinity(); if (!nutanixCreateVMInputs.getHostUUIDs().isEmpty()) { String[] hostUUIDs = nutanixCreateVMInputs.getHostUUIDs().split(delimiter); Collections.addAll(hostUUIDsList, hostUUIDs); affinity.setHost_uuids(hostUUIDsList); affinity.setPolicy(AFFINITY); } CreateVMRequestBody.VMDisks vmDisks = createVMBody.new VMDisks(); CreateVMRequestBody.DiskAddress diskAddress = createVMBody.new DiskAddress(); if (Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); CreateVMRequestBody.VMDiskClone vmDiskClone = createVMBody.new VMDiskClone(); CreateVMRequestBody.CloneDiskAddress cloneDiskAddress = createVMBody.new CloneDiskAddress(); if (!nutanixCreateVMInputs.getSourceVMDiskUUID().isEmpty()) { cloneDiskAddress.setVmdisk_uuid(nutanixCreateVMInputs.getSourceVMDiskUUID()); } else { cloneDiskAddress.setNdfs_filepath(nutanixCreateVMInputs.getNdfsFilepath()); } vmDiskClone.setMinimum_size(Long.parseLong(nutanixCreateVMInputs.getVmDiskMinimumSize()) * 1024 * 1024 * 1024); vmDiskClone.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskClone.setDisk_address(cloneDiskAddress); vmDisks.setVm_disk_clone(vmDiskClone); } else { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCreate vmDiskCreate = createVMBody.new VMDiskCreate(); vmDiskCreate.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskCreate.setSize((Long.parseLong(nutanixCreateVMInputs.getVmDiskSize()) * 1024 * 1024 * 1024)); vmDisks.setVm_disk_create(vmDiskCreate); } if (!nutanixCreateVMInputs.getExternalDiskUrl().isEmpty()) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCloneExternal vmDiskCloneExternal = createVMBody.new VMDiskCloneExternal(); vmDiskCloneExternal.setExternal_disk_url(nutanixCreateVMInputs.getExternalDiskUrl()); vmDiskCloneExternal.setSize(Integer.parseInt(nutanixCreateVMInputs.getExternalDiskSize())); vmDiskCloneExternal.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDisks.setVm_disk_clone_external(vmDiskCloneExternal); } vmDisks.setDisk_address(diskAddress); CreateVMRequestBody.VMNics vmNics = createVMBody.new VMNics(); vmNics.setNetwork_uuid(nutanixCreateVMInputs.getNetworkUUID()); vmNics.setIs_connected(Boolean.parseBoolean(nutanixCreateVMInputs.getIsConnected())); vmNics.setRequested_ip_address(nutanixCreateVMInputs.getRequestedIPAddress()); CreateVMRequestBody.VMFeatures vmFeatures = createVMBody.new VMFeatures(); vmFeatures.setAGENT_VM(Boolean.parseBoolean(nutanixCreateVMInputs.getAgentVM())); createVMData.setVmFeatures(vmFeatures); ArrayList vmNicsList = new ArrayList(); vmNicsList.add(vmNics); createVMData.setVmNics(vmNicsList); ArrayList vmDiskList = new ArrayList(); vmDiskList.add(vmDisks); createVMData.setVmDisks(vmDiskList); createVMData.setAffinity(affinity); try { requestBody = createVMMapper.writeValueAsString(createVMData); } catch (JsonProcessingException e) { e.printStackTrace(); } return requestBody; }
VMImpl { @NotNull public static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter) { String requestBody = EMPTY; final List<String> hostUUIDsList = new ArrayList<>(); ObjectMapper createVMMapper = new ObjectMapper(); CreateVMRequestBody createVMBody = new CreateVMRequestBody(); CreateVMRequestBody.CreateVMData createVMData = createVMBody.new CreateVMData(); createVMData.setName(nutanixCreateVMInputs.getVmName()); createVMData.setDescription(nutanixCreateVMInputs.getDescription()); createVMData.setMemory_mb(Integer.parseInt(nutanixCreateVMInputs.getVmMemorySize()) * 1024); createVMData.setNum_vcpus(Integer.parseInt(nutanixCreateVMInputs.getNumVCPUs())); createVMData.setNum_cores_per_vcpu(Integer.parseInt(nutanixCreateVMInputs.getNumCoresPerVCPU())); createVMData.setTimezone(nutanixCreateVMInputs.getTimeZone()); createVMData.setHypervisor_type(nutanixCreateVMInputs.getHypervisorType()); CreateVMRequestBody.Affinity affinity = createVMBody.new Affinity(); if (!nutanixCreateVMInputs.getHostUUIDs().isEmpty()) { String[] hostUUIDs = nutanixCreateVMInputs.getHostUUIDs().split(delimiter); Collections.addAll(hostUUIDsList, hostUUIDs); affinity.setHost_uuids(hostUUIDsList); affinity.setPolicy(AFFINITY); } CreateVMRequestBody.VMDisks vmDisks = createVMBody.new VMDisks(); CreateVMRequestBody.DiskAddress diskAddress = createVMBody.new DiskAddress(); if (Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); CreateVMRequestBody.VMDiskClone vmDiskClone = createVMBody.new VMDiskClone(); CreateVMRequestBody.CloneDiskAddress cloneDiskAddress = createVMBody.new CloneDiskAddress(); if (!nutanixCreateVMInputs.getSourceVMDiskUUID().isEmpty()) { cloneDiskAddress.setVmdisk_uuid(nutanixCreateVMInputs.getSourceVMDiskUUID()); } else { cloneDiskAddress.setNdfs_filepath(nutanixCreateVMInputs.getNdfsFilepath()); } vmDiskClone.setMinimum_size(Long.parseLong(nutanixCreateVMInputs.getVmDiskMinimumSize()) * 1024 * 1024 * 1024); vmDiskClone.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskClone.setDisk_address(cloneDiskAddress); vmDisks.setVm_disk_clone(vmDiskClone); } else { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCreate vmDiskCreate = createVMBody.new VMDiskCreate(); vmDiskCreate.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskCreate.setSize((Long.parseLong(nutanixCreateVMInputs.getVmDiskSize()) * 1024 * 1024 * 1024)); vmDisks.setVm_disk_create(vmDiskCreate); } if (!nutanixCreateVMInputs.getExternalDiskUrl().isEmpty()) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCloneExternal vmDiskCloneExternal = createVMBody.new VMDiskCloneExternal(); vmDiskCloneExternal.setExternal_disk_url(nutanixCreateVMInputs.getExternalDiskUrl()); vmDiskCloneExternal.setSize(Integer.parseInt(nutanixCreateVMInputs.getExternalDiskSize())); vmDiskCloneExternal.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDisks.setVm_disk_clone_external(vmDiskCloneExternal); } vmDisks.setDisk_address(diskAddress); CreateVMRequestBody.VMNics vmNics = createVMBody.new VMNics(); vmNics.setNetwork_uuid(nutanixCreateVMInputs.getNetworkUUID()); vmNics.setIs_connected(Boolean.parseBoolean(nutanixCreateVMInputs.getIsConnected())); vmNics.setRequested_ip_address(nutanixCreateVMInputs.getRequestedIPAddress()); CreateVMRequestBody.VMFeatures vmFeatures = createVMBody.new VMFeatures(); vmFeatures.setAGENT_VM(Boolean.parseBoolean(nutanixCreateVMInputs.getAgentVM())); createVMData.setVmFeatures(vmFeatures); ArrayList vmNicsList = new ArrayList(); vmNicsList.add(vmNics); createVMData.setVmNics(vmNicsList); ArrayList vmDiskList = new ArrayList(); vmDiskList.add(vmDisks); createVMData.setVmDisks(vmDiskList); createVMData.setAffinity(affinity); try { requestBody = createVMMapper.writeValueAsString(createVMData); } catch (JsonProcessingException e) { e.printStackTrace(); } return requestBody; } }
VMImpl { @NotNull public static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter) { String requestBody = EMPTY; final List<String> hostUUIDsList = new ArrayList<>(); ObjectMapper createVMMapper = new ObjectMapper(); CreateVMRequestBody createVMBody = new CreateVMRequestBody(); CreateVMRequestBody.CreateVMData createVMData = createVMBody.new CreateVMData(); createVMData.setName(nutanixCreateVMInputs.getVmName()); createVMData.setDescription(nutanixCreateVMInputs.getDescription()); createVMData.setMemory_mb(Integer.parseInt(nutanixCreateVMInputs.getVmMemorySize()) * 1024); createVMData.setNum_vcpus(Integer.parseInt(nutanixCreateVMInputs.getNumVCPUs())); createVMData.setNum_cores_per_vcpu(Integer.parseInt(nutanixCreateVMInputs.getNumCoresPerVCPU())); createVMData.setTimezone(nutanixCreateVMInputs.getTimeZone()); createVMData.setHypervisor_type(nutanixCreateVMInputs.getHypervisorType()); CreateVMRequestBody.Affinity affinity = createVMBody.new Affinity(); if (!nutanixCreateVMInputs.getHostUUIDs().isEmpty()) { String[] hostUUIDs = nutanixCreateVMInputs.getHostUUIDs().split(delimiter); Collections.addAll(hostUUIDsList, hostUUIDs); affinity.setHost_uuids(hostUUIDsList); affinity.setPolicy(AFFINITY); } CreateVMRequestBody.VMDisks vmDisks = createVMBody.new VMDisks(); CreateVMRequestBody.DiskAddress diskAddress = createVMBody.new DiskAddress(); if (Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); CreateVMRequestBody.VMDiskClone vmDiskClone = createVMBody.new VMDiskClone(); CreateVMRequestBody.CloneDiskAddress cloneDiskAddress = createVMBody.new CloneDiskAddress(); if (!nutanixCreateVMInputs.getSourceVMDiskUUID().isEmpty()) { cloneDiskAddress.setVmdisk_uuid(nutanixCreateVMInputs.getSourceVMDiskUUID()); } else { cloneDiskAddress.setNdfs_filepath(nutanixCreateVMInputs.getNdfsFilepath()); } vmDiskClone.setMinimum_size(Long.parseLong(nutanixCreateVMInputs.getVmDiskMinimumSize()) * 1024 * 1024 * 1024); vmDiskClone.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskClone.setDisk_address(cloneDiskAddress); vmDisks.setVm_disk_clone(vmDiskClone); } else { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCreate vmDiskCreate = createVMBody.new VMDiskCreate(); vmDiskCreate.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskCreate.setSize((Long.parseLong(nutanixCreateVMInputs.getVmDiskSize()) * 1024 * 1024 * 1024)); vmDisks.setVm_disk_create(vmDiskCreate); } if (!nutanixCreateVMInputs.getExternalDiskUrl().isEmpty()) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCloneExternal vmDiskCloneExternal = createVMBody.new VMDiskCloneExternal(); vmDiskCloneExternal.setExternal_disk_url(nutanixCreateVMInputs.getExternalDiskUrl()); vmDiskCloneExternal.setSize(Integer.parseInt(nutanixCreateVMInputs.getExternalDiskSize())); vmDiskCloneExternal.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDisks.setVm_disk_clone_external(vmDiskCloneExternal); } vmDisks.setDisk_address(diskAddress); CreateVMRequestBody.VMNics vmNics = createVMBody.new VMNics(); vmNics.setNetwork_uuid(nutanixCreateVMInputs.getNetworkUUID()); vmNics.setIs_connected(Boolean.parseBoolean(nutanixCreateVMInputs.getIsConnected())); vmNics.setRequested_ip_address(nutanixCreateVMInputs.getRequestedIPAddress()); CreateVMRequestBody.VMFeatures vmFeatures = createVMBody.new VMFeatures(); vmFeatures.setAGENT_VM(Boolean.parseBoolean(nutanixCreateVMInputs.getAgentVM())); createVMData.setVmFeatures(vmFeatures); ArrayList vmNicsList = new ArrayList(); vmNicsList.add(vmNics); createVMData.setVmNics(vmNicsList); ArrayList vmDiskList = new ArrayList(); vmDiskList.add(vmDisks); createVMData.setVmDisks(vmDiskList); createVMData.setAffinity(affinity); try { requestBody = createVMMapper.writeValueAsString(createVMData); } catch (JsonProcessingException e) { e.printStackTrace(); } return requestBody; }  }
VMImpl { @NotNull public static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter) { String requestBody = EMPTY; final List<String> hostUUIDsList = new ArrayList<>(); ObjectMapper createVMMapper = new ObjectMapper(); CreateVMRequestBody createVMBody = new CreateVMRequestBody(); CreateVMRequestBody.CreateVMData createVMData = createVMBody.new CreateVMData(); createVMData.setName(nutanixCreateVMInputs.getVmName()); createVMData.setDescription(nutanixCreateVMInputs.getDescription()); createVMData.setMemory_mb(Integer.parseInt(nutanixCreateVMInputs.getVmMemorySize()) * 1024); createVMData.setNum_vcpus(Integer.parseInt(nutanixCreateVMInputs.getNumVCPUs())); createVMData.setNum_cores_per_vcpu(Integer.parseInt(nutanixCreateVMInputs.getNumCoresPerVCPU())); createVMData.setTimezone(nutanixCreateVMInputs.getTimeZone()); createVMData.setHypervisor_type(nutanixCreateVMInputs.getHypervisorType()); CreateVMRequestBody.Affinity affinity = createVMBody.new Affinity(); if (!nutanixCreateVMInputs.getHostUUIDs().isEmpty()) { String[] hostUUIDs = nutanixCreateVMInputs.getHostUUIDs().split(delimiter); Collections.addAll(hostUUIDsList, hostUUIDs); affinity.setHost_uuids(hostUUIDsList); affinity.setPolicy(AFFINITY); } CreateVMRequestBody.VMDisks vmDisks = createVMBody.new VMDisks(); CreateVMRequestBody.DiskAddress diskAddress = createVMBody.new DiskAddress(); if (Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); CreateVMRequestBody.VMDiskClone vmDiskClone = createVMBody.new VMDiskClone(); CreateVMRequestBody.CloneDiskAddress cloneDiskAddress = createVMBody.new CloneDiskAddress(); if (!nutanixCreateVMInputs.getSourceVMDiskUUID().isEmpty()) { cloneDiskAddress.setVmdisk_uuid(nutanixCreateVMInputs.getSourceVMDiskUUID()); } else { cloneDiskAddress.setNdfs_filepath(nutanixCreateVMInputs.getNdfsFilepath()); } vmDiskClone.setMinimum_size(Long.parseLong(nutanixCreateVMInputs.getVmDiskMinimumSize()) * 1024 * 1024 * 1024); vmDiskClone.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskClone.setDisk_address(cloneDiskAddress); vmDisks.setVm_disk_clone(vmDiskClone); } else { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCreate vmDiskCreate = createVMBody.new VMDiskCreate(); vmDiskCreate.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskCreate.setSize((Long.parseLong(nutanixCreateVMInputs.getVmDiskSize()) * 1024 * 1024 * 1024)); vmDisks.setVm_disk_create(vmDiskCreate); } if (!nutanixCreateVMInputs.getExternalDiskUrl().isEmpty()) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCloneExternal vmDiskCloneExternal = createVMBody.new VMDiskCloneExternal(); vmDiskCloneExternal.setExternal_disk_url(nutanixCreateVMInputs.getExternalDiskUrl()); vmDiskCloneExternal.setSize(Integer.parseInt(nutanixCreateVMInputs.getExternalDiskSize())); vmDiskCloneExternal.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDisks.setVm_disk_clone_external(vmDiskCloneExternal); } vmDisks.setDisk_address(diskAddress); CreateVMRequestBody.VMNics vmNics = createVMBody.new VMNics(); vmNics.setNetwork_uuid(nutanixCreateVMInputs.getNetworkUUID()); vmNics.setIs_connected(Boolean.parseBoolean(nutanixCreateVMInputs.getIsConnected())); vmNics.setRequested_ip_address(nutanixCreateVMInputs.getRequestedIPAddress()); CreateVMRequestBody.VMFeatures vmFeatures = createVMBody.new VMFeatures(); vmFeatures.setAGENT_VM(Boolean.parseBoolean(nutanixCreateVMInputs.getAgentVM())); createVMData.setVmFeatures(vmFeatures); ArrayList vmNicsList = new ArrayList(); vmNicsList.add(vmNics); createVMData.setVmNics(vmNicsList); ArrayList vmDiskList = new ArrayList(); vmDiskList.add(vmDisks); createVMData.setVmDisks(vmDiskList); createVMData.setAffinity(affinity); try { requestBody = createVMMapper.writeValueAsString(createVMData); } catch (JsonProcessingException e) { e.printStackTrace(); } return requestBody; }  @NotNull static Map<String, String> listVMs(@NotNull final NutanixListVMsInputs nutanixListVMsInputs); @NotNull static Map<String, String> createVM(@NotNull final NutanixCreateVMInputs nutanixCreateVMInputs); @NotNull static Map<String, String> updateVM(@NotNull final NutanixUpdateVMInputs nutanixUpdateVMInputs); @NotNull static Map<String, String> deleteVM(@NotNull final NutanixDeleteVMInputs nutanixDeleteVMInputs); @NotNull static Map<String, String> setVMPowerState(@NotNull final NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static Map<String, String> getVMDetails(@NotNull final NutanixGetVMDetailsInputs nutanixGetVMDetailsInputs); @NotNull static String listVMsURL(NutanixListVMsInputs nutanixListVMsInputs); @NotNull static String getVMDetailsURL(NutanixGetVMDetailsInputs nutanixGetVMDetailsInputs); @NotNull static String createVMURL(NutanixCreateVMInputs nutanixCreateVMInputs); @NotNull static String updateVMURL(NutanixUpdateVMInputs nutanixUpdateVMInputs); static String deleteVMURL(NutanixDeleteVMInputs nutanixDeleteVMInputs); @NotNull static String setVMPowerStateURL(NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter); @NotNull static String setVMPowerStateBody(NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static String updateVMBody(NutanixUpdateVMInputs nutanixUpdateVMInputs, String delimiter); }
VMImpl { @NotNull public static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter) { String requestBody = EMPTY; final List<String> hostUUIDsList = new ArrayList<>(); ObjectMapper createVMMapper = new ObjectMapper(); CreateVMRequestBody createVMBody = new CreateVMRequestBody(); CreateVMRequestBody.CreateVMData createVMData = createVMBody.new CreateVMData(); createVMData.setName(nutanixCreateVMInputs.getVmName()); createVMData.setDescription(nutanixCreateVMInputs.getDescription()); createVMData.setMemory_mb(Integer.parseInt(nutanixCreateVMInputs.getVmMemorySize()) * 1024); createVMData.setNum_vcpus(Integer.parseInt(nutanixCreateVMInputs.getNumVCPUs())); createVMData.setNum_cores_per_vcpu(Integer.parseInt(nutanixCreateVMInputs.getNumCoresPerVCPU())); createVMData.setTimezone(nutanixCreateVMInputs.getTimeZone()); createVMData.setHypervisor_type(nutanixCreateVMInputs.getHypervisorType()); CreateVMRequestBody.Affinity affinity = createVMBody.new Affinity(); if (!nutanixCreateVMInputs.getHostUUIDs().isEmpty()) { String[] hostUUIDs = nutanixCreateVMInputs.getHostUUIDs().split(delimiter); Collections.addAll(hostUUIDsList, hostUUIDs); affinity.setHost_uuids(hostUUIDsList); affinity.setPolicy(AFFINITY); } CreateVMRequestBody.VMDisks vmDisks = createVMBody.new VMDisks(); CreateVMRequestBody.DiskAddress diskAddress = createVMBody.new DiskAddress(); if (Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); CreateVMRequestBody.VMDiskClone vmDiskClone = createVMBody.new VMDiskClone(); CreateVMRequestBody.CloneDiskAddress cloneDiskAddress = createVMBody.new CloneDiskAddress(); if (!nutanixCreateVMInputs.getSourceVMDiskUUID().isEmpty()) { cloneDiskAddress.setVmdisk_uuid(nutanixCreateVMInputs.getSourceVMDiskUUID()); } else { cloneDiskAddress.setNdfs_filepath(nutanixCreateVMInputs.getNdfsFilepath()); } vmDiskClone.setMinimum_size(Long.parseLong(nutanixCreateVMInputs.getVmDiskMinimumSize()) * 1024 * 1024 * 1024); vmDiskClone.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskClone.setDisk_address(cloneDiskAddress); vmDisks.setVm_disk_clone(vmDiskClone); } else { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCreate vmDiskCreate = createVMBody.new VMDiskCreate(); vmDiskCreate.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDiskCreate.setSize((Long.parseLong(nutanixCreateVMInputs.getVmDiskSize()) * 1024 * 1024 * 1024)); vmDisks.setVm_disk_create(vmDiskCreate); } if (!nutanixCreateVMInputs.getExternalDiskUrl().isEmpty()) { diskAddress.setDevice_bus(nutanixCreateVMInputs.getDeviceBus()); diskAddress.setDisk_label(nutanixCreateVMInputs.getDiskLabel()); diskAddress.setDevice_index(Integer.parseInt(nutanixCreateVMInputs.getDeviceIndex())); vmDisks.setFlash_mode_enabled(Boolean.parseBoolean(nutanixCreateVMInputs.getFlashModeEnabled())); vmDisks.setIs_scsi_pass_through(Boolean.parseBoolean(nutanixCreateVMInputs.getIsSCSIPassThrough())); vmDisks.setIs_thin_provisioned(Boolean.parseBoolean(nutanixCreateVMInputs.getIsThinProvisioned())); vmDisks.setIs_cdrom(Boolean.parseBoolean(nutanixCreateVMInputs.getIsCDROM())); vmDisks.setIs_empty(Boolean.parseBoolean(nutanixCreateVMInputs.getIsEmpty())); CreateVMRequestBody.VMDiskCloneExternal vmDiskCloneExternal = createVMBody.new VMDiskCloneExternal(); vmDiskCloneExternal.setExternal_disk_url(nutanixCreateVMInputs.getExternalDiskUrl()); vmDiskCloneExternal.setSize(Integer.parseInt(nutanixCreateVMInputs.getExternalDiskSize())); vmDiskCloneExternal.setStorage_container_uuid(nutanixCreateVMInputs.getStorageContainerUUID()); vmDisks.setVm_disk_clone_external(vmDiskCloneExternal); } vmDisks.setDisk_address(diskAddress); CreateVMRequestBody.VMNics vmNics = createVMBody.new VMNics(); vmNics.setNetwork_uuid(nutanixCreateVMInputs.getNetworkUUID()); vmNics.setIs_connected(Boolean.parseBoolean(nutanixCreateVMInputs.getIsConnected())); vmNics.setRequested_ip_address(nutanixCreateVMInputs.getRequestedIPAddress()); CreateVMRequestBody.VMFeatures vmFeatures = createVMBody.new VMFeatures(); vmFeatures.setAGENT_VM(Boolean.parseBoolean(nutanixCreateVMInputs.getAgentVM())); createVMData.setVmFeatures(vmFeatures); ArrayList vmNicsList = new ArrayList(); vmNicsList.add(vmNics); createVMData.setVmNics(vmNicsList); ArrayList vmDiskList = new ArrayList(); vmDiskList.add(vmDisks); createVMData.setVmDisks(vmDiskList); createVMData.setAffinity(affinity); try { requestBody = createVMMapper.writeValueAsString(createVMData); } catch (JsonProcessingException e) { e.printStackTrace(); } return requestBody; }  @NotNull static Map<String, String> listVMs(@NotNull final NutanixListVMsInputs nutanixListVMsInputs); @NotNull static Map<String, String> createVM(@NotNull final NutanixCreateVMInputs nutanixCreateVMInputs); @NotNull static Map<String, String> updateVM(@NotNull final NutanixUpdateVMInputs nutanixUpdateVMInputs); @NotNull static Map<String, String> deleteVM(@NotNull final NutanixDeleteVMInputs nutanixDeleteVMInputs); @NotNull static Map<String, String> setVMPowerState(@NotNull final NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static Map<String, String> getVMDetails(@NotNull final NutanixGetVMDetailsInputs nutanixGetVMDetailsInputs); @NotNull static String listVMsURL(NutanixListVMsInputs nutanixListVMsInputs); @NotNull static String getVMDetailsURL(NutanixGetVMDetailsInputs nutanixGetVMDetailsInputs); @NotNull static String createVMURL(NutanixCreateVMInputs nutanixCreateVMInputs); @NotNull static String updateVMURL(NutanixUpdateVMInputs nutanixUpdateVMInputs); static String deleteVMURL(NutanixDeleteVMInputs nutanixDeleteVMInputs); @NotNull static String setVMPowerStateURL(NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static String createVMBody(NutanixCreateVMInputs nutanixCreateVMInputs, String delimiter); @NotNull static String setVMPowerStateBody(NutanixSetVMPowerStateInputs nutanixSetVMPowerStateInputs); @NotNull static String updateVMBody(NutanixUpdateVMInputs nutanixUpdateVMInputs, String delimiter);  }