Search in sources :

Example 1 with NasDatastoreInfo

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

the class ClusterMO method findDatastoreByExportPath.

@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.get_value() + ", exportPath: " + exportPath);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet(0).getVal();
            if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
                NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
                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)) {
                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
                        return oc.getObj();
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI)

Example 2 with NasDatastoreInfo

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

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

use of com.vmware.vim25.NasDatastoreInfo in project cloudstack by apache.

the class HostDatastoreSystemMO method findDatastoreByUrl.

// storeUrl in nfs://host/exportpath format
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
    assert (storeUrl != null);
    List<ManagedObjectReference> datastores = getDatastores();
    if (datastores != null && datastores.size() > 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 5 with NasDatastoreInfo

use of com.vmware.vim25.NasDatastoreInfo in project cloudstack by apache.

the class ClusterMO method findDatastoreByExportPath.

@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet().get(0).getVal();
            if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
                NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
                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)) {
                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
                        return oc.getObj();
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI)

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