use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class DatastoreMO method moveDatastoreFile.
public boolean moveDatastoreFile(String srcFilePath, ManagedObjectReference morSrcDc, ManagedObjectReference morDestDs, String destFilePath, ManagedObjectReference morDestDc, boolean forceOverwrite) throws Exception {
String srcDsName = getName();
DatastoreMO destDsMo = new DatastoreMO(_context, morDestDs);
String destDsName = destDsMo.getName();
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
String srcFullPath = srcFilePath;
if (!DatastoreFile.isFullDatastorePath(srcFullPath))
srcFullPath = String.format("[%s] %s", srcDsName, srcFilePath);
String destFullPath = destFilePath;
if (!DatastoreFile.isFullDatastorePath(destFullPath))
destFullPath = String.format("[%s] %s", destDsName, destFilePath);
ManagedObjectReference morTask = _context.getService().moveDatastoreFile_Task(morFileManager, srcFullPath, morSrcDc, destFullPath, morDestDc, forceOverwrite);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware moveDatgastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class DatastoreMO method deleteFile.
public boolean deleteFile(String path, ManagedObjectReference morDc, boolean testExistence) throws Exception {
String datastoreName = getName();
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
String fullPath = path;
if (!DatastoreFile.isFullDatastorePath(fullPath))
fullPath = String.format("[%s] %s", datastoreName, path);
try {
if (testExistence && !fileExists(fullPath))
return true;
} catch (Exception e) {
s_logger.info("Unable to test file existence due to exception " + e.getClass().getName() + ", skip deleting of it");
return true;
}
ManagedObjectReference morTask = _context.getService().deleteDatastoreFile_Task(morFileManager, fullPath, morDc);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference 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.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class HostDatastoreSystemMO method findDatastoreByUrl.
// storeUrl in nfs://host/exportpath format
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
assert (storeUrl != null);
ManagedObjectReference[] datastores = getDatastores();
if (datastores != null && datastores.length > 0) {
for (ManagedObjectReference morDatastore : datastores) {
NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
if (info != null) {
URI uri = new URI(storeUrl);
String vmwareStyleUrl = "netfs://" + uri.getHost() + "/" + uri.getPath() + "/";
if (info.getUrl().equals(vmwareStyleUrl))
return morDatastore;
}
}
}
return null;
}
use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.
the class HostDatastoreSystemMO method findDatastore.
public ManagedObjectReference findDatastore(String name) throws Exception {
// added cloud.com specific name convention, we will use custom field "cloud.uuid" as datastore name as well
CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
assert (key != 0);
ObjectContent[] ocs = getDatastorePropertiesOnHostDatastoreSystem(new String[] { "name", String.format("value[%d]", key) });
if (ocs != null) {
for (ObjectContent oc : ocs) {
if (oc.getPropSet(0).getVal().equals(name))
return oc.getObj();
if (oc.getPropSet().length > 1) {
DynamicProperty prop = oc.getPropSet(1);
if (prop != null && prop.getVal() != null) {
if (prop.getVal() instanceof CustomFieldStringValue) {
String val = ((CustomFieldStringValue) prop.getVal()).getValue();
if (val.equalsIgnoreCase(name))
return oc.getObj();
}
}
}
}
}
return null;
}
Aggregations