Search in sources :

Example 86 with ManagedObjectReference

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;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 87 with ManagedObjectReference

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;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 88 with ManagedObjectReference

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;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 89 with ManagedObjectReference

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;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 90 with ManagedObjectReference

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);
    }
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)236 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 Pair (com.cloud.utils.Pair)49 RemoteException (java.rmi.RemoteException)48 ArrayList (java.util.ArrayList)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)39 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)35 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)32 IOException (java.io.IOException)31 CloudException (com.cloud.exception.CloudException)30 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)30 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)29 ObjectContent (com.vmware.vim25.ObjectContent)28 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)27 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)25 ConfigurationException (javax.naming.ConfigurationException)24 InternalErrorException (com.cloud.exception.InternalErrorException)23 VirtualDisk (com.vmware.vim25.VirtualDisk)23 ConnectException (java.net.ConnectException)23