use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class ClusterMO 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.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
ManagedObjectReference morDs = null;
ManagedObjectReference morDsFirst = null;
List<ManagedObjectReference> hosts = _context.getVimClient().getDynamicProperty(_mor, "host");
if (hosts != null && hosts.size() > 0) {
for (ManagedObjectReference morHost : hosts) {
HostMO hostMo = new HostMO(_context, morHost);
morDs = hostMo.mountDatastore(vmfsDatastore, poolHostAddress, poolHostPort, poolPath, poolUuid);
if (morDsFirst == null)
morDsFirst = morDs;
// assume datastore is in scope of datacenter
assert (morDsFirst.getValue().equals(morDs.getValue()));
}
}
if (morDs == null) {
String msg = "Failed to mount datastore in all hosts within the cluster";
s_logger.error(msg);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
throw new Exception(msg);
}
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - mountDatastore() done(successfully)");
return morDs;
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
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 - attachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " + morDs.getValue() + ", 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.getDeviceChange().add(deviceConfigSpec);
ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (!result) {
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)");
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class VmwareStorageProcessor method prepareManagedDatastore.
private ManagedObjectReference prepareManagedDatastore(VmwareContext context, VmwareHypervisorHost hyperHost, String diskUuid, String iScsiName, String storageHost, int storagePort, String chapInitiatorUsername, String chapInitiatorSecret, String chapTargetUsername, String chapTargetSecret) throws Exception {
if (storagePort == DEFAULT_NFS_PORT) {
s_logger.info("creating the NFS datastore with the following configuration - storageHost: " + storageHost + ", storagePort: " + storagePort + ", exportpath: " + iScsiName + "and diskUuid : " + diskUuid);
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
ClusterMO cluster = new ClusterMO(context, morCluster);
List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
HostMO host = new HostMO(context, lstHosts.get(0).first());
HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
return hostDatastoreSystem.createNfsDatastore(storageHost, storagePort, iScsiName, diskUuid);
} else {
return getVmfsDatastore(context, hyperHost, VmwareResource.getDatastoreName(iScsiName), storageHost, storagePort, trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);
}
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class VirtualMachineMO method changeDatastore.
public boolean changeDatastore(VirtualMachineRelocateSpec relocateSpec) throws Exception {
ManagedObjectReference morTask = _context.getVimClient().getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware RelocateVM_Task to change datastore failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class VirtualMachineMO method getOwnerDatastore.
public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.getPathSet().add("name");
TraversalSpec vmDatastoreTraversal = new TraversalSpec();
vmDatastoreTraversal.setType("VirtualMachine");
vmDatastoreTraversal.setPath("datastore");
vmDatastoreTraversal.setName("vmDatastoreTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(vmDatastoreTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (ocs != null) {
for (ObjectContent oc : ocs) {
DynamicProperty prop = oc.getPropSet().get(0);
if (prop.getVal().toString().equals(dsName)) {
return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
}
}
}
return null;
}
Aggregations