Search in sources :

Example 56 with Folder

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

the class VirtualStorageObjectManagerMO method createDisk.

public VStorageObject createDisk(ManagedObjectReference morDS, Storage.ProvisioningType diskProvisioningType, long currentSizeInBytes, String datastoreFilepath, String filename) throws Exception {
    long currentSizeInMB = currentSizeInBytes / (1024 * 1024);
    VslmCreateSpecDiskFileBackingSpec diskFileBackingSpec = new VslmCreateSpecDiskFileBackingSpec();
    diskFileBackingSpec.setDatastore(morDS);
    if (diskProvisioningType != null) {
        if (diskProvisioningType == Storage.ProvisioningType.FAT) {
            diskFileBackingSpec.setProvisioningType(BaseConfigInfoDiskFileBackingInfoProvisioningType.EAGER_ZEROED_THICK.value());
        } else if (diskProvisioningType == Storage.ProvisioningType.THIN) {
            diskFileBackingSpec.setProvisioningType(BaseConfigInfoDiskFileBackingInfoProvisioningType.THIN.value());
        } else if (diskProvisioningType == Storage.ProvisioningType.SPARSE) {
            diskFileBackingSpec.setProvisioningType(BaseConfigInfoDiskFileBackingInfoProvisioningType.LAZY_ZEROED_THICK.value());
        }
    }
    // path should be just the folder name. For example, instead of '[datastore1] folder1/filename.vmdk' you would just do 'folder1'.
    // path is introduced from 6.7. In 6.5 disk will be created in the default folder "fcd"
    diskFileBackingSpec.setPath(null);
    VslmCreateSpec vslmCreateSpec = new VslmCreateSpec();
    vslmCreateSpec.setBackingSpec(diskFileBackingSpec);
    vslmCreateSpec.setCapacityInMB(currentSizeInMB);
    vslmCreateSpec.setName(filename);
    ManagedObjectReference morTask = _context.getService().createDiskTask(_mor, vslmCreateSpec);
    boolean result = _context.getVimClient().waitForTask(morTask);
    VStorageObject vStorageObject = null;
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        // _context.getService().reconcileDatastoreInventoryTask(_mor, morDS);
        TaskInfo taskInfo = TaskMO.getTaskInfo(_context, morTask);
        vStorageObject = (VStorageObject) taskInfo.getResult();
    } else {
        LOGGER.error("VMware CreateDisk_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return vStorageObject;
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo) VslmCreateSpecDiskFileBackingSpec(com.vmware.vim25.VslmCreateSpecDiskFileBackingSpec) VslmCreateSpec(com.vmware.vim25.VslmCreateSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VStorageObject(com.vmware.vim25.VStorageObject)

Example 57 with Folder

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

the class DatastoreMO method folderExists.

public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
    if (results != null) {
        List<FileInfo> info = results.getFile();
        if (info != null && info.size() > 0) {
            s_logger.info("Folder " + folderName + " exists on datastore");
            return true;
        }
    }
    s_logger.info("Folder " + folderName + " does not exist on datastore");
    return false;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Example 58 with Folder

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

the class VirtualMachineMO method getVmxHttpAccessUrl.

public String getVmxHttpAccessUrl() throws Exception {
    Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
    VirtualMachineFileInfo fileInfo = getFileInfo();
    String vmxFilePath = fileInfo.getVmPathName();
    String[] vmxPathTokens = vmxFilePath.split("\\[|\\]|/");
    StringBuffer sb = new StringBuffer("https://" + _context.getServerAddress() + "/folder/");
    sb.append(URLEncoder.encode(vmxPathTokens[2].trim(), "UTF-8"));
    sb.append("/");
    sb.append(URLEncoder.encode(vmxPathTokens[3].trim(), "UTF-8"));
    sb.append("?dcPath=");
    sb.append(URLEncoder.encode(dcInfo.second(), "UTF-8"));
    sb.append("&dsName=");
    sb.append(URLEncoder.encode(vmxPathTokens[1].trim(), "UTF-8"));
    return sb.toString();
}
Also used : VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)30 TraversalSpec (com.vmware.vim25.TraversalSpec)15 ArrayList (java.util.ArrayList)15 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)13 SelectionSpec (com.vmware.vim25.SelectionSpec)12 ObjectSpec (com.vmware.vim25.ObjectSpec)11 PropertySpec (com.vmware.vim25.PropertySpec)11 TaskInfo (com.vmware.vim25.TaskInfo)10 RemoteException (java.rmi.RemoteException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)8 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)8 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)6 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)6 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)6 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)6 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)6