Search in sources :

Example 6 with VirtualEthernetCard

use of com.vmware.vim25.VirtualEthernetCard 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 7 with VirtualEthernetCard

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

the class VirtualMachineMO method getNicDeviceIndex.

public Pair<Integer, VirtualDevice> getNicDeviceIndex(String networkNamePrefix) throws Exception {
    VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().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);
            }
        }
    }
    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;
        }
    });
    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")) {
            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) ArrayList(java.util.ArrayList) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Pair(com.cloud.utils.Pair)

Example 8 with VirtualEthernetCard

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

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.get_value());
    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 9 with VirtualEthernetCard

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

the class VmwareHelper method prepareNicDevice.

public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String portGroupName, 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();
    }
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(portGroupName);
    nicBacking.setNetwork(morNetwork);
    nic.setBacking(nicBacking);
    VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
    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 : VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) VirtualPCNet32(com.vmware.vim25.VirtualPCNet32) VirtualVmxnet2(com.vmware.vim25.VirtualVmxnet2) VirtualVmxnet3(com.vmware.vim25.VirtualVmxnet3) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualE1000(com.vmware.vim25.VirtualE1000)

Example 10 with VirtualEthernetCard

use of com.vmware.vim25.VirtualEthernetCard 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)

Aggregations

VirtualEthernetCard (com.vmware.vim25.VirtualEthernetCard)10 VirtualDevice (com.vmware.vim25.VirtualDevice)5 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)5 VirtualE1000 (com.vmware.vim25.VirtualE1000)5 VirtualPCNet32 (com.vmware.vim25.VirtualPCNet32)5 VirtualVmxnet2 (com.vmware.vim25.VirtualVmxnet2)5 VirtualVmxnet3 (com.vmware.vim25.VirtualVmxnet3)5 DistributedVirtualSwitchPortConnection (com.vmware.vim25.DistributedVirtualSwitchPortConnection)4 VirtualEthernetCardDistributedVirtualPortBackingInfo (com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 VirtualEthernetCardNetworkBackingInfo (com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo)3 ArrayList (java.util.ArrayList)3 Pair (com.cloud.utils.Pair)2 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)1 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)1 VirtualSwitchType (com.cloud.hypervisor.vmware.mo.VirtualSwitchType)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1