Search in sources :

Example 6 with HostDatastoreBrowserSearchSpec

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

the class DatastoreMO method fileDiskSize.

public long fileDiskSize(String fileFullPath) throws Exception {
    long size = 0;
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
    FileQueryFlags fqf = new FileQueryFlags();
    fqf.setFileSize(true);
    fqf.setFileOwner(true);
    fqf.setFileType(true);
    fqf.setModification(true);
    searchSpec.setDetails(fqf);
    searchSpec.setSearchCaseInsensitive(false);
    searchSpec.getMatchPattern().add(file.getFileName());
    // ROOT-2.vmdk, [3ecf7a579d3b3793b86d9d019a97ae27] s-2-VM
    s_logger.debug("Search file " + file.getFileName() + " on " + dirFile.getPath());
    HostDatastoreBrowserSearchResults result = browserMo.searchDatastore(dirFile.getPath(), searchSpec);
    if (result != null) {
        List<FileInfo> info = result.getFile();
        for (FileInfo fi : info) {
            if (file.getFileName().equals(fi.getPath())) {
                s_logger.debug("File found = " + fi.getPath() + ", size=" + toHumanReadableSize(fi.getFileSize()));
                return fi.getFileSize();
            }
        }
    }
    s_logger.debug("File " + fileFullPath + " does not exist on datastore");
    return size;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) FileQueryFlags(com.vmware.vim25.FileQueryFlags)

Example 7 with HostDatastoreBrowserSearchSpec

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

the class HostDatastoreBrowserMO method searchDatastoreSubFolders.

@SuppressWarnings("unchecked")
public ArrayList<HostDatastoreBrowserSearchResults> searchDatastoreSubFolders(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.getValue() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastoreSubFoldersTask(_mor, datastorePath, searchSpec);
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (result) {
            _context.waitForTaskProgressDone(morTask);
            return (ArrayList<HostDatastoreBrowserSearchResults>) _context.getVimClient().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 - searchDatastoreSubFolders() done");
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 8 with HostDatastoreBrowserSearchSpec

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

Example 9 with HostDatastoreBrowserSearchSpec

use of com.vmware.vim25.HostDatastoreBrowserSearchSpec in project photon-model by vmware.

the class EnumerationClient method createHostDatastoreBrowserSearchSpecForDisk.

/**
 * Create search specification that searches for exact disk name.
 */
private HostDatastoreBrowserSearchSpec createHostDatastoreBrowserSearchSpecForDisk(String diskName) {
    VmDiskFileQueryFilter vdiskFilter = new VmDiskFileQueryFilter();
    VmDiskFileQuery fQuery = new VmDiskFileQuery();
    fQuery.setFilter(vdiskFilter);
    HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
    searchSpec.getQuery().add(fQuery);
    FileQueryFlags flag = new FileQueryFlags();
    flag.setFileOwner(true);
    flag.setFileSize(true);
    flag.setFileType(true);
    flag.setModification(true);
    searchSpec.setDetails(flag);
    searchSpec.getMatchPattern().add(diskName + ".vmdk");
    return searchSpec;
}
Also used : HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) FileQueryFlags(com.vmware.vim25.FileQueryFlags) VmDiskFileQuery(com.vmware.vim25.VmDiskFileQuery) VmDiskFileQueryFilter(com.vmware.vim25.VmDiskFileQueryFilter)

Example 10 with HostDatastoreBrowserSearchSpec

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

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.getValue() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastoreTask(_mor, datastorePath, searchSpec);
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (result) {
            _context.waitForTaskProgressDone(morTask);
            return (HostDatastoreBrowserSearchResults) _context.getVimClient().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)

Aggregations

HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)8 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 FileQueryFlags (com.vmware.vim25.FileQueryFlags)3 FileInfo (com.vmware.vim25.FileInfo)2 ArrayList (java.util.ArrayList)2 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostDatastoreBrowserMO (com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 ArrayOfHostDatastoreBrowserSearchResults (com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults)1 FileFaultFaultMsg (com.vmware.vim25.FileFaultFaultMsg)1 InvalidCollectorVersionFaultMsg (com.vmware.vim25.InvalidCollectorVersionFaultMsg)1 InvalidDatastoreFaultMsg (com.vmware.vim25.InvalidDatastoreFaultMsg)1 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)1 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)1 TaskInfo (com.vmware.vim25.TaskInfo)1 VmDiskFileQuery (com.vmware.vim25.VmDiskFileQuery)1 VmDiskFileQueryFilter (com.vmware.vim25.VmDiskFileQueryFilter)1