Nutanix : Get List of Powered-off VMs (AHV)


Background

We have a quite large AHV infrastructure and sometimes this is not always easy to get all the relevant details to improve/maintain it. Don't get me wrong, Prism Central is helping a lot. But, when it comes to optimisation of the assets, it is hard to see what gains we can make - starting by detecting the powered off VMs.

Powered-Off VMs

VMs that are powered off are not taking any compute : True ! But what about storage ? Everything is thin provisioning by default on Nutanix, this is correct, but when you have many VMs powered off without any relationship between them, you still have some storage and reserved storage allocated. This is not always very obvious in Prism Central and I did not find a way to report the consumed storage.

There is a Prism Central API endpoint that help achieving this goal.

/api/nutanix/v3/vms/list

This call requires a payload to be sent, this payload is actually a way to filter the results. Remember, we need to get the powered off VM. So, we filter on the power_state.

    {
"kind": "vm",
"filter": "power_state == off",
"length" : 500
    }

The parameter length is specifying the maximum number of rows to return.
In a cURL statement, you get something similar to this : 

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{ \"kind\": \"vm\", \"filter\": \"power_state == off\", \"length\" : 500 }" "https://1.2.3.4:9440/api/nutanix/v3/vms/list"

The result is a long list of JSON-like string where it is easy to find the relevant information about the VMs and their status.

Of course, this could be interfaced into a script It can be find here. Please note the new function added to my Nutanix php Framework : nxpcGetOffVMs($clusterConnect).

Here is a sample output :


Sorry for the blurred area, I just need to protect my asset (even if they are powered off by now ;)

So, according to the above screenshot, we could reclaim almost 3 TB if we remove them. This is some serious savings ! Pay attention, this figure could be over estimated if your VM disks are not completely used and if you have linked clones ...

Disclaimer : this script only supports AHV with the current Prism Central version (2021.9.0.1). There are plans to get support for vmware as well in a future release. If your plan is to get any type of VMs, you need to query each clusters separately for each types of VMs family. This could be a nice evolution for this script.

I encourage you to run this tool regularly to make sure there are no VMs out of sights. This is not a bad thing to have powered off VMs on your clusters, forgetting them could be an issue, especially if you are short on storage.

I hope this helps !



Comments

  1. Are you running your script from a cvm in the cluster? We are CPU usage in our cluster going through the roof.

    ReplyDelete
    Replies
    1. No, I'm actually running this script from my machine. I wonder what taking your CPU. Is it the script ?

      Delete

Post a Comment

Thank you for your message, it has been sent to the moderator for review...

What's hot ?

Raspberry Pi : WiFi Hotspot for the Garden!

ShredOS : HDD degaussing with style

Wallbox : Get The Most Of It (with API)