Search in sources :

Example 6 with NasDatastoreInfo

use of com.vmware.vim25.NasDatastoreInfo 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)

Aggregations

NasDatastoreInfo (com.vmware.vim25.NasDatastoreInfo)6 URI (java.net.URI)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 DatastoreInfo (com.vmware.vim25.DatastoreInfo)2 ObjectContent (com.vmware.vim25.ObjectContent)2