Java 类com.vmware.vim25.HostDatastoreBrowserSearchSpec 实例源码

项目:photon-model    文件:EnumerationClient.java   
/**
 *  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;
}
项目:cloudstack    文件:HostDatastoreBrowserMO.java   
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;
}
项目:cloudstack    文件:HostDatastoreBrowserMO.java   
@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 - searchDatastore() done");
    }

    return null;
}
项目:cloudstack    文件:HostDatastoreBrowserMO.java   
public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, String fileName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.getMatchPattern().add(fileName);

    return searchDatastore(datastorePath, spec);
}
项目:cloudstack    文件:HostDatastoreBrowserMO.java   
public ArrayList<HostDatastoreBrowserSearchResults> searchDatastoreSubFolders(String datastorePath, String fileName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.getMatchPattern().add(fileName);

    return searchDatastoreSubFolders(datastorePath, spec);
}
项目:cloudstack    文件:DatastoreMO.java   
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.setModification(true);
    searchSpec.setDetails(fqf);
    searchSpec.setSearchCaseInsensitive(false);
    searchSpec.getMatchPattern().add(file.getFileName());
    s_logger.debug("Search file " + file.getFileName() + " on " + dirFile.getPath()); //ROOT-2.vmdk, [3ecf7a579d3b3793b86d9d019a97ae27] s-2-VM
    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=" + fi.getFileSize());
                return fi.getFileSize();
            }
        }
    }
    s_logger.debug("File " + fileFullPath + " does not exist on datastore");
    return size;
}
项目:cloudstack    文件:VmwareStorageManagerImpl.java   
private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, String exceptFileName)
        throws Exception {
    long size = 0;
    DatastoreMO dsMo = new DatastoreMO(context, morDs);
    HostDatastoreBrowserMO browserMo = dsMo.getHostDatastoreBrowserMO();
    String datastorePath = "[" + dsMo.getName() + "]";
    HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
    FileQueryFlags fqf = new FileQueryFlags();
    fqf.setFileSize(true);
    fqf.setFileOwner(true);
    fqf.setModification(true);
    searchSpec.setDetails(fqf);
    searchSpec.setSearchCaseInsensitive(false);
    searchSpec.getMatchPattern().add(fileName);
    ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders(datastorePath, searchSpec);
    for (HostDatastoreBrowserSearchResults result : results) {
        if (result != null) {
            List<FileInfo> info = result.getFile();
            for (FileInfo fi : info) {
                if (exceptFileName != null && fi.getPath().contains(exceptFileName)) {
                    continue;
                } else {
                    size = size + fi.getFileSize();
                }
            }
        }
    }
    return size;
}