VMware {code} Community
jonathan5
Contributor
Contributor

How do networks relate to virtual switches?

In the VI SDK, a network relates one or more hosts to one or more VMs. In the VMWare web console for my host, several networks are displayed such as Bridged, HostOnly and NAT, each with a particular "VMNet", which appear to be the virtual switches. I can't find anywhere in the VI SDK though where a network relates to a virtual switch or a virtual nic. Ultimately, I'm looking to find what virtual switches or nics it is that my VMs are using. How can I find this through the VI SDK?

Thanks

0 Kudos
2 Replies
admin
Immortal
Immortal

HostNetworkSystem will provide you all of the information you are looking for. To get an mor of HostNetworkSystem, you can traverse from the HostSystem.configManager.networkSystem.

Once you have the mor to HostNetworkSystem, fetch it's networkConfig.portGroup property, which lists all the port groups defined on the host. You can use two of the following properties:

1a) Each portGroup has a property portGroup.spec.name, listing the name of the portgroup.

1b) portGroup.spec.vswitchName. This will provide you the identifier of the virtual switch on which this port group is located.

Now mapping these details with respect to VM:

A VirtualMachine mor will have a propety Network, which returns a collection of references to the subset of network objects in the datacenter that is used by this virtual machine. The name property of these networks will be the key to relate to 1a and 1b, thus relating the HostNetwork System details to the relevant vswitches or nics being used by vm's.

0 Kudos
jonathan5
Contributor
Contributor

Makes sense. Thanks for the response.

0 Kudos