Search in sources :

Example 1 with VirtualDeviceFileBackingInfo

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;
}
Also used : StorageIOAllocationInfo(com.vmware.vim25.StorageIOAllocationInfo) VirtualDeviceFileBackingInfo(com.vmware.vim25.VirtualDeviceFileBackingInfo) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) VirtualDeviceConfigSpecFileOperation(com.vmware.vim25.VirtualDeviceConfigSpecFileOperation) Operation(com.vmware.xenon.common.Operation) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) DiskService(com.vmware.photon.controller.model.resources.DiskService)

Example 2 with VirtualDeviceFileBackingInfo

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.
    }
}
Also used : VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDiskType(com.vmware.vim25.VirtualDiskType) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException)

Aggregations

FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 DiskStateExpanded (com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded)1 StorageIOAllocationInfo (com.vmware.vim25.StorageIOAllocationInfo)1 VirtualDeviceConfigSpecFileOperation (com.vmware.vim25.VirtualDeviceConfigSpecFileOperation)1 VirtualDeviceConfigSpecOperation (com.vmware.vim25.VirtualDeviceConfigSpecOperation)1 VirtualDeviceFileBackingInfo (com.vmware.vim25.VirtualDeviceFileBackingInfo)1 VirtualDiskFlatVer1BackingInfo (com.vmware.vim25.VirtualDiskFlatVer1BackingInfo)1 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)1 VirtualDiskType (com.vmware.vim25.VirtualDiskType)1 Operation (com.vmware.xenon.common.Operation)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1