Leveraging the vSphere API cookbook in PowerCLI

If you have ever run into an issue with PowerCLI where you can find the information you need in the API guide but not a cmdlet to report the info?  Here is one walk through of how I got my groove back tracked down the info I needed.

I found myself, as I often do, wandering the rain washed beaches in South Florida wondering how to figure out from PowerCLI the Network Resource Pool assigned to a given Distributed PortGroup.

A perusal of the latest PowerCLI update showed some new cmdlets but none of them report on the NRPs – even at the dVS level.

I did find that the net-dvs command from ESXi would report the dVS info like this:

com.vmware.common.port.respools.cfg:
 NRP_30717_dvs-421:50:-1:2

Although it would seem a little cryptic w/o the user-defined name and didn’t link back to a portgroup.  It did list the QoS tag (the last integer on the second line) tho so that was something.

I noticed in the API there was a Managed Object – Vmware Distributed Virtual Switch which had a  networkResourcePool property. That sounded promising, now what?

I started digging through blog after blog about accessing the API via PowerCLI and finally I just started playing at the PowerCLI prompt using the Get-View cmdlet Alan and Luc rave about.

$vds = get-vdswitch -name "sostech" | get-view
$vds |gm

hey – there’s my field!

TypeName: VMware.Vim.VmwareDistributedVirtualSwitch

Name MemberType Definition
---- ---------- ----------
AddDVPortgroup Method System.Void AddDVPortgroup(VMware.Vim.DVPortgroupConfigSpec[] spec)
...
NetworkResourcePool                 Property   VMware.Vim.DVSNetworkResourcePool[] NetworkResourcePool {get;}
...

It lists it as a property, so:

PowerCLI E:\> $vds.networkresourcepool
Key : nfs
Name : NFS Traffic
Description : NFS Traffic Type
ConfigVersion : 1
AllocationInfo : VMware.Vim.DVSNetworkResourcePoolAllocationInfo
DynamicType :
DynamicProperty :
...

Key : NRP_2258_dvs-546
Name : SOSTechPool
Description :
ConfigVersion : 1
AllocationInfo : VMware.Vim.DVSNetworkResourcePoolAllocationInfo
DynamicType :
DynamicProperty :

(Note that there are eight default pools)
Ok, there is the name, so what QoS did I set for that and what portgroups is it assigned to?

The AllocationInfo field starts with “VMware.Vim” so it must be an object, let’s look in there:

PowerCLI E:\> $vds.networkresourcepool[8].AllocationInfo
Limit : -1
Shares : VMware.Vim.SharesInfo
PriorityTag : 1
DynamicType :
DynamicProperty :

For those of you playing along at home, the $vds.networkresporcepool is an array – the eight defaults plus my custom one.  The [8] tells PowerShell to use the ninth member of the array.  And there is my QoS / PriorityTag.

One liner, retrieving the QoS or PriorityTag of a specific Resource Pool on a specific vDS:

((get-vdswitch -name "sostech" | get-view).networkresourcepool | where {$_.name -eq "SOSTechPool"}).allocationinfo.prioritytag

Now to figure out what PortGroups use it. I dug all over the API and finally found the networkResourcePoolKey which was a property of a DVPortSetting.  However, that is a property for a specific port, surely the portgroup has it set at some level?  I then noticed that the DVPortSetting was a property of several objects, including DVSConfigSpec – which turned out to hold the default information for a given dVS including a DVPortSetting which is used for the default settings for all ports.

Using a technique as above – assigning a Get-View of the object to a variable and then drilling into it, I arrived at a oneliner to return the “Key” of the ResourcePool associated with a given portgroup (note that -1 is returned if none is configured)

(get-vdportgroup -name "SOSTech" | get-view).config.DefaultPortConfig.NetworkResourcePoolKey.value

You can then match that key with the “key” value of the NetworkResource Pool found above to retreive the pretty name and QoS setting.

This entry was posted in Computing, PowerShell, Scripting, Virtualization, VMware. Bookmark the permalink.

4 Responses to Leveraging the vSphere API cookbook in PowerCLI

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.