use of com.vmware.vim25.VirtualDeviceFileBackingInfo in project photon-model by vmware.
the class ClientUtils method handleVirtualDiskUpdate.
/**
* Process VirtualDisk and update the details in the diskLinks of the provisioned compute
*/
public static Operation handleVirtualDiskUpdate(String endpointLink, DiskStateExpanded matchedDs, VirtualDisk disk, List<String> diskLinks, String regionId, Service service, String vm, String dcLink, EnumerationProgress ctx, ComputeState oldDocument) {
if (disk.getBacking() == null || !(disk.getBacking() instanceof VirtualDeviceFileBackingInfo)) {
return null;
}
VirtualDeviceFileBackingInfo backing = (VirtualDeviceFileBackingInfo) disk.getBacking();
Operation operation;
DiskService.DiskState ds;
if (matchedDs == null) {
// This is the new disk, hence add it to the list
ds = new DiskService.DiskStateExpanded();
ds.documentSelfLink = UriUtils.buildUriPath(DiskService.FACTORY_LINK, service.getHost().nextUUID());
ds.name = disk.getDeviceInfo().getLabel();
ds.creationTimeMicros = Utils.getNowMicrosUtc();
ds.type = DiskService.DiskType.HDD;
ds.regionId = regionId;
ds.capacityMBytes = disk.getCapacityInKB() / 1024;
ds.sourceImageReference = VimUtils.datastorePathToUri(backing.getFileName());
ds.persistent = Boolean.FALSE;
addEndpointLinks(ds, endpointLink);
updateDiskStateFromVirtualDisk(disk, ds);
updateDiskStateFromBackingInfo(backing, ds);
if (disk.getStorageIOAllocation() != null) {
StorageIOAllocationInfo storageInfo = disk.getStorageIOAllocation();
CustomProperties.of(ds).put(SHARES, storageInfo.getShares().getShares()).put(LIMIT_IOPS, storageInfo.getLimit()).put(SHARES_LEVEL, storageInfo.getShares().getLevel().value());
}
if (null != oldDocument) {
// we have vm state document, populate vm self link in disk state
CustomProperties.of(ds).put(VIRTUAL_MACHINE_LINK, oldDocument.documentSelfLink);
}
fillInControllerUnitNumber(ds, disk.getUnitNumber());
diskLinks.add(ds.documentSelfLink);
} else {
// This is known disk, hence update with the provisioned attributes.
ds = matchedDs;
ds.sourceImageReference = VimUtils.datastorePathToUri(backing.getFileName());
if (matchedDs.persistent == null) {
matchedDs.persistent = Boolean.FALSE;
}
ds.regionId = regionId;
addEndpointLinks(ds, endpointLink);
updateDiskStateFromVirtualDisk(disk, ds);
updateDiskStateFromBackingInfo(backing, ds);
}
CustomProperties.of(ds).put(CustomProperties.DISK_DATASTORE_NAME, backing.getDatastore().getValue()).put(CustomProperties.TYPE, VirtualDisk.class.getSimpleName()).put(CustomProperties.DISK_PROVISION_IN_GB, disk.getCapacityInKB() / (1024 * 1024)).put(CustomProperties.DATACENTER_SELF_LINK, dcLink).put(CustomProperties.DISK_PARENT_VM, vm);
// Disk needs the VMs MoRef for the functional Key
if (ctx != null) {
VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(ds, ctx.getVcUuid(), VimUtils.convertStringToMoRef(vm));
}
operation = (matchedDs == null) ? createDisk(ds, service) : createDiskPatch(ds, service);
return operation;
}
use of com.vmware.vim25.VirtualDeviceFileBackingInfo in project photon-model by vmware.
the class ClientUtils method updateDiskStateFromBackingInfo.
private static void updateDiskStateFromBackingInfo(VirtualDeviceFileBackingInfo backing, DiskService.DiskState ds) {
try {
if (backing instanceof VirtualDiskFlatVer1BackingInfo) {
VirtualDiskFlatVer1BackingInfo flatVer1 = (VirtualDiskFlatVer1BackingInfo) backing;
updateDiskModeInDiskState(VirtualDiskMode.fromValue(flatVer1.getDiskMode()), ds);
} else if (backing instanceof VirtualDiskFlatVer2BackingInfo) {
VirtualDiskFlatVer2BackingInfo flatVer2 = (VirtualDiskFlatVer2BackingInfo) backing;
updateDiskModeInDiskState(VirtualDiskMode.fromValue(flatVer2.getDiskMode()), ds);
// Update the provisioning type as well.
VirtualDiskType diskType = VirtualDiskType.THICK;
if (flatVer2.isThinProvisioned()) {
diskType = VirtualDiskType.THIN;
} else if (flatVer2.isEagerlyScrub()) {
diskType = VirtualDiskType.EAGER_ZEROED_THICK;
}
CustomProperties.of(ds).put(PROVISION_TYPE, diskType.value());
}
} catch (Exception e) {
// any exception ignore it. it won't update the properties in the disk.
}
}
Aggregations