VMware {code} Community
mm6
Contributor
Contributor

can't connect virtual nic to distributed virtual port group

I'm trying to connect a virtual nic on a vm to a distributed virtual port group. I have tried every set of options to the nic config spec I can think of.

For any VM I create using the API, in vSphere Client when you right click the VM, edit settings, select the network adapter, the network label dropdown is set to empty. When I pick the correct network from the dropdown the nic in the VM works.

The sample code seems to say that all you need to do is setDeviceName on the nic backing to one of the names in the network label dropdown in vSphere client.

Have tried:

- backing.setNetwork to a reference to the network

- using VirtualEthernetCardDistrbibutedVirtualPortBackingInfo instead of VirtualEthernetCardNetworkBackingInfo

- using nic.setDeviceInfo() and setting label and summary to the name of the network

I just need to know what to set to populate this dropdown so the nic works without manually setting the network label in the gui.

0 Kudos
2 Replies
mm6
Contributor
Contributor

The only way I could get the VM to come up with working network was using VirtualE1000 with VirtualEthernetCardDistributedVirtualPortBackingInfo backing.

Backing had port set to a DistributedVirtualSwitchPortConnection.

DistributedVirtualSwitchPortConnection had portgroupkey set to the name of the MOR of the network (like "dvportgroup-669"), and switchuuid set to the uuid of the switch, which had to be formatted exactly with lowercase, a space every two characters and dash in the middle. I found out these by looking at the .vmx files of working ones. Stil haven't found a way to get switch uuids using the API.

Code that worked:

public VirtualDeviceConfigSpec buildNic(final String networkName)

throws VmConfigBuilderException {

final DistributedVirtualSwitchPortConnection connection = new DistributedVirtualSwitchPortConnection();

connection.setPortgroupKey(networkName);

connection

.setSwitchUuid("b8 11 03 50 35 cf ee cb-8d 36 34 77 9c 92 76 83");

final VirtualEthernetCardDistributedVirtualPortBackingInfo backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo();

backing.setPort(connection);

final VirtualEthernetCard nic = new VirtualE1000();

nic.setAddressType("generated");

nic.setBacking(backing);

nic.setKey(30);

final VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();

spec.setOperation(VirtualDeviceConfigSpecOperation.add);

spec.setDevice(nic);

return spec;

}

0 Kudos
anshumanmathur
Contributor
Contributor

How do i get the UUID of the dvSwitch to which the portgroup belongs?

0 Kudos