public static VirtualDeviceConfigSpec createFloppy(VirtualDevice sioController, int unitNumber) { VirtualFloppy floppy = new VirtualFloppy(); floppy.setControllerKey(sioController.getKey()); floppy.setUnitNumber(unitNumber); VirtualDeviceConnectInfo info = new VirtualDeviceConnectInfo(); info.setAllowGuestControl(true); info.setConnected(true); info.setStartConnected(true); floppy.setConnectable(info); VirtualFloppyDeviceBackingInfo backing = new VirtualFloppyDeviceBackingInfo(); backing.setDeviceName(String.format("floppy-%d", unitNumber)); floppy.setBacking(backing); VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec(); spec.setDevice(floppy); spec.setOperation(VirtualDeviceConfigSpecOperation.ADD); 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; }
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); }
/** * Changes to backing of the floppy to an image-backed one. */ public static void insertFloppy(VirtualFloppy floppy, String imagePath) { VirtualFloppyImageBackingInfo backingInfo = new VirtualFloppyImageBackingInfo(); backingInfo.setFileName(imagePath); floppy.setBacking(backingInfo); }
private List<VirtualDevice> getListOfVirtualFloppy(ArrayOfVirtualDevice devices) { return devices.getVirtualDevice().stream() .filter(d -> d instanceof VirtualFloppy) .collect(Collectors.toList()); }