use of com.vmware.vim25.StorageIOAllocationInfo 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.StorageIOAllocationInfo in project photon-model by vmware.
the class ClientUtils method getStorageIOAllocationInfo.
/**
* Constructs storage IO allocation if this is not already dictated by the storage policy that
* is chosen.
*/
public static StorageIOAllocationInfo getStorageIOAllocationInfo(DiskService.DiskStateExpanded diskState) throws NumberFormatException {
if (diskState.customProperties != null) {
String sharesLevel = diskState.customProperties.get(SHARES_LEVEL);
// set anything on the API for this. Hence default to null.
if (sharesLevel != null) {
try {
StorageIOAllocationInfo allocationInfo = new StorageIOAllocationInfo();
SharesInfo sharesInfo = new SharesInfo();
sharesInfo.setLevel(SharesLevel.fromValue(sharesLevel));
if (sharesInfo.getLevel() == SharesLevel.CUSTOM) {
// Set shares value
String sharesVal = diskState.customProperties.get(SHARES);
if (sharesVal == null || sharesVal.isEmpty()) {
// Reset to normal as nothing is specified for the shares
sharesInfo.setLevel(SharesLevel.NORMAL);
} else {
sharesInfo.setShares(Integer.parseInt(sharesVal));
}
}
allocationInfo.setShares(sharesInfo);
String limitIops = diskState.customProperties.get(LIMIT_IOPS);
if (limitIops != null && !limitIops.isEmpty()) {
allocationInfo.setLimit(Long.parseLong(limitIops));
}
return allocationInfo;
} catch (Exception e) {
logger.warn("Ignoring the storage IO allocation customization values due to {}", e.getMessage());
return null;
}
}
}
return null;
}
Aggregations