Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

acropolis CLI to shutdown all vms currently on

SOLVED Go to solution
Adventurer

acropolis CLI to shutdown all vms currently on

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 Smiley Happy

 

thx, Brent

 

1 ACCEPTED SOLUTION

Accepted Solutions
Adventurer

Re: acropolis CLI to shutdown all vms currently on

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

1 REPLY
Adventurer

Re: acropolis CLI to shutdown all vms currently on

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