WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / SPBM APIs are now included in pyvmomi (vSphere SDK for Python)

SPBM APIs are now included in pyvmomi (vSphere SDK for Python)

01.19.2017 by William Lam // 6 Comments

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 6.0.0.2016.4 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:

  • list_vm_storage_policy.py - List all VM Storage Policies
  • update_vm_storage_policy.py - Update an existing VM Storage Policy

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 192.168.1.51 -u '*protected email*' -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 192.168.1.51 -u '*protected email*' -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.

More from my site

  • Feedback on default behavior for VM Storage Policy
  • Minimum permissions to view VM Storage Policies
  • Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy
  • Extending RVC to support renaming VM Storage Policies
  • SPBM (Storage Policy Based Management) MOB in vSphere 5.5

Categories // Automation, VSAN Tags // pyVmomi, spbm, vm storage policy, vm storage profile

Comments

  1. *protectedScott S. says

    01/19/2017 at 11:44 am

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

    Reply
  2. *protectedRahul Garg says

    02/20/2017 at 1:05 am

    Thanks ... I was looking for this only.

    Reply
  3. *protectedXing says

    03/23/2017 at 8:34 pm

    Hi William,

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

    Reply
  4. *protectedcoolsunnyvale says

    02/19/2020 at 5:00 pm

    Do u have any samples for pbmcreate() .

    Reply
  5. *protectedshwetank says

    12/28/2020 at 10:45 am

    I am recently trying to fetch vm storage policies and getting the below error:

    Traceback (most recent call last):
    File "/Users/mshwetank/Desktop/test/./test_sp.py", line 109, in
    main()
    File "/Users/mshwetank/Desktop/test/./test_sp.py", line 85, in main
    pm = pbmContent.profileManager
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyVmomi/VmomiSupport.py", line 706, in
    self.f(*(self.args + (obj,) + args), **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyVmomi/VmomiSupport.py", line 512, in _InvokeMethod
    return self._stub.InvokeMethod(self, info, args)
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyVmomi/SoapAdapter.py", line 1397, in InvokeMethod
    raise obj # pylint: disable-msg=E0702
    pyVmomi.VmomiSupport.SecurityError: (vmodl.fault.SecurityError) {
    dynamicType = ,
    dynamicProperty = (vmodl.DynamicProperty) [],
    msg = '',
    faultCause = ,
    faultMessage = (vmodl.LocalizableMessage) []
    }

    I am getting the error at the below line in list_vm_storage_policy.py:

    profileIds = pm.PbmQueryProfile(resourceType=pbm.profile.ResourceType(
    resourceType="STORAGE"), profileCategory="REQUIREMENT"
    )

    Any help on this would be greatly appreciated.

    Reply
  6. *protectedNick says

    08/25/2022 at 9:26 pm

    Didn't seem to find any 'disconnect' action in your sample script. Any idea how to do that? Or the pbm endpoint will just get disconnected along with the ordinary vcenter service instance?

    Reply

Thanks for the comment!Cancel reply

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

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...