use of com.vmware.vim25.VirtualFloppy in project photon-model by vmware.
the class ClientUtils method createFloppy.
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;
}
use of com.vmware.vim25.VirtualFloppy in project photon-model by vmware.
the class ClientUtils method attachDiskToVM.
public static String attachDiskToVM(ArrayOfVirtualDevice devices, ManagedObjectReference vm, DiskService.DiskStateExpanded diskState, ManagedObjectReference diskDatastore, Connection connection, VimPortType vimPort) throws Exception {
String diskPath = VimUtils.uriToDatastorePath(diskState.sourceImageReference);
String diskFullPath = CustomProperties.of(diskState).getString(DISK_FULL_PATH, null);
Boolean insertCdRom = CustomProperties.of(diskState).getBoolean(INSERT_CDROM, false);
VirtualDeviceConfigSpec deviceConfigSpec = null;
if (diskState.type == DiskService.DiskType.HDD) {
VirtualSCSIController scsiController = getFirstScsiController(devices);
// Get available free unit numbers for the given scsi controller.
Integer[] scsiUnits = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(diskState);
deviceConfigSpec = createHdd(scsiController.getKey(), scsiUnits[0], diskState, diskFullPath, diskDatastore, pbmSpec, false);
} else if (diskState.type == DiskService.DiskType.CDROM) {
if (insertCdRom) {
if (diskPath == null) {
throw new IllegalStateException(String.format("Cannot insert empty iso file into CD-ROM"));
}
// Find first available CD ROM to insert the iso file
VirtualCdrom cdrom = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualCdrom).map(d -> (VirtualCdrom) d).findFirst().orElse(null);
if (cdrom == null) {
throw new IllegalStateException(String.format("Could not find Virtual CD ROM to insert %s.", diskPath));
}
insertCdrom(cdrom, diskPath);
deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(cdrom);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
} else {
VirtualDevice ideController = getFirstIdeController(devices);
int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
int availableUnitNumber = nextUnitNumber(ideUnit);
deviceConfigSpec = createCdrom(ideController, availableUnitNumber);
fillInControllerUnitNumber(diskState, availableUnitNumber);
if (diskPath != null) {
// mount iso image
insertCdrom((VirtualCdrom) deviceConfigSpec.getDevice(), diskPath);
}
// Live add of cd-rom is not possible. Hence it needs to be powered off
// Power off is needed to ADD cd-rom
powerOffVm(connection, vimPort, vm);
}
} else if (diskState.type == DiskService.DiskType.FLOPPY) {
VirtualDevice sioController = getFirstSioController(devices);
int sioUnit = findFreeUnit(sioController, devices.getVirtualDevice());
int availableUnitNumber = nextUnitNumber(sioUnit);
deviceConfigSpec = createFloppy(sioController, availableUnitNumber);
fillInControllerUnitNumber(diskState, availableUnitNumber);
if (diskPath != null) {
insertFloppy((VirtualFloppy) deviceConfigSpec.getDevice(), diskPath);
}
// Power off is needed to ADD floppy
powerOffVm(connection, vimPort, vm);
}
VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
spec.getDeviceChange().add(deviceConfigSpec);
ManagedObjectReference reconfigureTask = vimPort.reconfigVMTask(vm, spec);
TaskInfo info = VimUtils.waitTaskEnd(connection, reconfigureTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
if (!insertCdRom && diskState.type != DiskService.DiskType.HDD) {
// This means it is CDROM or Floppy. Hence power on the VM as it is powered off to
// perform the operation
powerOnVM(connection, vimPort, vm);
}
return diskFullPath;
}
use of com.vmware.vim25.VirtualFloppy in project photon-model by vmware.
the class VSphereAdapterInstanceService method updateDiskLinksAfterProvisionSuccess.
/**
* 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 instanceof VirtualDisk) {
handleVirtualDiskUpdate(ctx.child.endpointLink, matchedDs, (VirtualDisk) disk, diskLinks, ctx.parent.description.regionId, this, CustomProperties.of(state).getString(CustomProperties.MOREF), CustomProperties.of(state).getString(CustomProperties.DATACENTER_SELF_LINK), null, null).sendWith(this);
} else if (disk instanceof VirtualCdrom) {
handleVirtualDeviceUpdate(ctx.child.endpointLink, matchedDs, DiskType.CDROM, disk, diskLinks, ctx.parent.description.regionId, this, true, CustomProperties.of(state).getString(CustomProperties.DATACENTER_SELF_LINK)).sendWith(this);
} else if (disk instanceof VirtualFloppy) {
handleVirtualDeviceUpdate(ctx.child.endpointLink, matchedDs, DiskType.FLOPPY, disk, diskLinks, ctx.parent.description.regionId, this, true, CustomProperties.of(state).getString(CustomProperties.DATACENTER_SELF_LINK)).sendWith(this);
}
}
state.diskLinks = diskLinks;
}
use of com.vmware.vim25.VirtualFloppy in project photon-model by vmware.
the class InstanceClient method attachDisks.
/**
* Creates disks and attaches them to the vm created by {@link #createInstance()}. The given
* diskStates are enriched with data from vSphere and can be patched back to xenon.
*/
public void attachDisks(List<DiskStateExpanded> diskStates, boolean isImageDisks) throws Exception {
if (this.vm == null) {
throw new IllegalStateException("Cannot attach diskStates if VM is not created");
}
EnumSet<DiskType> notSupportedTypes = EnumSet.of(DiskType.SSD, DiskType.NETWORK);
List<DiskStateExpanded> unsupportedDisks = diskStates.stream().filter(d -> notSupportedTypes.contains(d.type)).collect(Collectors.toList());
if (!unsupportedDisks.isEmpty()) {
throw new IllegalStateException("Some diskStates cannot be created: " + unsupportedDisks.stream().map(d -> d.documentSelfLink).collect(Collectors.toList()));
}
// the path to folder holding all vm files
String dir = this.get.entityProp(this.vm, VimPath.vm_config_files_vmPathName);
dir = Paths.get(dir).getParent().toString();
ArrayOfVirtualDevice devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
VirtualSCSIController scsiController = getFirstScsiController(devices);
// Get available free unit numbers for the given scsi controller.
Integer[] scsiUnits = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
VirtualDevice ideController = getFirstIdeController(devices);
int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
VirtualDevice sioController = getFirstSioController(devices);
int sioUnit = findFreeUnit(sioController, devices.getVirtualDevice());
List<VirtualDeviceConfigSpec> newDisks = new ArrayList<>();
boolean cdromAdded = false;
List<DiskStateExpanded> disksToBeCustomized = null;
int scsiUnitIndex = 0;
for (DiskStateExpanded ds : diskStates) {
String diskPath = VimUtils.uriToDatastorePath(ds.sourceImageReference);
if (ds.type == DiskType.HDD) {
// Find if there is a storage policy defined for this disk
List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(ds);
VirtualDeviceConfigSpec hdd;
if (diskPath != null) {
// create full clone of given disk
hdd = createFullCloneAndAttach(diskPath, ds, dir, scsiController, scsiUnits[scsiUnitIndex], pbmSpec);
newDisks.add(hdd);
// When it is through clone, customize after the clone is complete.
if (disksToBeCustomized == null) {
disksToBeCustomized = new ArrayList<>(diskStates.size());
}
if (isImageDisks) {
disksToBeCustomized.add(ds);
}
} else {
String dsDirForDisk = getDatastorePathForDisk(ds, dir);
String diskName = makePathToVmdkFile(ds.name, dsDirForDisk);
hdd = createHdd(scsiController.getKey(), scsiUnits[scsiUnitIndex], ds, diskName, getDataStoreForDisk(ds, pbmSpec), pbmSpec);
newDisks.add(hdd);
}
scsiUnitIndex++;
}
if (ds.type == DiskType.CDROM) {
VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
fillInControllerUnitNumber(ds, ideUnit);
ideUnit = nextUnitNumber(ideUnit);
if (diskPath != null) {
// mount iso image
insertCdrom((VirtualCdrom) cdrom.getDevice(), diskPath);
}
newDisks.add(cdrom);
cdromAdded = true;
}
if (ds.type == DiskType.FLOPPY) {
VirtualDeviceConfigSpec floppy = createFloppy(sioController, sioUnit);
fillInControllerUnitNumber(ds, sioUnit);
sioUnit = nextUnitNumber(sioUnit);
if (diskPath != null) {
// mount iso image
insertFloppy((VirtualFloppy) floppy.getDevice(), diskPath);
}
newDisks.add(floppy);
}
// mark disk as attached
ds.status = DiskStatus.ATTACHED;
}
// add a cdrom so that ovf transport works
if (!cdromAdded && isImageDisks) {
VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
newDisks.add(cdrom);
}
// add disks one at a time
for (VirtualDeviceConfigSpec newDisk : newDisks) {
VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
spec.getDeviceChange().add(newDisk);
ManagedObjectReference reconfigureTask = getVimPort().reconfigVMTask(this.vm, spec);
TaskInfo info = waitTaskEnd(reconfigureTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
}
// If disks are created through full clone, then reconfigure
if (disksToBeCustomized != null && !disksToBeCustomized.isEmpty()) {
// Get the hardware devices once again as they are reconfigured
devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
reconfigureBootDisk(this.vm, getCustomizationConfigSpecs(devices, disksToBeCustomized));
}
}
use of com.vmware.vim25.VirtualFloppy in project photon-model by vmware.
the class ClientUtils method insertFloppy.
/**
* 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);
}
Aggregations