use of com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithAdditionalDisks.
@Test
public void deployFromLibraryWithAdditionalDisks() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState(true, true);
try {
if (vm == null) {
return;
}
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
assertEquals(3, virtualDisks.size());
assertEquals(3, vm.diskLinks.size());
List<DeferredResult<DiskService.DiskState>> disks = vm.diskLinks.stream().map(link -> {
Operation getOp = Operation.createGet(this.host, link).setReferer(this.host.getReferer());
return this.host.sendWithDeferredResult(getOp, DiskService.DiskState.class);
}).collect(Collectors.toList());
DeferredResult.allOf(disks).thenAccept(diskStates -> diskStates.stream().forEach(ds -> {
assertNotNull(ds.customProperties);
assertNotNull(ds.sourceImageReference);
assertNotNull(ds.customProperties.get(PROVIDER_DISK_UNIQUE_ID));
}));
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID in project photon-model by vmware.
the class InstanceClient method handleVirtualDiskCleanup.
/**
* For every disk states in the compute based on the persistent flag if it is set as TRUE,
* then disk will be detached before we delete the vm.
*/
private void handleVirtualDiskCleanup(ServiceHost serviceHost, ManagedObjectReference vm, ArrayOfVirtualDevice devices, List<DiskStateExpanded> disks) throws Exception {
if (CollectionUtils.isEmpty(disks)) {
return;
}
List<DiskStateExpanded> persistDisks = disks.stream().filter(disk -> disk.type == DiskType.HDD).filter(disk -> disk.persistent != null && disk.persistent).collect(Collectors.toList());
if (CollectionUtils.isEmpty(persistDisks)) {
return;
}
List<Operation> diskUpdateOps = new ArrayList<>(persistDisks.size());
for (DiskStateExpanded ds : persistDisks) {
VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices), ds);
if (vd != null) {
detachDisk(this.connection, vd, vm, getVimPort());
}
// Now update the status of the persistent disks to be AVAILABLE
ds.status = DiskService.DiskStatus.AVAILABLE;
CustomProperties.of(ds).put(DISK_CONTROLLER_NUMBER, (String) null).put(PROVIDER_DISK_UNIQUE_ID, (String) null);
ds.id = UriUtils.getLastPathSegment(ds.documentSelfLink);
diskUpdateOps.add(Operation.createPut(PhotonModelUriUtils.createInventoryUri(serviceHost, ds.documentSelfLink)).setReferer(serviceHost.getUri()).setBody(ds));
disks.remove(ds);
}
// call patch operations on the disk states
OperationJoin.create(diskUpdateOps).setCompletion((os, errors) -> {
if (errors != null && !errors.isEmpty()) {
logger.warn(String.format("Exception in updating persistent disk during deletion of VM." + " Error : %s", Utils.toString(errors)));
}
}).sendWith(serviceHost);
}
Aggregations