Search in sources :

Example 31 with VirtualDevice

use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.

the class VirtualMachineMO method getNicDevices.

private List<VirtualDevice> getNicDevices(boolean sorted) throws Exception {
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    List<VirtualDevice> nics = new ArrayList<VirtualDevice>();
    if (devices != null) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualEthernetCard) {
                nics.add(device);
            }
        }
    }
    if (sorted) {
        Collections.sort(nics, new Comparator<VirtualDevice>() {

            @Override
            public int compare(VirtualDevice arg0, VirtualDevice arg1) {
                int unitNumber0 = arg0.getUnitNumber() != null ? arg0.getUnitNumber().intValue() : -1;
                int unitNumber1 = arg1.getUnitNumber() != null ? arg1.getUnitNumber().intValue() : -1;
                if (unitNumber0 < unitNumber1)
                    return -1;
                else if (unitNumber0 > unitNumber1)
                    return 1;
                return 0;
            }
        });
    }
    return nics;
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard)

Example 32 with VirtualDevice

use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.

the class VirtualMachineMO method getDiskDeviceByBusName.

public VirtualDisk getDiskDeviceByBusName(List<VirtualDevice> allDevices, String busName) throws Exception {
    for (VirtualDevice device : allDevices) {
        if (device instanceof VirtualDisk) {
            VirtualDisk disk = (VirtualDisk) device;
            String diskBusName = getDeviceBusName(allDevices, disk);
            if (busName.equalsIgnoreCase(diskBusName))
                return disk;
        }
    }
    return null;
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 33 with VirtualDevice

use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.

the class VirtualMachineMO method getMatchedDevices.

public VirtualDevice[] getMatchedDevices(Class<?>[] deviceClasses) throws Exception {
    assert (deviceClasses != null);
    List<VirtualDevice> returnList = new ArrayList<VirtualDevice>();
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    if (devices != null) {
        for (VirtualDevice device : devices) {
            for (Class<?> clz : deviceClasses) {
                if (clz.isInstance(device)) {
                    returnList.add(device);
                    break;
                }
            }
        }
    }
    return returnList.toArray(new VirtualDevice[0]);
}
Also used : ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice)

Example 34 with VirtualDevice

use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method tearDownDevices.

public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
    VirtualDevice[] devices = getMatchedDevices(deviceClasses);
    if (devices.length > 0) {
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
        for (int i = 0; i < devices.length; i++) {
            deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
            deviceConfigSpecArray[i].setDevice(devices[i]);
            deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
        }
        vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
        if (!configureVm(vmConfigSpec)) {
            throw new Exception("Failed to detach devices");
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice)

Example 35 with VirtualDevice

use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method detachIso.

public void detachIso(String isoDatastorePath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: " + isoDatastorePath);
    VirtualDevice device = getIsoDevice();
    if (device == null) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Unable to find a CDROM device");
    }
    VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
    backingInfo.setDeviceName("");
    device.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    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 detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualDevice (com.vmware.vim25.VirtualDevice)49 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)23 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)23 VirtualDisk (com.vmware.vim25.VirtualDisk)22 ArrayList (java.util.ArrayList)20 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)19 Pair (com.cloud.utils.Pair)15 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)15 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)15 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)15 VirtualEthernetCard (com.vmware.vim25.VirtualEthernetCard)11 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)8 IOException (java.io.IOException)8 CloudException (com.cloud.exception.CloudException)6 InternalErrorException (com.cloud.exception.InternalErrorException)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 ConnectException (java.net.ConnectException)6 RemoteException (java.rmi.RemoteException)6 ConfigurationException (javax.naming.ConfigurationException)6