Search in sources :

Example 6 with HostDatastoreSystem

use of com.vmware.vim25.mo.HostDatastoreSystem in project cloudstack by apache.

the class VmwareStorageProcessor method cleanUpDatastore.

/**
 * 1) Possibly expand the datastore.
 * 2) Possibly consolidate all relevant VMDK files into one VMDK file.
 * 3) Possibly move the VMDK file to the root folder (may already be there).
 * 4) If the VMDK file wasn't already in the root folder, then delete the folder the VMDK file was in.
 * 5) Possibly rename the VMDK file (this will lead to there being a delta file with the new name and the
 *    original file with the original name).
 *
 * Note: If the underlying VMDK file was for a root disk, the 'vmdk' parameter's value might look, for example,
 *  like "i-2-32-VM/ROOT-32.vmdk".
 *
 * Note: If the underlying VMDK file was for a data disk, the 'vmdk' parameter's value might look, for example,
 *  like "-iqn.2010-01.com.solidfire:4nhe.data-32.79-0.vmdk".
 *
 * Returns the (potentially new) name of the VMDK file.
 */
private String cleanUpDatastore(Command cmd, HostDatastoreSystemMO hostDatastoreSystem, DatastoreMO dsMo, Map<String, String> details) throws Exception {
    s_logger.debug(String.format("Executing clean up in DataStore: [%s].", dsMo.getName()));
    boolean expandDatastore = Boolean.parseBoolean(details.get(DiskTO.EXPAND_DATASTORE));
    // reserve value in use is set to the minimum for the cloned volume), but that's fine.
    if (expandDatastore) {
        expandDatastore(hostDatastoreSystem, dsMo);
    }
    String vmdk = details.get(DiskTO.VMDK);
    String fullVmdkPath = new DatastoreFile(dsMo.getName(), vmdk).getPath();
    VmwareContext context = hostService.getServiceContext(null);
    VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
    DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
    String vmName = getVmName(vmdk);
    // If vmName is not null, then move all VMDK files out of this folder to the root folder and then delete the folder named vmName.
    if (vmName != null) {
        String workerVmName = hostService.getWorkerName(context, cmd, 0, dsMo);
        VirtualMachineMO vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVmName, null);
        if (vmMo == null) {
            throw new Exception("Unable to create a worker VM for volume creation");
        }
        vmMo.attachDisk(new String[] { fullVmdkPath }, dsMo.getMor());
        List<String> backingFiles = new ArrayList<>(1);
        List<VirtualDisk> virtualDisks = vmMo.getVirtualDisks();
        VirtualDisk virtualDisk = virtualDisks.get(0);
        VirtualDeviceBackingInfo virtualDeviceBackingInfo = virtualDisk.getBacking();
        while (virtualDeviceBackingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
            VirtualDiskFlatVer2BackingInfo backingInfo = (VirtualDiskFlatVer2BackingInfo) virtualDeviceBackingInfo;
            backingFiles.add(backingInfo.getFileName());
            virtualDeviceBackingInfo = backingInfo.getParent();
        }
        vmMo.detachAllDisksAndDestroy();
        VmwareStorageLayoutHelper.moveVolumeToRootFolder(dcMo, backingFiles);
        vmdk = new DatastoreFile(vmdk).getFileName();
        // Delete the folder the VMDK file was in.
        DatastoreFile folderToDelete = new DatastoreFile(dsMo.getName(), vmName);
        dsMo.deleteFolder(folderToDelete.getPath(), dcMo.getMor());
    }
    return vmdk;
}
Also used : VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VirtualDisk(com.vmware.vim25.VirtualDisk) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 7 with HostDatastoreSystem

use of com.vmware.vim25.mo.HostDatastoreSystem in project cloudstack by apache.

the class VmwareStorageProcessor method prepareManagedDatastore.

private ManagedObjectReference prepareManagedDatastore(VmwareContext context, VmwareHypervisorHost hyperHost, String diskUuid, String iScsiName, String storageHost, int storagePort, String chapInitiatorUsername, String chapInitiatorSecret, String chapTargetUsername, String chapTargetSecret) throws Exception {
    if (storagePort == DEFAULT_NFS_PORT) {
        s_logger.info("creating the NFS datastore with the following configuration - storageHost: " + storageHost + ", storagePort: " + storagePort + ", exportpath: " + iScsiName + "and diskUuid : " + diskUuid);
        ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
        ClusterMO cluster = new ClusterMO(context, morCluster);
        List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
        HostMO host = new HostMO(context, lstHosts.get(0).first());
        HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
        return hostDatastoreSystem.createNfsDatastore(storageHost, storagePort, iScsiName, diskUuid);
    } else {
        return getVmfsDatastore(context, hyperHost, VmwareResource.getDatastoreName(iScsiName), storageHost, storagePort, trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostDatastoreSystemMO(com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 8 with HostDatastoreSystem

use of com.vmware.vim25.mo.HostDatastoreSystem in project cloudstack by apache.

the class VmwareStorageProcessor method expandDatastore.

public void expandDatastore(HostDatastoreSystemMO hostDatastoreSystem, DatastoreMO datastoreMO) throws Exception {
    List<VmfsDatastoreOption> vmfsDatastoreOptions = hostDatastoreSystem.queryVmfsDatastoreExpandOptions(datastoreMO);
    if (vmfsDatastoreOptions != null && vmfsDatastoreOptions.size() > 0) {
        VmfsDatastoreExpandSpec vmfsDatastoreExpandSpec = (VmfsDatastoreExpandSpec) vmfsDatastoreOptions.get(0).getSpec();
        hostDatastoreSystem.expandVmfsDatastore(datastoreMO, vmfsDatastoreExpandSpec);
    }
}
Also used : VmfsDatastoreExpandSpec(com.vmware.vim25.VmfsDatastoreExpandSpec) VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption)

Aggregations

ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)3 HostDatastoreSystemMO (com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO)3 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)3 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)3 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)3 Pair (com.cloud.utils.Pair)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 RemoteException (java.rmi.RemoteException)3 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)2 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertySpec (com.vmware.vim25.PropertySpec)2 TraversalSpec (com.vmware.vim25.TraversalSpec)2 VirtualDisk (com.vmware.vim25.VirtualDisk)2 VmfsDatastoreOption (com.vmware.vim25.VmfsDatastoreOption)2 ArrayList (java.util.ArrayList)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)1