Use pyvmomi to re-apply Storage Profile and Reclaim Space

By | August 4, 2017

I had a 5-node VSAN with 100+ TB of hybrid storage, and it was FULL.

I was kind of surprised because the application wasn’t heavy in use yet, but a new disk was added kept getting a vSphere error that it was running out of space and the VM would then crash.

I remembered a post from William Lam that stated that OVFs would deploy as thick (100% Object Space Reservation or OSR) even if the vmdks have the VSAN Default Policy assigned and that policy has 0% OSR. I remembered that the customer did deploy some VMs with Thick explicitly, just to try to make sure they saw the real space that would be available (including all disk space assigned and accounting for mirror copy). So even though the policy was set one way, it was actually a 100% OSR

You can see here that I had a huge amount of “overreserved” due to the thick provisioning. I basically needed to re-apply the VSAN Default Policy, but unfortunately the SPBM Cmdlets didn’t work for my environment, they were throwing off index errors and whatnot.

So I decided to try pyvmomi based on another post. Take a look at my other post about how to get pyvmomi setup on a RHEL 6 box.

Unfortunately William’s examples since actually set the policy. They listed the storage policies and updated the storage policies.

I found some other sample scripts and figured out that I needed to do a use a device spec, assign a profile to that and then assign that to a vm change spec and then pass that to the reconfigure vm method. It’s all in the script that you can find here.

You do need the Storage Policy ID (the -p param) so use william’s script (you can use the version that I have here that works with python3.3)

You also need the UUID of the VM (the -d param), which is NOT the MOREF or smbios.

According to Alan Renouf, this is the VC-VM instance uuid



Leave a Reply

Your email address will not be published. Required fields are marked *