I have been spending quite a bit of time lately with PowerCLI Core, especially with one of my pet projects. One of the limitations that PowerCLI Core has today is that the Storage cmdlets which includes vSAN and VVol functionality has not been ported over yet. This means that if you need to do something with VM Storage Policies for example, it would not be possible with PowerCLI Core and you would have to use the Windows PowerCLI version instead.

While investigating for an alternative solution to PowerCLI Core to get access to the Storage Policy Based Management (SPBM) APIs, I was pleasantly surprised to learn that pyvmomi (vSphere SDK for Python) had recently added support for the SPBM APIs in their release last year. I had accidentally stumbled onto this news while looking through the pyvmomi Github issues, specifically this one here. I was surprise to see there was no mention of this enhancement in the pyvmomi release notes.

This is great news for pyvmomi consumers and given this was news to me, I am guessing it might be news for others so figure I would also share the info. While looking into using the SPBM APIs from pyvmomi, I did not see any sample scripts showing how to use the SPBM API. Given I needed to write a script for my project, I figure I would also create a couple of examples to help others get started.

Here are two sample SPBM pyvmomi scripts:

Here is an example of running the first script which lists all VM Storage Policies that are defined for a given vCenter Server:

./list_vm_storage_policy.py -s -u [email protected]' -p 'VMware1!'

Here is an example of running the second script which updates an existing VM Storage Policy called "Silver" with the following configuration changes to the policy FTT=1, Stripe Width=2 and Force Provisioning=False:

./update_vm_storage_policy.py -s -u [email protected]' -p 'VMware1!' -n Silver -r "{'VSAN.hostFailuresToTolerate':1,'VSAN.stripeWidth':2,'VSAN.forceProvisioning':False}"

You can confirm the change was applied by running the first script again or you could also login to your vSphere Web Client to see the changes as shown in the screenshot below.

For more information on how to get started with SPBM API, be sure to check out the SPBM API Programming Guide as well as the SPBM API Reference Guide.

3 thoughts on “SPBM APIs are now included in pyvmomi (vSphere SDK for Python)

  1. Wow, I can’t believe you just posted this 4 hours ago. It’s exactly what I was looking for! Thanks!

  2. Hi William,

    Are there any commands that could be used to show the VM storage policy uuid with RVC or any other ways?

Thanks for the comment!