lurims
Enthusiast
Enthusiast

How to find VMkernel ports of a Distributed Virtual PortGroup

I could not find any property related to the VMkernel ports of a DV Portgroup.  I am able to list protgroup and config property, which gives most of the things I need, but I could not find anything on  how to check if a Portgroup has any Kernel ports and how to list them.

pastedImage_1.pngpastedImage_2.png

Tags (2)
0 Kudos
5 Replies
daphnissov
Immortal
Immortal

It's probably not a property of a vDS because a vmkernel port is not specific to a vDS or vSS; it's independent of those switch types.

0 Kudos
lurims
Enthusiast
Enthusiast

Can someone help on how to find these VMKernel ports connected to a portgroup?

0 Kudos
MihailsA
Contributor
Contributor

Hi lurims,

It's something similar I've had to do recently. I had to remove all the VMkernel ports on all hosts in a cluster within a specified distributed virtual portgroup. I used this code with two inputs:

hosts (Array/VC:HostSystems)

portGroup (VC:DistributedVirtualPortgroup)

And the script itself:

for each (var host in hosts){

    var networkSystem = host.configManager.networkSystem; //host is a input parameter of type VcHostSystem
    System.log('Looking at host: '+host.name);
    for each (var vnic in networkSystem.networkConfig.vnic) {
        if (vnic.spec.distributedVirtualPort) {
            System.debug('Got vmk: '+vnic.device+ ' '+vnic.spec.ip.ipAddress+ ' '+ vnic.spec.distributedVirtualPort.portgroupKey+' distributed portgroup');
          if (vnic.spec.distributedVirtualPort.portgroupKey == portGroup.key) {
            System.log('Removing vmk: '+vnic.device);
            networkSystem.removeVirtualNic(vnic.device);
          }
        }
        else {
            System.debug('Got vmk: '+vnic.device+ ' '+vnic.spec.ip.ipAddress+ ' '+ vnic.portgroup+' standard portgroup');
        }
    }
}      

In your case you just have to replace the networkSystem.removeVirtualNic(vnic.device);  operation with your own operations, like populate an Array of strings with vnic.device , which is the name of the VMkernel adapter.

0 Kudos
lurims
Enthusiast
Enthusiast

Thanks for the reply and that helps I guess.  Could you/some one help if the following is correct?

  1. for a given port group I will go and find the host (VC:HostSystem)
  2. I assume (have seen so) all Hosts are connected to the same cluster has the same set of VMKernel Adapaters, so checking one ESXi host should be good enough.
  3. List all VMKernel Adapaters of each NIC of that host and list all  PGs of each NIC.  I see this is listed as "Network Labels" in vSphere client as below.  Seems this network label object is nothing but portgroup.
  4. pastedImage_1.png
  5. Once I get all port groups  of each NIC, listed for the Host object, I will list them and compare with the portgroup in the input.  If there is at least 1 match, it is the confirmation that the PG has a VMkernel port connected to, otherwise, there is no VMKernel port connected to the PG.
0 Kudos
lurims
Enthusiast
Enthusiast

Seems this object (Portgroup) is not listing any hosts in the array.  An idea?  It is supposed to list the hosts right?

pastedImage_0.png

0 Kudos