private static VirtualDeviceConfigSpec createNicSpec(String netName, String nicName, Network network, DistributedVirtualSwitch dvs,
                                                         VirtualDeviceConfigSpecOperation op) throws Exception {

        logger.log(Level.FINE, "Netname: " + netName);
        logger.log(Level.FINE, "Nicname: " + nicName);
        logger.log(Level.FINE, "Network: " + network.getName());
        logger.log(Level.FINE, "DVS: " + dvs.getName());

        VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
        nicSpec.setOperation(op);

        String key = "";

        for (DistributedVirtualPortgroup dvpg : dvs.getPortgroup()) {
            if (dvpg.getName().equalsIgnoreCase(netName)) {
                key = dvpg.getConfig().getKey();
            }
        }

        String uuid = dvs.getConfig().getUuid();

        DistributedVirtualSwitchPortConnection switchCon = new DistributedVirtualSwitchPortConnection();
        switchCon.setSwitchUuid(uuid);
        switchCon.setPortgroupKey(key);

        VirtualEthernetCardDistributedVirtualPortBackingInfo portBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
        portBacking.setPort(switchCon);

        VirtualEthernetCard nic = new VirtualVmxnet3();

        Description info = new Description();
        info.setLabel(nicName);
        info.setSummary(netName);
        nic.setDeviceInfo(info);

        // type: "generated", "manual", "assigned" by VC
        nic.setAddressType("generated");
        nic.setBacking(portBacking);
        nic.setKey(0);

        nicSpec.setDevice(nic);
        return nicSpec;
    }