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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations