com.vmware.vim25.VirtualEthernetCard Java Examples

The following examples show how to use com.vmware.vim25.VirtualEthernetCard. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String dvPortGroupName,
        String dvSwitchUuid, String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
    final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();

    dvPortConnection.setSwitchUuid(dvSwitchUuid);
    dvPortConnection.setPortgroupKey(morNetwork.getValue());
    dvPortBacking.setPort(dvPortConnection);
    nic.setBacking(dvPortBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
 
Example #2
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String portGroupName,
        String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(portGroupName);
    nicBacking.setNetwork(morNetwork);
    nic.setBacking(nicBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
 
Example #3
Source File: VmwareCustomizeProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected List<CustomizationAdapterMapping> createCustomizationAdapterMappings(
        VmwareProcessClient vmwareProcessClient, VirtualMachine machine) {

    List<CustomizationAdapterMapping> nicSettingMap = new ArrayList<CustomizationAdapterMapping>();

    // VirtualEthernetCardを取得
    VirtualMachineConfigInfo configInfo = machine.getConfig();
    for (VirtualDevice device : configInfo.getHardware().getDevice()) {
        if (device instanceof VirtualEthernetCard) {
            VirtualEthernetCard virtualEthernetCard = VirtualEthernetCard.class.cast(device);
            CustomizationAdapterMapping mapping = new CustomizationAdapterMapping();
            CustomizationIPSettings settings = new CustomizationIPSettings();

            // すべてのNICをDHCPにする
            CustomizationDhcpIpGenerator dhcpIp = new CustomizationDhcpIpGenerator();
            settings.setIp(dhcpIp);

            mapping.setMacAddress(virtualEthernetCard.getMacAddress());
            mapping.setAdapter(settings);
            nicSettingMap.add(mapping);
        }
    }

    return nicSettingMap;
}
 
Example #4
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public static VirtualDevice prepareNicOpaque(VirtualMachineMO vmMo, VirtualEthernetCardType deviceType, String portGroupName,
        String macAddress, int contextNumber, boolean connected, boolean connectOnStart) throws Exception {

    assert(vmMo.getRunningHost().hasOpaqueNSXNetwork());

    VirtualEthernetCard nic = createVirtualEthernetCard(deviceType);

    VirtualEthernetCardOpaqueNetworkBackingInfo nicBacking = new VirtualEthernetCardOpaqueNetworkBackingInfo();
    nicBacking.setOpaqueNetworkId("br-int");
    nicBacking.setOpaqueNetworkType("nsx.network");

    nic.setBacking(nicBacking);

    nic.setAddressType("Manual");
    nic.setConnectable(getVirtualDeviceConnectInfo(connected, connectOnStart));
    nic.setMacAddress(macAddress);
    nic.setKey(-contextNumber);
    return nic;
}
 
Example #5
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected VirtualEthernetCard editEthernetCards(VirtualMachine machine, String networkName) {
    // ネットワークアダプタ E1000を使用する
    VirtualEthernetCard ethernetCard = new VirtualE1000();

    // 分散ポートグループ情報取得
    DistributedVirtualPortgroupInfo dvPortgroupInfo = getDVPortgroupInfo(machine, networkName);

    if (dvPortgroupInfo != null) {
        // 分散ポートグループの場合
        VirtualEthernetCardDistributedVirtualPortBackingInfo nicBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
        nicBacking.setPort(new DistributedVirtualSwitchPortConnection());
        nicBacking.getPort().setPortgroupKey(dvPortgroupInfo.getPortgroupKey());
        nicBacking.getPort().setSwitchUuid(dvPortgroupInfo.getSwitchUuid());
        ethernetCard.setBacking(nicBacking);
    } else {
        // 標準ポートグループの場合
        VirtualEthernetCardNetworkBackingInfo backingInfo = new VirtualEthernetCardNetworkBackingInfo();
        backingInfo.setDeviceName(networkName);
        ethernetCard.setBacking(backingInfo);
    }

    return ethernetCard;
}
 
Example #6
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected boolean checkSameNormalNetwork(VirtualEthernetCard ethernetCard1, VirtualEthernetCard ethernetCard2) {
    if (!(ethernetCard1.getBacking() instanceof VirtualEthernetCardNetworkBackingInfo)) {
        return false;
    }

    if (!(ethernetCard2.getBacking() instanceof VirtualEthernetCardNetworkBackingInfo)) {
        return false;
    }

    VirtualEthernetCardNetworkBackingInfo backingInfo1 = VirtualEthernetCardNetworkBackingInfo.class
            .cast(ethernetCard1.getBacking());

    VirtualEthernetCardNetworkBackingInfo backingInfo2 = VirtualEthernetCardNetworkBackingInfo.class
            .cast(ethernetCard2.getBacking());

    return StringUtils.equals(backingInfo1.getDeviceName(), backingInfo2.getDeviceName());
}
 
Example #7
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected boolean checkSameDistributedNetwork(VirtualEthernetCard ethernetCard1,
        VirtualEthernetCard ethernetCard2) {
    if (!(ethernetCard1.getBacking() instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo)) {
        return false;
    }

    if (!(ethernetCard2.getBacking() instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo)) {
        return false;
    }

    VirtualEthernetCardDistributedVirtualPortBackingInfo backingInfo1 = VirtualEthernetCardDistributedVirtualPortBackingInfo.class
            .cast(ethernetCard1.getBacking());

    VirtualEthernetCardDistributedVirtualPortBackingInfo backingInfo2 = VirtualEthernetCardDistributedVirtualPortBackingInfo.class
            .cast(ethernetCard2.getBacking());

    return StringUtils.equals(backingInfo1.getPort().getPortgroupKey(), backingInfo2.getPort().getPortgroupKey());
}
 
Example #8
Source File: VmwareHelper.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static VirtualEthernetCard createVirtualEthernetCard(VirtualEthernetCardType deviceType) {
    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();
    }
    return nic;
}
 
Example #9
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: VmUtils.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
VirtualDeviceConfigSpec getNicSpecs(String fileName, List<VirtualDevice> virtualDevicesList,
                                    VirtualDeviceConfigSpecOperation operation, String addressType,
                                    Integer key, String parameter, VmInputs vmInputs) {
    VirtualDeviceConfigSpec nicSpecs = new VirtualDeviceConfigSpec();
    VirtualEthernetCard nic;
    if (Operation.ADD.toString().equalsIgnoreCase(parameter)) {
        nic = getEth(fileName, addressType, key);
        return getNicOpSpec(nicSpecs, operation, nic);
    } else {
        nic = findVirtualDevice(VirtualEthernetCard.class, virtualDevicesList, vmInputs);
        if (nic != null) {
            return getNicOpSpec(nicSpecs, operation, nic);
        }
    }
    throw new RuntimeException("No nic named: [" + vmInputs.getUpdateValue() + "] can be found.");
}
 
Example #11
Source File: NetworkManager.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the NICs in the given VM.
 *
 * @param vmw
 *            connected VMware client entity
 * @param paramHandler
 *            entity which holds all properties of the instance
 * @param vmwInstance
 *            the virtual machine that gets reconfigured
 */
public static void configureNetworkAdapter(VMwareClient vmw,
        VirtualMachineConfigSpec vmConfigSpec,
        VMPropertyHandler paramHandler, ManagedObjectReference vmwInstance)
        throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);

    int numberOfNICs = Integer.parseInt(paramHandler
            .getServiceSetting(VMPropertyHandler.TS_NUMBER_OF_NICS));

    if (numberOfNICs != vmNics.size()) {
        throw new Exception(
                "the number of NICs in virtual machine does not match the service parameter. VM: "
                        + configInfo.getName() + " NICs: " + vmNics.size()
                        + " " + VMPropertyHandler.TS_NUMBER_OF_NICS + ": "
                        + numberOfNICs);
    }

    for (int i = 1; i <= numberOfNICs; i++) {
        String newNetworkName = paramHandler.getNetworkAdapter(i);
        VirtualEthernetCard vmNic = vmNics.get(i - 1);
        String vmNetworkName = getNetworkName(vmw, vmwInstance, i);
        if (newNetworkName != null && newNetworkName.length() > 0
                && !newNetworkName.equals(vmNetworkName)) {
            ManagedObjectReference newNetworkRef = getNetworkFromHost(vmw,
                    vmwInstance, newNetworkName);

            replaceNetworkAdapter(vmConfigSpec, vmNic, newNetworkRef,
                    newNetworkName);
        } else {
            connectNIC(vmConfigSpec, vmNic, vmNetworkName);
        }
    }
}
 
Example #12
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public String getDvPortGroupName(VirtualEthernetCard nic) throws Exception {
    VirtualEthernetCardDistributedVirtualPortBackingInfo dvpBackingInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo)nic.getBacking();
    DistributedVirtualSwitchPortConnection dvsPort = dvpBackingInfo.getPort();
    String dvPortGroupKey = dvsPort.getPortgroupKey();
    ManagedObjectReference dvPortGroupMor = new ManagedObjectReference();
    dvPortGroupMor.setValue(dvPortGroupKey);
    dvPortGroupMor.setType("DistributedVirtualPortgroup");
    return (String)_context.getVimClient().getDynamicProperty(dvPortGroupMor, "name");
}
 
Example #13
Source File: VirtualMachineMO.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private VirtualDeviceConfigSpec getNicOpSpec(VirtualDeviceConfigSpec nicSpecs, VirtualDeviceConfigSpecOperation operation,
                                             VirtualEthernetCard nic) {
    nicSpecs.setOperation(operation);
    nicSpecs.setDevice(nic);

    return nicSpecs;
}
 
Example #15
Source File: VmUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private VirtualEthernetCard getEth(String fileName, String addressType, Integer key) {
    VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
    nicBacking.setDeviceName(fileName);

    VirtualEthernetCard nic = new VirtualPCNet32();
    nic.setBacking(nicBacking);
    nic.setAddressType(addressType);
    nic.setKey(key);

    return nic;
}
 
Example #16
Source File: VmwareInitProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected Map<String, String> createStaticNetworkData(VirtualEthernetCard ethernetCard,
        VmwareAddress vmwareAddress) {
    Map<String, String> map = new HashMap<String, String>();
    String macAddress = ethernetCard.getMacAddress().toUpperCase();
    map.put("BootProto", "static");
    map.put("Mac", macAddress);
    map.put("IP", vmwareAddress.getIpAddress());
    map.put("Netmask", vmwareAddress.getSubnetMask());
    map.put("Gateway", vmwareAddress.getDefaultGateway());
    return map;
}
 
Example #17
Source File: VmwareInitProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected Map<String, String> createPublicNetworkData(Long instanceNo, VirtualEthernetCard ethernetCard) {
    VmwareAddress vmwareAddress = vmwareAddressDao.readByInstanceNo(instanceNo);
    if (vmwareAddress == null) {
        // VmwareAddressがない場合は動的IP
        return createDhcpNetworkData(ethernetCard);
    }

    if (BooleanUtils.isTrue(vmwareAddress.getEnabled())) {
        // VmwareAddressが有効な場合は静的IP
        return createStaticNetworkData(ethernetCard, vmwareAddress);
    } else {
        // VmwareAddressが無効な場合は動的IP
        return createDhcpNetworkData(ethernetCard);
    }
}
 
Example #18
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected List<VirtualEthernetCard> createEthernetCards(VmwareProcessClient vmwareProcessClient, Long instanceNo,
        VirtualMachine machine) {
    Instance instance = instanceDao.read(instanceNo);
    List<VmwareNetwork> vmwareNetworks = vmwareNetworkDao.readByFarmNo(instance.getFarmNo());

    // ネットワーク名の取得
    PlatformVmware platformVmware = platformVmwareDao.read(instance.getPlatformNo());
    String publicNetworkName = platformVmware.getPublicNetwork();
    String privateNetworkName = platformVmware.getPrivateNetwork();
    for (VmwareNetwork vmwareNetwork : vmwareNetworks) {
        if (BooleanUtils.isTrue(vmwareNetwork.getPublicNetwork())) {
            publicNetworkName = vmwareNetwork.getNetworkName();
        } else {
            privateNetworkName = vmwareNetwork.getNetworkName();
        }
    }

    // イーサネット設定の作成
    List<VirtualEthernetCard> ethernetCards = new ArrayList<VirtualEthernetCard>();

    // Public側イーサネット設定
    if (StringUtils.isNotEmpty(publicNetworkName)) {
        VirtualEthernetCard publicEthernetCard = editEthernetCards(machine, publicNetworkName);
        ethernetCards.add(publicEthernetCard);
    }

    // Private側イーサネット設定
    VirtualEthernetCard privateEthernetCard = editEthernetCards(machine, privateNetworkName);
    ethernetCards.add(privateEthernetCard);

    return ethernetCards;
}
 
Example #19
Source File: NetworkManager.java    From development with Apache License 2.0 5 votes vote down vote up
public static List<VirtualEthernetCard> getNetworkAdapter(
        VirtualMachineConfigInfo configInfo) {
    List<VirtualEthernetCard> nics = new ArrayList<VirtualEthernetCard>();
    List<VirtualDevice> devices = configInfo.getHardware().getDevice();
    for (VirtualDevice vd : devices) {
        if (vd instanceof VirtualEthernetCard) {
            nics.add((VirtualEthernetCard) vd);
        }
    }

    return nics;
}
 
Example #20
Source File: NetworkManager.java    From development with Apache License 2.0 5 votes vote down vote up
public static int getNumberOfNICs(VMwareClient vmw,
        ManagedObjectReference vmwInstance) throws Exception {
    logger.debug("");

    VirtualMachineConfigInfo configInfo = (VirtualMachineConfigInfo) vmw
            .getServiceUtil().getDynamicProperty(vmwInstance, "config");
    List<VirtualEthernetCard> vmNics = getNetworkAdapter(configInfo);
    return vmNics.size();
}
 
Example #21
Source File: VmwareInitProcess.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
protected Map<String, String> createDhcpNetworkData(VirtualEthernetCard ethernetCard) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("BootProto", "dhcp");
    map.put("Mac", ethernetCard.getMacAddress().toUpperCase());
    return map;
}