Search in sources :

Example 11 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class DatastoreMO method moveDatastoreFile.

public boolean moveDatastoreFile(String srcFilePath, ManagedObjectReference morSrcDc, ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc, boolean forceOverwrite) throws Exception {
    String srcDsName = getName();
    DatastoreMO destDsMo = new DatastoreMO(_context, morDestDs);
    String destDsName = destDsMo.getName();
    ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
    String srcFullPath = srcFilePath;
    if (!DatastoreFile.isFullDatastorePath(srcFullPath))
        srcFullPath = String.format("[%s] %s", srcDsName, srcFilePath);
    String destFullPath = destFilePath;
    if (!DatastoreFile.isFullDatastorePath(destFullPath))
        destFullPath = String.format("[%s] %s", destDsName, destFilePath);
    ManagedObjectReference morTask = _context.getService().moveDatastoreFile_Task(morFileManager, srcFullPath, morSrcDc, destFullPath, morDestDc, forceOverwrite);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware moveDatgastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 12 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class DatastoreMO method deleteFile.

public boolean deleteFile(String path, ManagedObjectReference morDc, boolean testExistence) throws Exception {
    String datastoreName = getName();
    ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
    String fullPath = path;
    if (!DatastoreFile.isFullDatastorePath(fullPath))
        fullPath = String.format("[%s] %s", datastoreName, path);
    try {
        if (testExistence && !fileExists(fullPath))
            return true;
    } catch (Exception e) {
        s_logger.info("Unable to test file existence due to exception " + e.getClass().getName() + ", skip deleting of it");
        return true;
    }
    ManagedObjectReference morTask = _context.getService().deleteDatastoreFile_Task(morFileManager, fullPath, morDc);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class HostDatastoreBrowserMO method searchDatastore.

public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastore(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastore_Task(_mor, datastorePath, searchSpec);
        String result = _context.getServiceUtil().waitForTask(morTask);
        if (result.equals("sucess")) {
            _context.waitForTaskProgressDone(morTask);
            return (HostDatastoreBrowserSearchResults) _context.getServiceUtil().getDynamicProperty(morTask, "info.result");
        } else {
            s_logger.error("VMware searchDaastore_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
    } finally {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - searchDatastore() done");
    }
    return null;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class HostDatastoreSystemMO method findDatastoreByUrl.

// storeUrl in nfs://host/exportpath format
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
    assert (storeUrl != null);
    ManagedObjectReference[] datastores = getDatastores();
    if (datastores != null && datastores.length > 0) {
        for (ManagedObjectReference morDatastore : datastores) {
            NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
            if (info != null) {
                URI uri = new URI(storeUrl);
                String vmwareStyleUrl = "netfs://" + uri.getHost() + "/" + uri.getPath() + "/";
                if (info.getUrl().equals(vmwareStyleUrl))
                    return morDatastore;
            }
        }
    }
    return null;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 15 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class HostDatastoreSystemMO method findDatastore.

public ManagedObjectReference findDatastore(String name) throws Exception {
    // added cloud.com specific name convention, we will use custom field "cloud.uuid" as datastore name as well
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    ObjectContent[] ocs = getDatastorePropertiesOnHostDatastoreSystem(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet(0).getVal().equals(name))
                return oc.getObj();
            if (oc.getPropSet().length > 1) {
                DynamicProperty prop = oc.getPropSet(1);
                if (prop != null && prop.getVal() != null) {
                    if (prop.getVal() instanceof CustomFieldStringValue) {
                        String val = ((CustomFieldStringValue) prop.getVal()).getValue();
                        if (val.equalsIgnoreCase(name))
                            return oc.getObj();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)236 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 Pair (com.cloud.utils.Pair)49 RemoteException (java.rmi.RemoteException)48 ArrayList (java.util.ArrayList)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)39 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)35 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)32 IOException (java.io.IOException)31 CloudException (com.cloud.exception.CloudException)30 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)30 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)29 ObjectContent (com.vmware.vim25.ObjectContent)28 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)27 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)25 ConfigurationException (javax.naming.ConfigurationException)24 InternalErrorException (com.cloud.exception.InternalErrorException)23 VirtualDisk (com.vmware.vim25.VirtualDisk)23 ConnectException (java.net.ConnectException)23