use of com.vmware.vim25.mo.Datastore 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.mo.Datastore 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.mo.Datastore 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;
}
use of com.vmware.vim25.mo.Datastore in project CloudStack-archive by CloudStack-extras.
the class HostMO method mountDatastore.
@Override
public ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress, int poolHostPort, String poolPath, String poolUuid) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore(). target MOR: " + _mor.get_value() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
HostDatastoreSystemMO hostDatastoreSystemMo = getHostDatastoreSystemMO();
ManagedObjectReference morDatastore = hostDatastoreSystemMo.findDatastore(poolUuid);
if (morDatastore == null) {
if (!vmfsDatastore) {
morDatastore = hostDatastoreSystemMo.createNfsDatastore(poolHostAddress, poolHostPort, poolPath, poolUuid);
if (morDatastore == null) {
String msg = "Unable to create NFS datastore. host: " + poolHostAddress + ", port: " + poolHostPort + ", path: " + poolPath + ", uuid: " + poolUuid;
s_logger.error(msg);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
throw new Exception(msg);
}
} else {
morDatastore = _context.getDatastoreMorByPath(poolPath);
if (morDatastore == null) {
String msg = "Unable to create VMFS datastore. host: " + poolHostAddress + ", port: " + poolHostPort + ", path: " + poolPath + ", uuid: " + poolUuid;
s_logger.error(msg);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
throw new Exception(msg);
}
DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
dsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, poolUuid);
}
}
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore() done(successfully)");
return morDatastore;
}
use of com.vmware.vim25.mo.Datastore in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method attachIso.
// isoDatastorePath: [datastore name] isoFilePath
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " + morDs.get_value() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
assert (isoDatastorePath != null);
assert (morDs != null);
boolean newCdRom = false;
VirtualCdrom cdRom = (VirtualCdrom) getIsoDevice();
if (cdRom == null) {
newCdRom = true;
cdRom = new VirtualCdrom();
cdRom.setControllerKey(getIDEDeviceControllerKey());
int deviceNumber = getNextIDEDeviceNumber();
cdRom.setUnitNumber(deviceNumber);
cdRom.setKey(-deviceNumber);
}
VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
cInfo.setConnected(connect);
cInfo.setStartConnected(connectAtBoot);
cdRom.setConnectable(cInfo);
VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
backingInfo.setFileName(isoDatastorePath);
backingInfo.setDatastore(morDs);
cdRom.setBacking(backingInfo);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(cdRom);
if (newCdRom) {
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
} else {
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
}
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (!result.equals("sucess")) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(failed)");
throw new Exception("Failed to attach ISO due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Aggregations