#!/bin/bash # # following prerequisites are needed # - all keys must be present to current user (use add_keys script to import) flavor='testing' secgroup='Bitmask' keys='--key_name varac --key_name drebs --key_name kwadronaut --key_name micah --key_name elijah' usage() { cat << EOF usage: $0 options This script reverts an openstack instance to it's snapshot. OPTIONS: -h Show this message -i -s -v verbose mode EOF } set -- $(getopt hi:s:v "$@") while [ $# -gt 0 ] do case "$1" in (-h) usage; exit 1 ;; (-i) instance="$2"; shift;; (-s) snapshot="$2"; shift;; (--) shift; break;; (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; (*) break;; esac shift done if [[ -z $instance ]] || [[ -z $snapshot ]] then usage exit 1 fi echo "Querying $instance..." ips=`nova show --minimal $instance | grep 'private network'| cut -f 3 -d'|'` # 192.168.10.2, 192.168.11.7, 192.168.11.9 float_ips=`echo "$ips"| cut -f 2- -d',' | sed 's/,/ /g'` # 192.168.11.7 192.168.11.9 echo "Floating IPs: $float_ips" for ip in $float_ips do echo "Removing floating ip $ip from $instance" nova floating-ip-delete $ip # will re-allocate the removed ip in the pool echo "Re-allocating $ip to the floating-ip pool" nova floating-ip-create > /dev/null done echo echo "Deleting $instance" nova delete $instance echo echo "Booting $instance from snapshot $snap" result=`nova boot --image $snapshot --flavor $flavor --security-groups $secgroup $keys $instance` # unfortunatly unformatted #echo $result newid=`echo "$result" | grep '| id ' | cut -d '|' -f 3 | sed 's/ //g' ` echo echo "New ID for instance $instance: $newid" for ip in $float_ips do echo "Adding floating ip $ip to $newid" nova add-floating-ip $newid $ip done nova list echo echo "Hang on and wait for the new instance (ID $newid) to finish building before you try to login !"