Skip to content

Instantly share code, notes, and snippets.

@freyes
Last active August 29, 2015 14:05
Show Gist options
  • Save freyes/7585042130dec5923044 to your computer and use it in GitHub Desktop.
Save freyes/7585042130dec5923044 to your computer and use it in GitHub Desktop.
Pause/unpause all the virtual machines in a OpenStack cloud
#!/bin/bash
#
# Usage:
# ./os-nova-pause.sh pause
#
# Note: remember to define the environment variables used by the openstack clients
# typically this is done sourcing a 'openrc' file (you can download it from horizon)
#
function mod_server {
local tenant_id="$1"
local server_id="$2"
local op="$3"
local nova_opts=""
if [ -n "$tenant_id" ]; then
nova_opts="--os-tenant-id $1"
fi
nova $nova_opts $op $server_id
return $?
}
operation="${1:-pause}"
echo "Going to $operation ALL the virtual machines"
for tenant_id in $(keystone tenant-list | grep -v ' service ' | tail -n +4 | head -n -1 | cut -d'|' -f2); do
for server_id in $(nova --os-tenant-id "$tenant_id" list | grep -v PAUSED | tail -n +4 | head -n -1 | cut -d'|' -f2); do
echo -n "$operation $server_id (tenant $tenant_id)..."
mod_server $tenant_id $server_id $operation
if [ "$?" == "0" ]; then
echo "done"
else
echo "ERROR"
exit 1
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment