// http://communities.vmware.com/message/1251528
VirtualDeviceConfigSpec nicSpec =
new VirtualDeviceConfigSpec();
nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
VirtualEthernetCard nic=null;
if (nicAdapter.equals("e1000")) {
nic= new VirtualE1000();
}
if (nicAdapter.equals("pcnet32")) {
nic= new VirtualPCNet32();
}
if (nicAdapter.equals("vmxnet2")) {
nic= new VirtualVmxnet2();
}
if (nicAdapter.equals("vmxnet3")) {
nic= new VirtualVmxnet3();
}
if (nic==null) {
throw new Exception("unknown nic adaptor type: use e1000, pcnet32, vmxnet2, vmxnet3 ");
}
nic.setConnectable(new VirtualDeviceConnectInfo());
nic.connectable.setStartConnected(startConnected);
nic.connectable.setConnected(connected);
VirtualEthernetCardNetworkBackingInfo nicBacking =
new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(nicNetwork);
Description info = new Description();
info.setLabel(nicName);
info.setSummary(nicNetwork);
nic.setDeviceInfo(info);
// type: "generated", "manual", "assigned" by VC
nic.setAddressType("generated");
nic.setBacking(nicBacking);
nic.setKey(0);
nicSpec.setDevice(nic);
return nicSpec;
}