public static VirtualDeviceConfigSpec createCdrom(VirtualDevice ideController, int unitNumber) { VirtualCdrom cdrom = new VirtualCdrom(); cdrom.setControllerKey(ideController.getKey()); cdrom.setUnitNumber(unitNumber); VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo(); info.setAllowGuestControl(true); info.setConnected(true); info.setStartConnected(true); cdrom.setConnectable(info); VirtualCdromAtapiBackingInfo backing = new VirtualCdromAtapiBackingInfo(); backing.setDeviceName(String.format("cdrom-%d-%d", ideController.getKey(), unitNumber)); backing.setUseAutoDetect(false); cdrom.setBacking(backing); VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec(); spec.setDevice(cdrom); spec.setOperation(VirtualDeviceConfigSpecOperation.ADD); return spec; }
private VirtualDeviceConfigSpec reconfigureCdrom(VirtualCdrom vcd) { VirtualCdrom cdrom = new VirtualCdrom(); cdrom.setControllerKey(vcd.getControllerKey()); cdrom.setKey(vcd.getKey()); cdrom.setUnitNumber(vcd.getUnitNumber()); VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo(); info.setAllowGuestControl(true); info.setConnected(true); info.setStartConnected(true); cdrom.setConnectable(info); cdrom.setBacking(vcd.getBacking()); VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec(); spec.setDevice(cdrom); spec.setOperation(VirtualDeviceConfigSpecOperation.EDIT); return spec; }
/** * Update the details of the disk into compute state after the provisioning is successful */ private void updateDiskLinksAfterProvisionSuccess(ComputeState state, List<VirtualDevice> disks, ProvisionContext ctx) { ArrayList<String> diskLinks = new ArrayList<>(disks.size()); // Fill in the disk links from the input to the ComputeState, as it may contain non hdd // disk as well. For ex, Floppy or CD-Rom ctx.disks.stream().forEach(ds -> diskLinks.add(ds.documentSelfLink)); // Handle all the HDD disk for (VirtualDevice disk : disks) { DiskStateExpanded matchedDs = findMatchingDiskState(disk, ctx.disks); if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) { handleVirtualDiskUpdate(matchedDs, (VirtualDisk) disk, diskLinks, ctx); } else if (disk instanceof VirtualCdrom) { handleVirtualDeviceUpdate(matchedDs, DiskType.CDROM, disk, diskLinks, ctx); } else if (disk instanceof VirtualFloppy) { handleVirtualDeviceUpdate(matchedDs, DiskType.FLOPPY, disk, diskLinks, ctx); } else { continue; } } state.diskLinks = diskLinks; }
static VirtualDeviceConfigSpec createAddCdConfigSpec(VirtualMachine vm, String dsName, String isoName) throws Exception { VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec(); cdSpec.setOperation(VirtualDeviceConfigSpecOperation.add); VirtualCdrom cdrom = new VirtualCdrom(); VirtualCdromIsoBackingInfo cdDeviceBacking = new VirtualCdromIsoBackingInfo(); DatastoreSummary ds = findDatastoreSummary(vm, dsName); cdDeviceBacking.setDatastore(ds.getDatastore()); cdDeviceBacking.setFileName("[" + dsName +"] "+ vm.getName() + "/" + isoName + ".iso"); VirtualDevice vd = getIDEController(vm); cdrom.setBacking(cdDeviceBacking); cdrom.setControllerKey(vd.getKey()); cdrom.setUnitNumber(vd.getUnitNumber()); cdrom.setKey(-1); cdSpec.setDevice(cdrom); return cdSpec; }
static VirtualDeviceConfigSpec createRemoveCdConfigSpec(VirtualMachine vm, String cdName) throws Exception { VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec(); cdSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); VirtualCdrom cdRemove = (VirtualCdrom)findVirtualDevice(vm.getConfig(), cdName); if(cdRemove != null) { cdSpec.setDevice(cdRemove); return cdSpec; } else { System.out.println("No device available " + cdName); return null; } }
public List<VirtualDevice> getDisks() { ArrayOfVirtualDevice dev = (ArrayOfVirtualDevice) getOrDefault( VimPath.vm_config_hardware_device, null); if (dev == null) { return Collections.emptyList(); } return dev.getVirtualDevice().stream() .filter(d -> d instanceof VirtualDisk || d instanceof VirtualCdrom || d instanceof VirtualFloppy) .collect(Collectors.toList()); }
public static DiskService.DiskStateExpanded findMatchingDiskState(VirtualDevice vd, List<DiskService.DiskStateExpanded> disks) { // Step 1: Match if there are matching bootOrder number with Unit number of disk // Step 2: If not, then find a custom property to match the bootOrder with the unit number // Step 3: If no match found then this is the new disk so return null if (disks == null || disks.isEmpty()) { return null; } return disks.stream() .filter(ds -> { if (vd instanceof VirtualDisk && ds.type == DiskService.DiskType.HDD) { return true; } else if (vd instanceof VirtualCdrom && ds.type == DiskService.DiskType.CDROM) { return true; } else if (vd instanceof VirtualFloppy && ds.type == DiskService.DiskType.FLOPPY) { return true; } return false; }) .filter(ds -> { boolean isFound = (ds.bootOrder != null && (ds.bootOrder - 1) == vd .getUnitNumber()); if (!isFound) { // Now check custom properties for controller unit number if (ds.customProperties != null && ds.customProperties.get (DISK_CONTROLLER_NUMBER) != null) { int unitNumber = Integer.parseInt(ds.customProperties.get (DISK_CONTROLLER_NUMBER)); isFound = unitNumber == vd.getUnitNumber(); } } return isFound; }).findFirst().orElse(null); }
VirtualDeviceConfigSpec getPopulatedCDSpecs(String fileName, ManagedObjectReference dataStoreRef, List<VirtualDevice> virtualDevicesList, VirtualDeviceConfigSpecOperation operation, Integer controllerKey, Integer unitNumber, Integer key, String parameter, VmInputs vmInputs) { VirtualDeviceConfigSpec cdSpecs = new VirtualDeviceConfigSpec(); if (Operation.ADD.toString().equalsIgnoreCase(parameter)) { VirtualCdromIsoBackingInfo cdIsoBacking = new VirtualCdromIsoBackingInfo(); cdIsoBacking.setDatastore(dataStoreRef); cdIsoBacking.setFileName(fileName + TEST_CD_ISO); VirtualCdrom cdRom = new VirtualCdrom(); cdRom.setBacking(cdIsoBacking); cdRom.setControllerKey(controllerKey); cdRom.setUnitNumber(unitNumber); cdRom.setKey(key); return getCDSpec(cdSpecs, operation, cdRom); } else { VirtualCdrom cdRemove = findVirtualDevice(VirtualCdrom.class, virtualDevicesList, vmInputs); if (cdRemove != null) { return getCDSpec(cdSpecs, operation, cdRemove); } } throw new RuntimeException("No optical device named: [" + vmInputs.getUpdateValue() + "] can be found."); }
private VirtualDeviceConfigSpec getCDSpec(VirtualDeviceConfigSpec cdSpecs, VirtualDeviceConfigSpecOperation operation, VirtualCdrom cdRom) { cdSpecs.setOperation(operation); cdSpecs.setDevice(cdRom); return cdSpecs; }
public VirtualDevice getIsoDevice() throws Exception { List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device"); if (devices != null && devices.size() > 0) { for (VirtualDevice device : devices) { if (device instanceof VirtualCdrom) { return device; } } } return null; }
public VirtualDevice getIsoDevice(int key) throws Exception { List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device"); if (devices != null && devices.size() > 0) { for (VirtualDevice device : devices) { if (device instanceof VirtualCdrom && device.getKey() == key) { return device; } } } return null; }
public VirtualDevice getIsoDevice(String filename) throws Exception { List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient(). getDynamicProperty(_mor, "config.hardware.device"); if(devices != null && devices.size() > 0) { for(VirtualDevice device : devices) { if(device instanceof VirtualCdrom && device.getBacking() instanceof VirtualCdromIsoBackingInfo && ((VirtualCdromIsoBackingInfo)device.getBacking()).getFileName().equals(filename)) { return device; } } } return null; }
private List<VirtualDevice> getListOfVirtualCdRom(ArrayOfVirtualDevice devices) { return devices.getVirtualDevice().stream() .filter(d -> d instanceof VirtualCdrom) .collect(Collectors.toList()); }
/** * Changes to backing of the cdrom to an iso-backed one. * * @param cdrom * @param imagePath * path to iso on disk, sth. like "[datastore] /images/ubuntu-16.04-amd64.iso" */ public static void insertCdrom(VirtualCdrom cdrom, String imagePath) { VirtualCdromIsoBackingInfo backing = new VirtualCdromIsoBackingInfo(); backing.setFileName(imagePath); cdrom.setBacking(backing); }