static VirtualDeviceConfigSpec createNicSpec(String netName, String nicName) throws Exception { VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add); VirtualEthernetCard nic = new VirtualPCNet32(); VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); nicBacking.setDeviceName(netName); Description info = new Description(); info.setLabel(nicName); info.setSummary(netName); nic.setDeviceInfo(info); // type: "generated", "manual", "assigned" by VC nic.setAddressType("generated"); nic.setBacking(nicBacking); nic.setKey(0); nicSpec.setDevice(nic); return nicSpec; }
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; }
static VirtualDeviceConfigSpec getNICDeviceConfigSpec( VirtualMachine vm, String op, String name) throws Exception { VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); VirtualMachineConfigInfo vmConfigInfo = vm.getConfig(); if("add".equalsIgnoreCase(op) && doesNetworkNameExist(vm, name)) { nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add); VirtualEthernetCard nic = new VirtualPCNet32(); VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); nicBacking.setDeviceName(name); nic.setAddressType("generated"); nic.setBacking(nicBacking); nic.setKey(4); nicSpec.setDevice(nic); return nicSpec; } else if("remove".equalsIgnoreCase(op)) { VirtualDevice [] vds = vmConfigInfo.getHardware().getDevice(); nicSpec.setOperation( VirtualDeviceConfigSpecOperation.remove); for(int i=0;i<vds.length;i++) { if((vds[i] instanceof VirtualEthernetCard) && (vds[i].getDeviceInfo().getLabel().equalsIgnoreCase( name))) { nicSpec.setDevice(vds[i]); return nicSpec; } } } return null; }