How to remove several VM at the same time on AHV cluster?

  • 1 August 2021
  • 1 reply

Badge +1


If you have several Virtual machines on an AHV cluster that must be deleted, can you delete  them at the same time from Prism Central or should you remove them one by one from Prism Element?

Also, is there any Rest API or PowerCLI to do that process?



1 reply

Userlevel 2
Badge +4

@daniel.martinez-42326 The recommended way is to do it directly via Prism Central wherein you will get an option to select multiple VMs and then perform the delete action on it.

For REST API based deletion, we have a rest API to delete a single VM using the VM UUID. So, you will need to create a script to first get the VM UUIDs (using the VM GET API call) in case if you don’t have it already and then use the VM UUIDs to delete the VMs using the VM DELETE REST API call. 

Other way to do it could be via the following process:

  1. Write a list of VM names that you want to delete into a file (each name in new line). For example File name could be - '/tmp/vms_to_delete'
  2. Run the following command from any CVM in the cluster (login as nutanix user) to delete the VMs listed in step 1 (change the filename based on the name provided in step 1):
    for i in $(cat /tmp/vms_to_delete); do echo $i && acli vm.delete $i; done
    -- It will ask you to type yes to confirm each of them, so it is quite safe