Search in sources :

Example 1 with FileQueryFlags

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

the class VmwareStorageManagerImpl method getVMSnapshotChainSize.

private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, String exceptFileName, String vmName) throws Exception {
    long size = 0;
    DatastoreMO dsMo = new DatastoreMO(context, morDs);
    HostDatastoreBrowserMO browserMo = dsMo.getHostDatastoreBrowserMO();
    String datastorePath = (new DatastoreFile(dsMo.getName(), vmName)).getPath();
    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;
}
Also used : HostDatastoreBrowserMO(com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO) HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) FileQueryFlags(com.vmware.vim25.FileQueryFlags) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO)

Example 2 with FileQueryFlags

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

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

Aggregations

FileQueryFlags (com.vmware.vim25.FileQueryFlags)3 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)3 FileInfo (com.vmware.vim25.FileInfo)2 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)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 VmDiskFileQuery (com.vmware.vim25.VmDiskFileQuery)1 VmDiskFileQueryFilter (com.vmware.vim25.VmDiskFileQueryFilter)1