use of com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER 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