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.
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.
Can someone help on how to find these VMKernel ports connected to a portgroup?
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.
Thanks for the reply and that helps I guess. Could you/some one help if the following is correct?
Seems this object (Portgroup) is not listing any hosts in the array. An idea? It is supposed to list the hosts right?