Solved

acropolis CLI to shutdown all vms currently on


Userlevel 1
Badge +6
Hi All, I am trying to write a one (or few) liner to shutdown all non CVM vms found on the cluster. (AHV)

I know 'acli vm.list power_state=on' returns a list of vms across the cluster.... and I know i can do an 'acli vm.force_off [VM Name]' to shut those down.

Is there a bash script ninja out there that could help me write a one liner loop to take all VM names found in the first output, with the second command?

I'll keep on trying, maybe i have command-line haze happening and just need a break 🙂

thx, Brent
icon

Best answer by BrentHysop 11 April 2017, 19:24

Woohoo. replying to myself, just to update the community with the solution. As my colleauge often says, my problem was a loose nut at the keyboard.

Heres the one liner:

for vm_name in `acli vm.list power_state=on | grep -v ^'VM name' | awk '{print $1}'`; do acli vm.force_off $vm_name; done

hope someone finds that helpful. when you are scripting nutanix cluster shutdowns, the 'echo y | cluster stop' command will fail if there are running guest vms, so this is part of the forcing the cluster down, somewhat gracefully.

thx, Brent

View original

This topic has been closed for comments

4 replies

Userlevel 1
Badge +6
Woohoo. replying to myself, just to update the community with the solution. As my colleauge often says, my problem was a loose nut at the keyboard.

Heres the one liner:

for vm_name in `acli vm.list power_state=on | grep -v ^'VM name' | awk '{print $1}'`; do acli vm.force_off $vm_name; done

hope someone finds that helpful. when you are scripting nutanix cluster shutdowns, the 'echo y | cluster stop' command will fail if there are running guest vms, so this is part of the forcing the cluster down, somewhat gracefully.

thx, Brent
Userlevel 3
Badge +16
Hey @BrentHysop ! This is gold! Thanks! So... This listed out my VM's, but only until it hit a space. It didn't recognize when it went to shut down. Doh! Defeated by spaces, again.
Userlevel 7
Badge +35
Thanks for sharing @BrentHysop - big help for the community! 👍
Hi all,

here my script.

for vm_name in `acli vm.list power_state=on | grep -v ^'VM name' | awk '{print $1}'`; do acli vm.shutdown $vm_name; done

i change acli command from acli vm.force_off to acli vm,shutdown

this command will excute safely shutdown

base on acli parameter:
  • Initiates a Guest level Reboot of the VMs :
code:
vm.guest_reboot
  • Initiates a Guest level Shutdown of the VMs :
code:
vm.guest_shutdown
  • Force VM into the powered off state :
code:
vm.force_off
  • Lists all VMs :
code:
vm.list
  • Powers off the specified VMs :
code:
vm.off
  • Powers on the specified VMs :
code:
vm.on
  • Power cycles the specified VMs :
code:
vm.power_cycle
  • Initiates a reboot by issuing an ACPI event :
code:
vm.reboot
  • Resets the specified VMs :
code:
vm.reset
  • Initiates a shutdown by issuing an ACPI event :
code:
vm.shutdown


Best Regards