Search in sources :

Example 1 with HostDatastoreBrowserSearchSpec

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

the class HostDatastoreBrowserMO method searchDatastore.

public HostDatastoreBrowserSearchResults searchDatastore(String datastorePath, String fileName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.setMatchPattern(new String[] { fileName });
    return searchDatastore(datastorePath, spec);
}
Also used : HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec)

Example 2 with HostDatastoreBrowserSearchSpec

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

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.get_value() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastore_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 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)

Example 3 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, String folderName, boolean caseInsensitive) throws Exception {
    HostDatastoreBrowserSearchSpec spec = new HostDatastoreBrowserSearchSpec();
    spec.setSearchCaseInsensitive(caseInsensitive);
    spec.setMatchPattern(new String[] { folderName });
    return searchDatastore(datastorePath, spec);
}
Also used : HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec)

Example 4 with HostDatastoreBrowserSearchSpec

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

the class EnumerationClient method queryDisksAvailabilityinVSphere.

/**
 * Utility method that crosschecks the availability of independent disks in vSphere.
 */
public List<String> queryDisksAvailabilityinVSphere(Map<String, Object> diskInfoInLocalIndex) {
    final List<String> unAvailableDisks = new ArrayList<>();
    diskInfoInLocalIndex.entrySet().stream().forEach(entry -> {
        DiskService.DiskState diskState = Utils.fromJson(entry.getValue(), DiskService.DiskState.class);
        String diskDirectoryPath = diskState.customProperties.get(CustomProperties.DISK_PARENT_DIRECTORY);
        String datastoreName = diskState.customProperties.get(CustomProperties.DISK_DATASTORE_NAME);
        HostDatastoreBrowserSearchSpec searchSpec = createHostDatastoreBrowserSearchSpecForDisk(diskState.id);
        try {
            this.getMoRef.entityProps(this.finder.datastore(datastoreName).object, "browser").entrySet().stream().forEach(item -> {
                try {
                    ManagedObjectReference hostBrowser = (ManagedObjectReference) item.getValue();
                    ManagedObjectReference task = connection.getVimPort().searchDatastoreSubFoldersTask(hostBrowser, diskDirectoryPath, searchSpec);
                    TaskInfo info = VimUtils.waitTaskEnd(connection, task);
                    ArrayOfHostDatastoreBrowserSearchResults searchResult = (ArrayOfHostDatastoreBrowserSearchResults) info.getResult();
                    if (searchResult == null) {
                        // Folder is deleted.
                        unAvailableDisks.add(entry.getKey());
                    } else {
                        searchResult.getHostDatastoreBrowserSearchResults().stream().forEach(result -> {
                            // Folder is present but the vmdk file is deleted.
                            if (CollectionUtils.isEmpty(result.getFile())) {
                                unAvailableDisks.add(entry.getKey());
                            }
                        });
                    }
                } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | InvalidCollectorVersionFaultMsg | FileFaultFaultMsg | InvalidDatastoreFaultMsg ex) {
                    logger.info("Unable to get the availability status for " + entry.getKey());
                }
            });
        } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | FinderException ex) {
            logger.info("Unable to find the datastore : " + datastoreName);
        }
    });
    return unAvailableDisks;
}
Also used : InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) ArrayList(java.util.ArrayList) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskInfo(com.vmware.vim25.TaskInfo) InvalidDatastoreFaultMsg(com.vmware.vim25.InvalidDatastoreFaultMsg) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) ArrayOfHostDatastoreBrowserSearchResults(com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with HostDatastoreBrowserSearchSpec

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

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