VMware Cloud Community
JLogan2016
Enthusiast
Enthusiast

Setting the number of available ports to 0 on all port groups

I am currently working with a customer that does government work, and has a requirement that all portgroups have 0 ports available. When a new server is spun up, an additional port is added; when it is decommissioned the port is (theoretically) removed. However this has not been the case, and running a small script against all portgroups shows a number that have several or more open ports. I am looking for a way to drop that to 0 without having to go through each manually, but am not finding a way.

To see what is out there, I am just pulling info from get-virtualportgroup. $_.ExtensionData.PortKeys.Count gives me the total number of ports, $_.ExtensionData.vm.count gives me the number of ports in use, and then I am simply subtracting one from the other to get a "portsleft" variable. Is there an easy way to take that portsleft var and set it to 0?

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Just to confirm, you are only looking at VDS, not VSS?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

At this point, that is correct. This customer does not use any VSS for VM traffic. If it is easily done to account for both I would like to see how to do so; who knows what the next customer will be using.

Reply
0 Kudos
LucD
Leadership
Leadership

I did some experimenting, and I think $vds.ExtensionData.Summary.VM.Count is not a correct value for the number of ports used.

Especially if a VM has more than 1 vNIC connected to a portgroup on that VDS.

I came up with the following (it shows the name of the VDS and the number of used ports (by VMs) over the total number of ports).

foreach($vds in Get-View -ViewType VmwareDistributedVirtualSwitch){

    $pgKeys = $vds.Portgroup.Value

    $nics = Get-View -Id $vds.Summary.vm | %{

      $_.Config.Hardware.Device |

      where{$_ -is [VMware.Vim.VirtualEthernetCard] -and $pgKeys -Contains $_.Backing.Port.PortgroupKey}

    }

   

    "$($vds.Name): $($nics.Count)/$($vds.Config.NumPorts)"

}

Can you check if that gives the correct values in your environment?

Also note that this does not yet take into account the number of ports used by the Uplinks.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

It appears that snippet shows the proper number for Total ports on all the VDS', but not the $nics.Count seems to be off

Example:

     dvSwitch-LOC1-Production-Blades: 0/33 - Actual 20/33 in use, 13 available

     dvSwitch-LOC1-Test-Blades: 145/1062 - Actual 811/1062 in use, 251 available

Reply
0 Kudos
LucD
Leadership
Leadership

Interesting, are those 20 ports in use on the 1st VDS all used by VMs?
And are the corresponding vNICs on those VMs in a connected state?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

So, actually only 12 are on VMs. Each of the two hosts has 1 for Management, 1 for vMotion, and 2 uplinks (8 total). Of the 12 VMs, all but one of the VMs are showing connected; the last is a proxy that is powered down.

Reply
0 Kudos
LucD
Leadership
Leadership

Of course, I forgot the VMKernel connections.

Back to the lab :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos