diff options
author | varac <varacanero@zeromail.org> | 2013-06-20 01:47:31 +0200 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2013-06-20 01:47:31 +0200 |
commit | 19a4caf006c1dc49605380b668344848b60f146d (patch) | |
tree | 17bd2d51ba308be74f09554a39756de48ce91a9b | |
parent | 5cbf9966db3e3d1390fa3cbea50dd73dbd8028c4 (diff) |
added script for reverting an instance from a snapshot, first version
-rw-r--r-- | example/revert_instance_from_snapshot.log | 34 | ||||
-rwxr-xr-x | revert_instance_from_snapshot.sh | 90 |
2 files changed, 124 insertions, 0 deletions
diff --git a/example/revert_instance_from_snapshot.log b/example/revert_instance_from_snapshot.log new file mode 100644 index 0000000..b1bf7ff --- /dev/null +++ b/example/revert_instance_from_snapshot.log @@ -0,0 +1,34 @@ +time ./revert_instance_from_snapshot.sh -i snapshot_test -s snap1 + +Querying snapshot_test... +Floating IPs: 192.168.11.7 192.168.11.8 +Removing floating ip 192.168.11.7 from snapshot_test +Re-allocating 192.168.11.7 to the floating-ip pool ++--------------+-------------+----------+------+ +| Ip | Instance Id | Fixed Ip | Pool | ++--------------+-------------+----------+------+ +| 192.168.11.7 | None | None | nova | ++--------------+-------------+----------+------+ +Removing floating ip 192.168.11.8 from snapshot_test +Re-allocating 192.168.11.8 to the floating-ip pool ++--------------+-------------+----------+------+ +| Ip | Instance Id | Fixed Ip | Pool | ++--------------+-------------+----------+------+ +| 192.168.11.8 | None | None | nova | ++--------------+-------------+----------+------+ +deleting snapshot_test +booting snapshot_test from snapshot +New ID for instance snapshot_test: 61722460-b18c-47dd-b20c-65bb62c01341 +Adding floating ip 192.168.11.7 to 61722460-b18c-47dd-b20c-65bb62c01341 +Adding floating ip 192.168.11.8 to 61722460-b18c-47dd-b20c-65bb62c01341 ++--------------------------------------+---------------+--------+--------------------------------------------------+ +| ID | Name | Status | Networks | ++--------------------------------------+---------------+--------+--------------------------------------------------+ +| 61722460-b18c-47dd-b20c-65bb62c01341 | snapshot_test | BUILD | private=192.168.10.2, 192.168.11.7, 192.168.11.8 | +| c522f43d-f9da-422e-bd53-821a1595fb28 | snapshot_test | ACTIVE | private=192.168.10.2 | ++--------------------------------------+---------------+--------+--------------------------------------------------+ + +Hang on and wait for the new instance (ID 61722460-b18c-47dd-b20c-65bb62c01341) to finish building before you try to login ! + +./revert_instance_from_snapshot.sh -i snapshot_test -s snap1 4.16s user 0.93s system 12% cpu 42.394 total + diff --git a/revert_instance_from_snapshot.sh b/revert_instance_from_snapshot.sh new file mode 100755 index 0000000..b8beb3e --- /dev/null +++ b/revert_instance_from_snapshot.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +flavor='m1.small' +secgroup='Bitmask' +keyname='varac' + + +usage() +{ +cat << EOF +usage: $0 options + +This script reverts an openstack instance to it's snapshot. + +OPTIONS: + -h Show this message + -i <instance> + -s <snapshot> + -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 --key_name $keyname $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 !" + |