use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project CloudStack-archive by CloudStack-extras.
the class DatastoreMO method fileExists.
public boolean fileExists(String fileFullPath) throws Exception {
DatastoreFile file = new DatastoreFile(fileFullPath);
DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
if (results != null) {
FileInfo[] info = results.getFile();
if (info != null && info.length > 0) {
s_logger.info("File " + fileFullPath + " exists on datastore");
return true;
}
}
s_logger.info("File " + fileFullPath + " does not exist on datastore");
return false;
/*
String[] fileNames = listDirContent(dirFile.getPath());
String fileName = file.getFileName();
for(String name : fileNames) {
if(name.equalsIgnoreCase(fileName))
return true;
}
return false;
*/
}
use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project CloudStack-archive by CloudStack-extras.
the class DatastoreMO method folderExists.
public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
if (results != null) {
FileInfo[] info = results.getFile();
if (info != null && info.length > 0) {
s_logger.info("Folder " + folderName + " exists on datastore");
return true;
}
}
s_logger.info("Folder " + folderName + " does not exist on datastore");
return false;
}
use of com.vmware.vim25.HostDatastoreBrowserSearchResults 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.HostDatastoreBrowserSearchResults 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.HostDatastoreBrowserSearchResults 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);
}
Aggregations