Jesse Andrews | f670549 | 2011-11-01 16:04:14 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **exercise.sh** - using the cloud can be fun |
| 4 | |
| 5 | # we will use the ``nova`` cli tool provided by the ``python-novaclient`` |
| 6 | # package |
| 7 | # |
| 8 | |
| 9 | |
| 10 | # This script exits on an error so that errors don't compound and you see |
| 11 | # only the first error that occured. |
| 12 | set -o errexit |
| 13 | |
| 14 | # Print the commands being run so that we can see the command that triggers |
| 15 | # an error. It is also useful for following allowing as the install occurs. |
| 16 | set -o xtrace |
| 17 | |
| 18 | |
| 19 | # Settings |
| 20 | # ======== |
| 21 | |
| 22 | # Use openrc + stackrc + localrc for settings |
| 23 | source ./openrc |
| 24 | |
| 25 | # Max time till the vm is bootable |
| 26 | BOOT_TIMEOUT=${BOOT_TIMEOUT:-15} |
| 27 | |
| 28 | IMAGE=`euca-describe-images | grep machine | cut -f2` |
| 29 | |
| 30 | INSTANCE=`euca-run-instance $IMAGE | grep INSTANCE | cut -f2` |
| 31 | |
| 32 | if ! timeout $BOOT_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then |
| 33 | echo "server didn't become active within $BOOT_TIMEOUT seconds" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | euca-terminate-instances $INSTANCE |