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) &&