for vm_name in `acli vm.list power_state=on | grep -v ^'VM name' | awk '{print $1}'`; do acli vm.shutdown $vm_name; done
which is excellent but Im not sure how to further filter it by VM name?
Any help appreciated.
Note: Id also appreciate any help with a script that then deletes any VM and associated snapshot starting with ‘Nutanix-Clone-’ - doing 80 or so through the web console is hard work.
Thanks for you time,
Aaron
Page 1 / 1
Hey @arboundy , about the script give me some time I will try it out in one of the test clusters and get back to you with the result. In the meantime here is an Acropolis cmdline guide to perform actions on a VM. The above script also uses these commands to perform the actions on the VMs:
In this script you can specify the VM names here “grep -v ^'VM name' “, but with a different wildcard i.e ‘-v’ here is for invert matching i.e here which does not matches the given string specified in “VM name”. So this script is shutting down all the VMs other than the VMs with name ‘VM name’ specified in the argument. Also the ^ regular expression pattern specifies the start of a line. This can be used in grep to match the lines which start with the given string or pattern.
for vm_name in `acli vm.list power_state=on | grep -v ^'VM name' | awk '{print $1}'`; do acli vm.shutdown $vm_name; done
Give me some time I will experiment this in one of my lab clusters and get back to you. In the mean time you can try it out too using the Acropolis guide and the script.
Let me know if you need anything else.
Thanks @AnishWalia20 - as I am raw (literally a couple of days) I look forward to your response and sincerely appreciate your assistance.
Hey @arboundy so I tried out and experimented with the scripts and here is how you can:
Shutdown all VM’s with the name starting ‘Nutanix-Clone-” : Login to one of the CVMs on the cluster and run this script:
cvm$ for vm_name in `acli vm.list power_state=on | grep -i ^'Nutanix-Clone-' | awk '{print $1}'`; do acli vm.force_off $vm_name; done
This will power off all the VMs starting with name “Nutanix-Clone-”.
Deletes any VM starting with ‘Nutanix-Clone’:
cvm$ for vm_name in `acli vm.list power_state=off | grep -i ^'Nutanix-Clone-' | awk '{print $1}'` ; do acli vm.delete $vm_name delete_snapshots="true" ; done
In the above scenario the VMs Starting with name ‘Nutanix-Clone-’ which were in powered-off state along with their snapshots were deleted. The option “delete_snapshots=”true” deleted the snapshots associated with the VMs.
The only thing you will have to do is enter “yes” for each VM as there will be a prompt for confirmation to delete.
Let me know if you need help with anything else as I would be more that happy to help.
Hey there @arboundy , just following up, were you able to execute the above script and achieve the above?
Let me know if you had any other doubts, I would be more than happy to clear them.