I was reading VCDX56’s post Nutanix AHV VM Reporting Via REST API authored by Magnus Andersson @magander3 where, as the title suggests, he discusses a script he wrote to gather information about VMs running on a Nutanix AHV cluster using the REST APIs. At the end of the post, he mentioned that he would like to change the script from Bash to Python.

I have recently been doing quite a bit REST API scripting with Python, so I took a crack at it last night.

Before we get to the script a couple of things. I wrote the script for Python 3. I tested it on Python 3.5.2 on Linux (Ubuntu & CentOS), and with Python 3.6.3 on Windows 10. On the Nutanix side this script was tested against AOS 5.1.2 and Nutanix Community Edition (CE) 2017.05.22.

This script utilizes the “requests” module, which is a standard module that should already be installed on Ubuntu 16.04. For Windows or other situations where the requests module isn’t loaded, you will need to install it via “pip install requests”. If pip is not installed, reinstall/upgrade your Python installation and include pip as you install it.

Mac users should use Homebrew to install Python 3 by running “brew install python3” from Terminal. That will include pip3 so you can then run “pip3 install requests”. Then you can run the script by running “python3 ahv-vm-reporting.py”. Thanks to Peter Chang @virtualbacon for the Mac instructions/testing.

This script will collect the following information and dump it into a CSV file:

  • VM Name
  • Total Number of Cores
  • Number of vCPUs
  • Number of Cores per vCPU
  • Memory in GB
  • Number of vDisks attached (not including cdroms or Volume Groups)
  • Disk Usage GB (total across all vDisks)
  • Disk Allocated GB (total across all vDisks)
  • Flash Mode Enabled
  • Volume Group Attached
  • Local AHV Snapshot Count
  • Local Protection Domain Snapshot Count
  • Remote Protection Domain Snapshot Count
  • IP Address(es)
  • Network Placement
  • AHV Host Placement

Comparing to Magnus’ work, you will see that I added a couple of fields and I did not include the Self Service Portal information. For that, I’m waiting for the Nutanix Calm integration in Prism Central.

So, on to the script. Just as in Magnus’ Bash version, you will need to edit the following variables to make it work in your environment:

  • user = “viewonly”
  • passwd = “viewonly”
  • CIP = “”

As you can probably tell from the variables, this script requires a user with “View Only” rights to the Nutanix cluster. While you could use a more privileged account, there is no need. The CIP variable is the Cluster Virtual IP Address or resolvable DNS name of the cluster.

Download (copy/paste) the script and run it from your own workstation (no need to run this in a CVM). After running the script a csv file will be created in the directory from where the script was run. The name will be “CIP-VM_Report-YYYYMMDDHHMM.csv” where CIP is the IP or DNS name defined in the CIP variable in the script. Open up the CSV, select all the columns, autofit the columns to text, and center the text. Bold the top row for titles and here’s what it should look like (click the image below for full view):






Again, credit is very much due to Magnus @magander3 for the idea and creation of the Bash version of this script.

Feel free to ask questions in the comments!