Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 3 | # we will use the ``euca2ools`` cli tool that wraps the python boto |
Jesse Andrews | 9f18634 | 2011-11-01 16:05:40 -0700 | [diff] [blame] | 4 | # library to test ec2 compatibility |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 5 | # |
| 6 | |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 7 | # This script exits on an error so that errors don't compound and you see |
| 8 | # only the first error that occured. |
| 9 | set -o errexit |
| 10 | |
| 11 | # Print the commands being run so that we can see the command that triggers |
| 12 | # an error. It is also useful for following allowing as the install occurs. |
| 13 | set -o xtrace |
| 14 | |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 15 | # Settings |
| 16 | # ======== |
| 17 | |
| 18 | # Use openrc + stackrc + localrc for settings |
Jesse Andrews | 787af01 | 2011-11-01 16:44:19 -0700 | [diff] [blame] | 19 | pushd $(cd $(dirname "$0")/.. && pwd) |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 20 | source ./openrc |
Jesse Andrews | 787af01 | 2011-11-01 16:44:19 -0700 | [diff] [blame] | 21 | popd |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 22 | |
Anthony Young | abda427 | 2011-12-16 20:16:20 +0000 | [diff] [blame] | 23 | # Find a machine image to boot |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 24 | IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1` |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 25 | |
Anthony Young | abda427 | 2011-12-16 20:16:20 +0000 | [diff] [blame] | 26 | # Define secgroup |
| 27 | SECGROUP=euca_secgroup |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 28 | |
Anthony Young | abda427 | 2011-12-16 20:16:20 +0000 | [diff] [blame] | 29 | # Add a secgroup |
| 30 | euca-add-group -d description $SECGROUP |
| 31 | |
| 32 | # Launch it |
| 33 | INSTANCE=`euca-run-instances -g $SECGROUP -t m1.tiny $IMAGE | grep INSTANCE | cut -f2` |
| 34 | |
| 35 | # Assure it has booted within a reasonable time |
Todd Willey | 9a3066f | 2011-11-05 11:02:34 -0400 | [diff] [blame] | 36 | if ! timeout $RUNNING_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then |
| 37 | echo "server didn't become active within $RUNNING_TIMEOUT seconds" |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 38 | exit 1 |
| 39 | fi |
| 40 | |
Anthony Young | abda427 | 2011-12-16 20:16:20 +0000 | [diff] [blame] | 41 | # Allocate floating address |
| 42 | FLOATING_IP=`euca-allocate-address | cut -f2` |
| 43 | |
| 44 | # Release floating address |
| 45 | euca-associate-address -i $INSTANCE $FLOATING_IP |
| 46 | |
| 47 | |
| 48 | # Authorize pinging |
| 49 | euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP |
| 50 | |
| 51 | # Max time till the vm is bootable |
| 52 | BOOT_TIMEOUT=${BOOT_TIMEOUT:-15} |
| 53 | if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then |
| 54 | echo "Couldn't ping server" |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
| 58 | # Revoke pinging |
| 59 | euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP |
| 60 | |
| 61 | # Delete group |
| 62 | euca-delete-group $SECGROUP |
| 63 | |
| 64 | # Release floating address |
| 65 | euca-disassociate-address $FLOATING_IP |
| 66 | |
| 67 | # Release floating address |
| 68 | euca-release-address $FLOATING_IP |
| 69 | |
| 70 | # Terminate instance |
Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame] | 71 | euca-terminate-instances $INSTANCE |