Nutanix SSH Scripts

During my work I do a lot of cvm oneliners to get things done easier and faster. Hereby a list of script to make life easier 😉 If you got some additions to the list, post it in the comments.

In some lines there is a Prefix-Filter. This is the “FIRSTPARTOFVMNAME” part. Change it to what is needed. All scripts/oneliners are performed in a CVM. So SSH into it and run it.

Spaces in virtual machine names are no fun 😉 Please try to avoid those, this can lead to scripts not working correctly.

There are a couple of command line tools to use for your scripts:

  • ACLI: Used for virtual machine management;
  • NCLI: Used for cluster management;
  • ECLI: Used for task management;
  • HOSTSSH: Used to execute commands on all the Hypervisors;
  • ALLSSH: Used to execute commands on all the CVM’s.

When we do an acli vm.list we get a list like this:

As you can see in the screenshot there first line is “VM name VM UUID”. When we are not filtering with a name-prefix this line will also be parsed into the command. So keep this in mind. 😉 When we add the name filtering (grep -i ^’FIRSTPARTOFVMNAME’) then the output is shown like this (column names are gone):

Lets explain the first oneliner in this post. It is: for vm_name in `acli vm.list power_state=on | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.off $vm_name; done

What it does is an “acli vm.list power_state=on | grep -i ^’Windows’. This will list all virtual machines which are powered on and the name starts with Windows.

As you can see in the screenshot we also see the ID of the virtual machine. We are only interested in the VM name so we need to filter to only the first column: acli vm.list power_state=on | grep -i ^’Windows’ | awk ‘{print $1}’

In the screenshot you see the problem with spaces in a virtual machine name. Please try to avoid that 😉

Now that we have the list with vm names we need to store them in a variable and parse that in a command. This is done with the for command.

for <variable_name> in `the command to get the virtual machine names`; do <command what to do with the machines use the $variable_name>; done

So to shutdown all running virtual machines which are starting with a particular name the oneliner will be:

All vm’s hard off:

With name-prefix filter: for vm_name in `acli vm.list power_state=on | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.off $vm_name; done


Without name-prefix filter: for vm_name in `acli vm.list power_state=on | awk '{print $1}'`; do acli vm.off $vm_name; done

All vm’s guest shutdown:
With name-prefix filter: for vm_name in `acli vm.list power_state=on | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.shutdown $vm_name; done


Without name-prefix filter: for vm_name in `acli vm.list power_state=on | awk '{print $1}'`; do acli vm.shutdown $vm_name; done

All VM’s on:
With name-prefix filter: for vm_name in `acli vm.list power_state=off | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.on $vm_name; done


Without name-prefix filter: for vm_name in `acli vm.list power_state=off | awk '{print $1}'`; do acli vm.on $vm_name; done

Remove vGPU from VM’s:

(Nvidia_GRID_M10-2q is the vGPU profile to be removed)

for vm_name in `acli vm.list | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.gpu_deassign $vm_name gpu=Nvidia_GRID_M10-2Q; done

Add vGPU to VM’s:

(Nvidia_GRID_M10-2q is the vGPU profile to be added)
for vm_name in `acli vm.list | grep -i ^'FIRSTPARTOFVMNAME' | awk '{print $1}'`; do acli vm.gpu_assign $vm_name gpu=Nvidia_GRID_M10-2Q; done

Remove all VM’s starting with “Nutanix-Clone-“:
for vm_name in `acli vm.list | grep -i ^'Nutanix-Clone-' | awk '{print $1}'` ; do acli -y vm.delete $vm_name delete_snapshots="true" ; done

List all VM’s with a CD/DVD mounted:
for vm_name in `acli vm.list | cut -d " " -f 1`; do if [ -n "`acli vm.get $vm_name | grep -A1 cdrom | grep container`" ] ; then echo $vm_name ; fi ; done

List all VM’s with an affinity rule and the hosts attached to:
for vm_name in `acli vm.list | cut -d " " -f 1`; do if [ -n "`acli vm.get $vm_name | grep affinity`" ] ; then echo $vm_name ; acli vm.get $vm_name | grep host_uuids ; fi ; done

List all VM’s marked as agent VM’s:

for vm_name in `acli vm.list |cut -d " " -f 1`; do if [ -n "`acli vm.get $vm_name | grep agent`" ] ; then echo $vm_name ; fi ; done

List all VM’s their mac-addresses:
for vm_name in $(acli vm.list | awk -F' {2,}' 'NR-1 {print $1}') ; do echo $vm_name ; acli vm.get $vm_name | grep mac_addr ; done

Start full curator scan:
for svm in `svmips`; do wget -O - "http://$svm:2010/master/api/client/StartCuratorTasks?task_type=2"; done

Start partial curator scan:
for svm in `svmips`; do wget -O - "http://$svm:2010/master/api/client/StartCuratorTasks?task_type=3"; done

Change the root password of iDrac for Dell nodes:

hostssh sudo ipmitool user set password 2 <new_password>

Abort all running tasks (Use with care):

for tasks in $(ecli task.list include_completed=false | awk '{print $1}'); do echo y | ~/bin/ergon_update_task --task_status=aborted --task_uuid=$tasks; done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top