use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class VmwareClient method getDecendentMoRef.
/**
* Get the ManagedObjectReference for an item under the
* specified root folder that has the type and name specified.
*
* @param root a root folder if available, or null for default
* @param type type of the managed object
* @param name name to match
*
* @return First ManagedObjectReference of the type / name pair found
*/
public ManagedObjectReference getDecendentMoRef(ManagedObjectReference root, String type, String name) throws Exception {
if (name == null || name.length() == 0) {
return null;
}
try {
// Create PropertySpecs
PropertySpec pSpec = new PropertySpec();
pSpec.setType(type);
pSpec.setAll(false);
pSpec.getPathSet().add("name");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(root);
oSpec.setSkip(false);
oSpec.getSelectSet().addAll(constructCompleteTraversalSpec());
PropertyFilterSpec spec = new PropertyFilterSpec();
spec.getPropSet().add(pSpec);
spec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
specArr.add(spec);
ManagedObjectReference propCollector = getPropCol();
List<ObjectContent> ocary = vimPort.retrieveProperties(propCollector, specArr);
if (ocary == null || ocary.size() == 0) {
return null;
}
// filter through retrieved objects to get the first match.
for (ObjectContent oc : ocary) {
ManagedObjectReference mor = oc.getObj();
List<DynamicProperty> propary = oc.getPropSet();
if (type == null || type.equals(mor.getType())) {
if (propary.size() > 0) {
String propval = (String) propary.get(0).getVal();
if (propval != null && name.equalsIgnoreCase(propval))
return mor;
}
}
}
} catch (InvalidPropertyFaultMsg invalidPropertyException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + invalidPropertyException.getMessage());
throw invalidPropertyException;
} catch (RuntimeFaultFaultMsg runtimeFaultException) {
s_logger.debug("Failed to get Vmware ManagedObjectReference for name: " + name + " and type: " + type + " due to " + runtimeFaultException.getMessage());
throw runtimeFaultException;
}
return null;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class VmwareClient method getMoRefProp.
/**
* Get a MORef from the property returned.
*
* @param objMor Object to get a reference property from
* @param propName name of the property that is the MORef
* @return the ManagedObjectReference for that property.
*/
public ManagedObjectReference getMoRefProp(ManagedObjectReference objMor, String propName) throws Exception {
Object props = getDynamicProperty(objMor, propName);
ManagedObjectReference propmor = null;
if (!props.getClass().isArray()) {
propmor = (ManagedObjectReference) props;
}
return propmor;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class VmwareHelper method prepareDiskDevice.
// vmdkDatastorePath: [datastore name] vmdkFilePath
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, VirtualDisk device, int controllerKey, String[] vmdkDatastorePathChain, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
assert (vmdkDatastorePathChain != null);
assert (vmdkDatastorePathChain.length >= 1);
VirtualDisk disk;
VirtualDiskFlatVer2BackingInfo backingInfo;
if (device != null) {
disk = device;
backingInfo = (VirtualDiskFlatVer2BackingInfo) disk.getBacking();
} else {
disk = new VirtualDisk();
backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDatastore(morDs);
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
disk.setBacking(backingInfo);
int ideControllerKey = vmMo.getIDEDeviceControllerKey();
if (controllerKey < 0)
controllerKey = ideControllerKey;
if (deviceNumber < 0) {
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
}
disk.setControllerKey(controllerKey);
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
connectInfo.setConnected(true);
connectInfo.setStartConnected(true);
disk.setConnectable(connectInfo);
}
backingInfo.setFileName(vmdkDatastorePathChain[0]);
if (vmdkDatastorePathChain.length > 1) {
String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
for (int i = 0; i < vmdkDatastorePathChain.length - 1; i++) parentDisks[i] = vmdkDatastorePathChain[i + 1];
setParentBackingInfo(backingInfo, morDs, parentDisks);
}
return disk;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class VmwareHelper method prepareDiskDevice.
// vmdkDatastorePath: [datastore name] vmdkFilePath
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
VirtualDisk disk = new VirtualDisk();
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
backingInfo.setThinProvisioned(true);
backingInfo.setEagerlyScrub(false);
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
disk.setBacking(backingInfo);
int ideControllerKey = vmMo.getIDEDeviceControllerKey();
if (controllerKey < 0)
controllerKey = ideControllerKey;
if (deviceNumber < 0) {
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
}
disk.setControllerKey(controllerKey);
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
disk.setCapacityInKB(sizeInMb * 1024);
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
connectInfo.setConnected(true);
connectInfo.setStartConnected(true);
disk.setConnectable(connectInfo);
return disk;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class VmwareContext method waitForTaskProgressDone.
public void waitForTaskProgressDone(ManagedObjectReference morTask) throws Exception {
while (true) {
TaskInfo tinfo = (TaskInfo) _vimClient.getDynamicProperty(morTask, "info");
Integer progress = tinfo.getProgress();
if (progress == null)
break;
if (progress.intValue() >= 100)
break;
Thread.sleep(1000);
}
}
Aggregations