Solved

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

  • 1 August 2021
  • 3 replies
  • 1645 views

Badge +1

Hi!

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?

 

Thanks

icon

Best answer by Nupur.Sakhalkar 18 August 2021, 21:14

View original

This topic has been closed for comments

3 replies

Userlevel 3
Badge +5

@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

 

Userlevel 3
Badge +5

@pkjarora You can use this command instead to forcefully say yes for deleting each VM listed in the /tmp/vms_to_delete file instead of it asking for confirmation on deleting each VM:

for i in $(cat /tmp/vms_to_delete); do echo $i && (echo yes | acli vm.delete $i); done

 

@Nupur.Sakhalkar do we have an option, where it will not even ask for confirmation before deleting each vm?