use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project cloudstack by apache.
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) {
List<FileInfo> info = results.getFile();
if (info != null && info.size() > 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 by apache.
the class DatastoreMO method searchFileInSubFolders.
public String searchFileInSubFolders(String fileName, boolean caseInsensitive, String excludeFolders) throws Exception {
String datastorePath = "[" + getName() + "]";
String rootDirectoryFilePath = String.format("%s %s", datastorePath, fileName);
String[] searchExcludedFolders = getSearchExcludedFolders(excludeFolders);
if (fileExists(rootDirectoryFilePath)) {
return rootDirectoryFilePath;
}
String parentFolderPath;
String absoluteFileName = null;
s_logger.info("Searching file " + fileName + " in " + datastorePath);
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders("[" + getName() + "]", fileName, caseInsensitive);
if (results != null && results.size() > 1) {
s_logger.warn("Multiple files with name " + fileName + " exists in datastore " + datastorePath + ". Trying to choose first file found in search attempt.");
} else if (results == null) {
String msg = "No file found with name " + fileName + " found in datastore " + datastorePath;
s_logger.error(msg);
throw new CloudException(msg);
}
for (HostDatastoreBrowserSearchResults result : results) {
List<FileInfo> info = result.getFile();
if (info != null && info.size() > 0) {
for (FileInfo fi : info) {
absoluteFileName = parentFolderPath = result.getFolderPath();
s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName);
if (parentFolderPath.endsWith("]"))
absoluteFileName += " ";
else if (!parentFolderPath.endsWith("/"))
absoluteFileName += "/";
absoluteFileName += fi.getPath();
if (isValidCloudStackFolderPath(parentFolderPath, searchExcludedFolders)) {
return absoluteFileName;
}
break;
}
}
}
return absoluteFileName;
}
use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project cloudstack by apache.
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.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;
}
use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project cloudstack by apache.
the class HostDatastoreBrowserMO method searchDatastore.
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);
}
use of com.vmware.vim25.HostDatastoreBrowserSearchResults in project cloudstack by apache.
the class HostDatastoreBrowserMO method searchDatastoreSubFolders.
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);
}
Aggregations