#!/bin/bash ###enumerate uuid's of all _running_ VMs in the pool for VM in `xe vm-list is-control-domain=false power-state=running params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"` do ###(uncomment following line to perform actual shutdown) #xe vm-shutdown vm=$VM echo $VM > /dev/null done ###get uuid of pool master - it must be the very last to shut down MASTER_UUID=`xe pool-list params=master | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-0-9]{4}-[a-f0-9]{12}"` ###enumerate of all xen hosts in the pool except master for HOST in `xe host-list params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"` do if [ $HOST != $MASTER_UUID ] then ###(uncomment following line to perform actual shutdown) #xe host-shutdown host=$HOST echo $HOST > /dev/null fi done ###finally shutdown pool master ###(uncomment following line to perform actual shutdown) #xe host-shutdown host=$HOST