Search in sources :

Example 6 with VirtualMachineRelocateSpecDiskLocator

use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project photon-model by vmware.

the class InstanceClient method cloneVm.

private ManagedObjectReference cloneVm(ManagedObjectReference template) throws Exception {
    ManagedObjectReference folder = getVmFolder();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
    ManagedObjectReference datastore = getDataStoreForDisk(this.bootDisk, pbmSpec);
    ManagedObjectReference resourcePool = getResourcePool();
    Map<String, Object> props = this.get.entityProps(template, VimPath.vm_config_hardware_device);
    ArrayOfVirtualDevice devices = (ArrayOfVirtualDevice) props.get(VimPath.vm_config_hardware_device);
    VirtualDisk vd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).findFirst().orElse(null);
    VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
    relocSpec.setDatastore(datastore);
    if (pbmSpec != null) {
        pbmSpec.stream().forEach(spec -> {
            relocSpec.getProfile().add(spec);
        });
    }
    relocSpec.setFolder(folder);
    relocSpec.setPool(resourcePool);
    relocSpec.setDiskMoveType(computeDiskMoveType().value());
    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocSpec);
    // Set the provisioning type of the parent disk.
    VirtualMachineRelocateSpecDiskLocator diskProvisionTypeLocator = setProvisioningType(vd, datastore, pbmSpec);
    if (diskProvisionTypeLocator != null) {
        cloneSpec.getLocation().getDisk().add(diskProvisionTypeLocator);
    }
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);
    String displayName = this.ctx.child.name;
    ManagedObjectReference cloneTask = getVimPort().cloneVMTask(template, folder, displayName, cloneSpec);
    TaskInfo info = waitTaskEnd(cloneTask);
    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }
    return (ManagedObjectReference) info.getResult();
}
Also used : ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) VirtualDiskSpec(com.vmware.vim25.VirtualDiskSpec) ClientUtils.fillInControllerUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.findFreeScsiUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeScsiUnit) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ClientUtils.getFirstIdeController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstIdeController) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) Utils(com.vmware.xenon.common.Utils) Document(org.w3c.dom.Document) Map(java.util.Map) VirtualDevice(com.vmware.vim25.VirtualDevice) EnumSet(java.util.EnumSet) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) ClientUtils.createHdd(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd) ClientUtils.getFirstScsiController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstScsiController) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ClientUtils.nextUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.nextUnitNumber) ClientUtils.getFirstSioController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstSioController) ClientUtils.getDatastorePathForDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastorePathForDisk) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) DuplicateNameFaultMsg(com.vmware.vim25.DuplicateNameFaultMsg) ArrayUpdateOperation(com.vmware.vim25.ArrayUpdateOperation) UriUtils(com.vmware.xenon.common.UriUtils) ClientUtils.detachDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk) VirtualFloppy(com.vmware.vim25.VirtualFloppy) ClientUtils.getStorageIOAllocationInfo(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getStorageIOAllocationInfo) Finder(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Finder) OvfDeployer(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController) OptionValue(com.vmware.vim25.OptionValue) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) VirtualCdrom(com.vmware.vim25.VirtualCdrom) STORAGE_REFERENCE(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_REFERENCE) OvfRetriever(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever) ClientUtils.getDiskProvisioningType(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskProvisioningType) DISK_DATASTORE_NAME(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_DATASTORE_NAME) VirtualMachineRelocateDiskMoveOptions(com.vmware.vim25.VirtualMachineRelocateDiskMoveOptions) InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) DiskStatus(com.vmware.photon.controller.model.resources.DiskService.DiskStatus) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) ClientUtils.getDiskMode(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskMode) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClientUtils.findFreeUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeUnit) ClientUtils.insertCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertCdrom) MethodFault(com.vmware.vim25.MethodFault) Lock(java.util.concurrent.locks.Lock) VirtualDisk(com.vmware.vim25.VirtualDisk) Paths(java.nio.file.Paths) InvalidNameFaultMsg(com.vmware.vim25.InvalidNameFaultMsg) ClientUtils.insertFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertFloppy) VAppPropertySpec(com.vmware.vim25.VAppPropertySpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualEthernetCardMacType(com.vmware.vim25.VirtualEthernetCardMacType) OvfParser(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser) BaseHelper(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BaseHelper) LoggerFactory(org.slf4j.LoggerFactory) ClientUtils.toKb(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.toKb) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VAppPropertyInfo(com.vmware.vim25.VAppPropertyInfo) ClientUtils.getPbmProfileSpec(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getPbmProfileSpec) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VM_PATH_FORMAT(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) DuplicateName(com.vmware.vim25.DuplicateName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualPCIController(com.vmware.vim25.VirtualPCIController) ClientUtils.createCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom) Entry(java.util.Map.Entry) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) FileAlreadyExists(com.vmware.vim25.FileAlreadyExists) ClientUtils.makePathToVmdkFile(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.makePathToVmdkFile) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) NetworkDeviceBackingFactory(com.vmware.photon.controller.model.adapters.vsphere.network.NetworkDeviceBackingFactory) ClientUtils.getDatastoreFromStoragePolicy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastoreFromStoragePolicy) Logger(org.slf4j.Logger) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ReentrantLock(java.util.concurrent.locks.ReentrantLock) VirtualE1000(com.vmware.vim25.VirtualE1000) Operation(com.vmware.xenon.common.Operation) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER) ClientUtils.createFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) DISK_PARENT_DIRECTORY(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_PARENT_DIRECTORY) TimeUnit(java.util.concurrent.TimeUnit) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) VirtualSCSISharing(com.vmware.vim25.VirtualSCSISharing) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Collections(java.util.Collections) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) MethodFault(com.vmware.vim25.MethodFault) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) FileAlreadyExists(com.vmware.vim25.FileAlreadyExists) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator)

Example 7 with VirtualMachineRelocateSpecDiskLocator

use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project cloudstack by apache.

the class VmwareResource method execute.

// OfflineVmwareMigration: refactor to be able to handle a detached volume
private Answer execute(MigrateVolumeCommand cmd) {
    String volumePath = cmd.getVolumePath();
    String chainInfo = cmd.getChainInfo();
    StorageFilerTO poolTo = cmd.getPool();
    VolumeObjectTO volumeObjectTO = (VolumeObjectTO) cmd.getSrcData();
    String vmName = cmd.getAttachedVmName();
    VirtualMachineMO vmMo = null;
    VmwareHypervisorHost srcHyperHost = null;
    // OfflineVmwareMigration: ifhost is null ???
    if (StringUtils.isBlank(cmd.getAttachedVmName())) {
        return migrateVolume(cmd);
    }
    ManagedObjectReference morDs = null;
    ManagedObjectReference morDc = null;
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
    List<VirtualMachineRelocateSpecDiskLocator> diskLocators = new ArrayList<VirtualMachineRelocateSpecDiskLocator>();
    VirtualMachineRelocateSpecDiskLocator diskLocator = null;
    String tgtDsName = "";
    try {
        srcHyperHost = getHyperHost(getServiceContext());
        morDc = srcHyperHost.getHyperHostDatacenter();
        tgtDsName = poolTo.getUuid();
        // find VM in this datacenter not just in this cluster.
        DatacenterMO dcMo = new DatacenterMO(getServiceContext(), morDc);
        vmMo = dcMo.findVm(vmName);
        if (vmMo == null) {
            String msg = "VM " + vmName + " does not exist in VMware datacenter " + morDc.getValue();
            s_logger.error(msg);
            throw new CloudRuntimeException(msg);
        }
        vmName = vmMo.getName();
        morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, tgtDsName);
        if (morDs == null) {
            String msg = "Unable to find the mounted datastore with name: " + tgtDsName + " on source host: " + srcHyperHost.getHyperHostName() + " to execute MigrateVolumeCommand";
            s_logger.error(msg);
            throw new Exception(msg);
        }
        DatastoreMO targetDsMo = new DatastoreMO(srcHyperHost.getContext(), morDs);
        if (cmd.getContextParam(DiskTO.PROTOCOL_TYPE) != null && cmd.getContextParam(DiskTO.PROTOCOL_TYPE).equalsIgnoreCase("DatastoreCluster")) {
            VmwareContext context = getServiceContext();
            VmwareHypervisorHost hyperHost = getHyperHost(context);
            VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
            VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDiskWithVolumeDetails(diskInfoBuilder, volumePath, chainInfo, false, null, poolTo.getUuid(), hyperHost, context);
            if (diskInfoBuilder != null && matchingExistingDisk != null) {
                String[] diskChain = matchingExistingDisk.getDiskChain();
                DatastoreFile file = new DatastoreFile(diskChain[0]);
                if (!file.getFileBaseName().equalsIgnoreCase(volumePath)) {
                    if (s_logger.isInfoEnabled())
                        s_logger.info("Detected disk-chain top file change on volume: " + volumePath + " -> " + file.getFileBaseName());
                    volumePath = file.getFileBaseName();
                }
            }
        }
        String fullVolumePath = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(targetDsMo, vmName, volumePath + VMDK_EXTENSION);
        Pair<VirtualDisk, String> diskInfo = getVirtualDiskInfo(vmMo, appendFileType(volumePath, VMDK_EXTENSION));
        String vmdkAbsFile = getAbsoluteVmdkFile(diskInfo.first());
        if (vmdkAbsFile != null && !vmdkAbsFile.isEmpty()) {
            vmMo.updateAdapterTypeIfRequired(vmdkAbsFile);
        }
        int diskId = diskInfo.first().getKey();
        diskLocator = new VirtualMachineRelocateSpecDiskLocator();
        diskLocator.setDatastore(morDs);
        diskLocator.setDiskId(diskId);
        diskLocators.add(diskLocator);
        if (cmd.getVolumeType() == Volume.Type.ROOT) {
            relocateSpec.setDatastore(morDs);
            // If a target datastore is provided for the VM, then by default all volumes associated with the VM will be migrated to that target datastore.
            // Hence set the existing datastore as target datastore for volumes that are not to be migrated.
            List<Pair<Integer, ManagedObjectReference>> diskDatastores = vmMo.getAllDiskDatastores();
            for (Pair<Integer, ManagedObjectReference> diskDatastore : diskDatastores) {
                if (diskDatastore.first().intValue() != diskId) {
                    diskLocator = new VirtualMachineRelocateSpecDiskLocator();
                    diskLocator.setDiskId(diskDatastore.first().intValue());
                    diskLocator.setDatastore(diskDatastore.second());
                    diskLocators.add(diskLocator);
                }
            }
        }
        relocateSpec.getDisk().addAll(diskLocators);
        // Change datastore
        if (!vmMo.changeDatastore(relocateSpec)) {
            throw new Exception("Change datastore operation failed during volume migration");
        } else {
            s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName);
        }
        // further volume operations on the ROOT volume such as volume snapshot etc. will result in DB inconsistencies.
        if (!vmMo.consolidateVmDisks()) {
            s_logger.warn("VM disk consolidation failed after storage migration.");
        } else {
            s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
        }
        // Update and return volume path and chain info because that could have changed after migration
        if (!targetDsMo.fileExists(fullVolumePath)) {
            VirtualDisk[] disks = vmMo.getAllDiskDevice();
            for (VirtualDisk disk : disks) if (disk.getKey() == diskId) {
                volumePath = vmMo.getVmdkFileBaseName(disk);
            }
        }
        VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
        chainInfo = _gson.toJson(diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, targetDsMo.getName()));
        MigrateVolumeAnswer answer = new MigrateVolumeAnswer(cmd, true, null, volumePath);
        answer.setVolumeChainInfo(chainInfo);
        return answer;
    } catch (Exception e) {
        String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
        s_logger.error(msg, e);
        return new MigrateVolumeAnswer(cmd, false, msg, null);
    }
}
Also used : ArrayList(java.util.ArrayList) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) Pair(com.cloud.utils.Pair) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) VirtualDisk(com.vmware.vim25.VirtualDisk) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 8 with VirtualMachineRelocateSpecDiskLocator

use of com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator in project cloudstack by apache.

the class VirtualMachineMO method setDiskProvisioningType.

private void setDiskProvisioningType(VirtualMachineRelocateSpec relocSpec, ManagedObjectReference morDs, Storage.ProvisioningType diskProvisioningType) throws Exception {
    if (diskProvisioningType == null) {
        return;
    }
    List<VirtualMachineRelocateSpecDiskLocator> relocateDisks = relocSpec.getDisk();
    List<VirtualDisk> disks = this.getVirtualDisks();
    for (VirtualDisk disk : disks) {
        VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) disk.getBacking();
        if (diskProvisioningType == Storage.ProvisioningType.FAT) {
            backing.setThinProvisioned(false);
            backing.setEagerlyScrub(true);
        } else if (diskProvisioningType == Storage.ProvisioningType.THIN) {
            backing.setThinProvisioned(true);
        } else if (diskProvisioningType == Storage.ProvisioningType.SPARSE) {
            backing.setThinProvisioned(false);
            backing.setEagerlyScrub(false);
        }
        VirtualMachineRelocateSpecDiskLocator diskLocator = new VirtualMachineRelocateSpecDiskLocator();
        diskLocator.setDiskId(disk.getKey());
        diskLocator.setDiskBackingInfo(backing);
        diskLocator.setDatastore(morDs);
        relocateDisks.add(diskLocator);
    }
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator)

Aggregations

VirtualMachineRelocateSpecDiskLocator (com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator)8 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)7 VirtualDisk (com.vmware.vim25.VirtualDisk)7 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 ArrayList (java.util.ArrayList)5 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)4 VirtualMachineCloneSpec (com.vmware.vim25.VirtualMachineCloneSpec)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 RESOURCE_GROUP_NAME (com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME)2 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)2 VM_PATH_FORMAT (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT)2 ClientUtils.createCdrom (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom)2 ClientUtils.createFloppy (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy)2 ClientUtils.createHdd (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd)2 ClientUtils.detachDisk (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk)2 ClientUtils.fillInControllerUnitNumber (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber)2 ClientUtils.findFreeScsiUnit (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeScsiUnit)2 ClientUtils.findFreeUnit (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeUnit)2 ClientUtils.findMatchingVirtualDevice (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice)2