vRA 7.x REST API calls–list all VMs (Python example)

This is actually a script I built to test out various things at once.  I was testing (and learning) how the vRealize Automation REST API calls work.  There are other good resources on the web for getting started.  While not a vRealize Automation example, I enjoyed this blog entry on Python and vSphere REST API calls with Python.    Between that, and the official documention, and some Postman experimentation, I was able to get things going.

The script itself as I use it is currently called within a simple Flask application, and served up by a NGINX container.  

Some other notes:

  • Import Credentials requires you to make a simple python file with a dictionary I called “login.”
  • You need a bearer token to authenticate with vRA.  So the first function grabs one.
  • Main work is done in the “get_resource_views,” where we grab all of the VMs created, get the information we desire, and then sort it.
  • “get_csv” creates a .csv file that I then save.  I link to the .csv file on the internal web page so that the report can be downloaded by those that need it.

The code can probably be tweaked further, but this should be enough to get most up and running.  I welcome any and all comments.

 

 

 

Quick PowerShell script to Storage VMotion a list of VMs

Everyone has simple scripts they use to get through their day, I’m sure. The following scenario deals with having a large list (as provided in a .csv) of VMs needing to be migrated to a different datastore cluster. When dealing with multiple migrations, Storage DRS doesn’t update as quickly as one would like. Therefore, the current LUN with the most space can quite quickly be pushed to capacity. Thus, in this script we sort all of the LUNS by the amount of free space, grab the top 10 with the most free space, and randomly pick a lun to migrate the next VM.

For our own purposes, we prefer to make sure all the .vmdks are eager zeroed. So just in case, we transform any potential non-thick provisioned eager zeroed disk.

Cleaning up Bad or ‘Stuck’ Requests in vRealize Automation (7.1)

Had a few requests that stayed within the system even though the builds failed.  This led to repeated attempts by vRA to expire items that didn’t exist.  Got together with VMware Tech Support and learned this handy method of clearing these requests up.

1. SSH into the vRA appliance
2. su -c “/opt/vmware/vpostgres/9.5/bin/psql vcac” postgres (ignore the “could not change directory” error you’ll get)
3. update cat_resource set leasestate = null, status = ‘DELETED’, datedeleted = now()::timestamp where name = ‘Target Item Name‘;
4. update comp_deployment set status = ‘DELETED’ where name = ‘Target Item Name‘;
5. \q
6. Exit

Hope that helps.

© 2018 msharp tech

Theme by Anders NorénUp ↑