Last active
August 29, 2015 14:26
-
-
Save zastari/0d4c7da2546c4a697fe3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# refresh.sh - Quickly deploy some cloud servers on which to run playbooks | |
# | |
# Requires: rackspace-cli ( http://rackspace-cli.readthedocs.org/ ) | |
# Usage: refresh.sh (create|destroy) | |
# | |
# Variables are read from this script instead of argv. Edit them until | |
# they match your environment | |
# | |
# BUG (possibly in rackspace-cli): Using --image-id with a custom image id | |
# results in an image not found error. Because of this, image names are | |
# used instead. | |
cache_file="/root/servers.list" | |
servers_to_create=2 | |
servers_name_root="hostname_" | |
servers_image_name="image_template" | |
servers_flavor="general1-1" | |
servers_ssh_key="id_rsa" | |
case $1 in | |
create) | |
if [ -f "${cache_file}" ]; then | |
echo "Server cache file, ${cache_file}, exists. If no servers are online try removing it." | |
exit 1 | |
fi | |
for i in $(seq "${servers_to_create}"); do | |
rack servers instance create --name ${servers_name_root}${i} --image-name ${servers_image_name} --flavor-id ${servers_flavor} --keypair ${servers_ssh_key} | |
done | tee >(awk '/ID/ {print $2}' > "${cache_file}") | |
;; | |
destroy) | |
if [ ! -f "${cache_file}" ]; then | |
echo "Server cache file, ${cache_file}, doesn't exist. If servers are staged you will need to delete them manually." | |
exit 1 | |
fi | |
while read servers_uuid; do | |
rack servers instance delete --id ${servers_uuid} | |
done < "${cache_file}" | |
rm -f ${cache_file} | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment