Search in sources :

Example 41 with Datastore

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

the class HostDatastoreSystemMO method findDatastoreByExportPath.

// TODO this is a hacking helper method, when we can pass down storage pool info along with volume
// we should be able to find the datastore by name
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    assert (exportPath != null);
    ManagedObjectReference[] datastores = getDatastores();
    if (datastores != null && datastores.length > 0) {
        for (ManagedObjectReference morDatastore : datastores) {
            DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
            if (dsMo.getInventoryPath().equals(exportPath))
                return morDatastore;
            NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
            if (info != null) {
                String vmwareUrl = info.getUrl();
                if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
                    vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
                URI uri = new URI(vmwareUrl);
                if (uri.getPath().equals("/" + exportPath))
                    return morDatastore;
            }
        }
    }
    return null;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 42 with Datastore

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

the class HostDatastoreSystemMO method getDatastorePropertiesOnHostDatastoreSystem.

public ObjectContent[] getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(propertyPaths);
    TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
    hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
    hostDsSys2DatastoreTraversal.setPath("datastore");
    hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { hostDsSys2DatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    return _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Example 43 with Datastore

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

the class ClusterMO method findDatastore.

@Override
public ManagedObjectReference findDatastore(String poolUuid) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.get_value() + ", poolUuid: " + poolUuid);
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet(0).getVal().equals(poolUuid))
                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(poolUuid)) {
                            if (s_logger.isTraceEnabled())
                                s_logger.trace("vCenter API trace - findDatastore() done(successfully)");
                            return oc.getObj();
                        }
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 44 with Datastore

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

the class DatastoreMO method getOwnerDatacenter.

public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
    if (_ownerDc != null)
        return _ownerDc;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.setPathSet(new String[] { "name" });
    TraversalSpec folderParentTraversal = new TraversalSpec();
    folderParentTraversal.setType("Folder");
    folderParentTraversal.setPath("parent");
    folderParentTraversal.setName("folderParentTraversal");
    folderParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "folderParentTraversal") });
    TraversalSpec dsParentTraversal = new TraversalSpec();
    dsParentTraversal.setType("Datastore");
    dsParentTraversal.setPath("parent");
    dsParentTraversal.setName("dsParentTraversal");
    dsParentTraversal.setSelectSet(new SelectionSpec[] { folderParentTraversal });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { dsParentTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    assert (ocs != null);
    assert (ocs[0].getObj() != null);
    assert (ocs[0].getPropSet() != null);
    String dcName = ocs[0].getPropSet()[0].getVal().toString();
    _ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs[0].getObj()), dcName);
    return _ownerDc;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec)

Example 45 with Datastore

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

the class HostDatastoreBrowserMO method searchDatastoreSubFolders.

public HostDatastoreBrowserSearchResults searchDatastoreSubFolders(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastoreSubFolders_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 searchDaastoreSubFolders_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)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)39 RemoteException (java.rmi.RemoteException)15 ArrayList (java.util.ArrayList)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 VirtualDisk (com.vmware.vim25.VirtualDisk)14 TraversalSpec (com.vmware.vim25.TraversalSpec)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)12 ObjectContent (com.vmware.vim25.ObjectContent)12 ObjectSpec (com.vmware.vim25.ObjectSpec)12 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)12 PropertySpec (com.vmware.vim25.PropertySpec)12 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)11 Pair (com.cloud.utils.Pair)10 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)10 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)10 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)10 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)8