Created
March 16, 2012 06:21
-
-
Save sleepsonthefloor/2048763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# we will use the ``euca2ools`` cli tool that wraps the python boto | |
# library to test ec2 compatibility | |
echo "**************************************************" | |
echo "Begin DevStack Exercise: $0" | |
echo "**************************************************" | |
# This script exits on an error so that errors don't compound and you see | |
# only the first error that occured. | |
set -o errexit | |
# Print the commands being run so that we can see the command that triggers | |
# an error. It is also useful for following allowing as the install occurs. | |
set -o xtrace | |
# Settings | |
# ======== | |
# Settings | |
# ======== | |
# Keep track of the current directory | |
EXERCISE_DIR=$(cd $(dirname "$0") && pwd) | |
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) | |
# Import common functions | |
source $TOP_DIR/functions | |
# Import EC2 configuration | |
source $TOP_DIR/eucarc | |
# Import exercise configuration | |
source $TOP_DIR/exerciserc | |
# Instance type to create | |
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny} | |
# Find a machine image to boot | |
IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1` | |
# Define secgroup | |
SECGROUP=euca_secgroup | |
# Add a secgroup | |
if ! euca-describe-groups | grep -q $SECGROUP; then | |
euca-add-group -d "$SECGROUP description" $SECGROUP | |
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then | |
echo "Security group not created" | |
exit 1 | |
fi | |
fi | |
# Launch it | |
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2` | |
die_if_not_set INSTANCE "Failure launching instance" | |
INSTANCE2=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2` | |
die_if_not_set INSTANCE "Failure launching instance" | |
sleep 10 | |
euca-terminate-instances $INSTANCE $INSTANCE2 | |
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2` | |
die_if_not_set INSTANCE "Failure launching instance" | |
INSTANCE2=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2` | |
die_if_not_set INSTANCE "Failure launching instance" | |
sleep 10 | |
euca-terminate-instances $INSTANCE $INSTANCE2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment