Search in sources :

Example 66 with VirtualDevice

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

the class VmwareHelper method prepareDvNicDevice.

public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
    VirtualEthernetCard nic;
    switch(deviceType) {
        case E1000:
            nic = new VirtualE1000();
            break;
        case PCNet32:
            nic = new VirtualPCNet32();
            break;
        case Vmxnet2:
            nic = new VirtualVmxnet2();
            break;
        case Vmxnet3:
            nic = new VirtualVmxnet3();
            break;
        default:
            assert (false);
            nic = new VirtualE1000();
    }
    final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
    final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
    final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    dvPortConnection.setSwitchUuid(dvSwitchUuid);
    dvPortConnection.setPortgroupKey(morNetwork.getValue());
    dvPortBacking.setPort(dvPortConnection);
    nic.setBacking(dvPortBacking);
    nic.setKey(30);
    connectInfo.setAllowGuestControl(true);
    connectInfo.setConnected(conntected);
    connectInfo.setStartConnected(connectOnStart);
    nic.setAddressType("Manual");
    nic.setConnectable(connectInfo);
    nic.setMacAddress(macAddress);
    nic.setUnitNumber(deviceNumber);
    nic.setKey(-contextNumber);
    return nic;
}
Also used : VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) VirtualPCNet32(com.vmware.vim25.VirtualPCNet32) VirtualVmxnet2(com.vmware.vim25.VirtualVmxnet2) VirtualVmxnet3(com.vmware.vim25.VirtualVmxnet3) DistributedVirtualSwitchPortConnection(com.vmware.vim25.DistributedVirtualSwitchPortConnection) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualE1000(com.vmware.vim25.VirtualE1000)

Example 67 with VirtualDevice

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

the class VirtualMachineMO method getVirtualDisks.

public List<VirtualDisk> getVirtualDisks() throws Exception {
    List<VirtualDisk> virtualDisks = new ArrayList<VirtualDisk>();
    List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
    for (VirtualDevice device : devices) {
        if (device instanceof VirtualDisk) {
            virtualDisks.add((VirtualDisk) device);
        }
    }
    return virtualDisks;
}
Also used : ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk)

Example 68 with VirtualDevice

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

the class VirtualMachineMO method getNicDeviceIndex.

public Pair<Integer, VirtualDevice> getNicDeviceIndex(String networkNamePrefix) throws Exception {
    List<VirtualDevice> nics = getNicDevices(true);
    int index = 0;
    String attachedNetworkSummary;
    String dvPortGroupName;
    for (VirtualDevice nic : nics) {
        attachedNetworkSummary = ((VirtualEthernetCard) nic).getDeviceInfo().getSummary();
        if (attachedNetworkSummary.startsWith(networkNamePrefix)) {
            return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
        } else if (attachedNetworkSummary.endsWith("DistributedVirtualPortBackingInfo.summary") || attachedNetworkSummary.startsWith("DVSwitch")) {
            dvPortGroupName = getDvPortGroupName((VirtualEthernetCard) nic);
            if (dvPortGroupName != null && dvPortGroupName.startsWith(networkNamePrefix)) {
                s_logger.debug("Found a dvPortGroup already associated with public NIC.");
                return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
            }
        }
        index++;
    }
    return new Pair<Integer, VirtualDevice>(new Integer(-1), null);
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Pair(com.cloud.utils.Pair)

Example 69 with VirtualDevice

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

the class VirtualMachineMO method attachDisk.

public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain));
    synchronized (_mor.getValue().intern()) {
        VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey, vmdkDatastorePathChain, -1, 1);
        VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        deviceConfigSpec.setDevice(newDisk);
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
        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 - attachDisk() done(failed)");
            throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
        _context.waitForTaskProgressDone(morTask);
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) Gson(com.google.gson.Gson) 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