Search in sources :

Example 26 with Datastore

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

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);
    List<ManagedObjectReference> datastores = getDatastores();
    if (datastores != null && datastores.size() > 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 27 with Datastore

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

the class HostDatastoreSystemMO method createVmfsDatastore.

public ManagedObjectReference createVmfsDatastore(String datastoreName, HostScsiDisk hostScsiDisk) throws Exception {
    // just grab the first instance of VmfsDatastoreOption
    VmfsDatastoreOption vmfsDatastoreOption = _context.getService().queryVmfsDatastoreCreateOptions(_mor, hostScsiDisk.getDevicePath(), 5).get(0);
    VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption.getSpec();
    // set the name of the datastore to be created
    vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
    return _context.getService().createVmfsDatastore(_mor, vmfsDatastoreCreateSpec);
}
Also used : VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec)

Example 28 with Datastore

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

the class HostDatastoreSystemMO method getDatastorePropertiesOnHostDatastoreSystem.

public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(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.getSelectSet().add(hostDsSys2DatastoreTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 29 with Datastore

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

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.getPathSet().add("name");
    TraversalSpec folderParentTraversal = new TraversalSpec();
    folderParentTraversal.setType("Folder");
    folderParentTraversal.setPath("parent");
    folderParentTraversal.setName("folderParentTraversal");
    SelectionSpec sSpec = new SelectionSpec();
    sSpec.setName("folderParentTraversal");
    folderParentTraversal.getSelectSet().add(sSpec);
    TraversalSpec dsParentTraversal = new TraversalSpec();
    dsParentTraversal.setType("Datastore");
    dsParentTraversal.setPath("parent");
    dsParentTraversal.setName("dsParentTraversal");
    dsParentTraversal.getSelectSet().add(folderParentTraversal);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dsParentTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    assert (ocs != null && ocs.size() > 0);
    assert (ocs.get(0).getObj() != null);
    assert (ocs.get(0).getPropSet() != null);
    String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
    _ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs.get(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) ArrayList(java.util.ArrayList)

Example 30 with Datastore

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

the class DatastoreMO method fileExists.

public boolean fileExists(String fileFullPath) throws Exception {
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
    if (results != null) {
        List<FileInfo> info = results.getFile();
        if (info != null && info.size() > 0) {
            s_logger.info("File " + fileFullPath + " exists on datastore");
            return true;
        }
    }
    s_logger.info("File " + fileFullPath + " does not exist on datastore");
    return false;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

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