Last active
December 7, 2015 10:53
-
-
Save mberglof/b259021daab2d5135a2e to your computer and use it in GitHub Desktop.
Creates server in RS and updates Route53
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
#!/bin/bash | |
DOMAIN=${1#*.} | |
SERVER=${1%%.*} | |
CPU=${2} | |
CENTOS=${CENTOS:=6} | |
if [[ $# -lt 2 ]]; then | |
echo -e "Usage:\t$(basename $0) <fqdn> <nr. cpus>" | |
echo -e "Example: \"CENTOS=7 $(basename $0) foo-01.example.com 4\"" | |
echo -e "This will create a CentOS 7 performance1-4 server with 4vCPU and 4GB RAM" | |
exit 1 | |
fi | |
function wait_rackconnect { | |
echo -n "Rackconnect not ready.." | |
rack servers instance get --name ${SERVER}.${DOMAIN} | grep rackconnect_automation_feature_provison_public_ip | grep ENABLED > /dev/null 2>&1 | |
READY=$? | |
until [ ${READY} -eq 0 ]; do | |
echo -n "." | |
sleep 30 | |
rack servers instance get --name ${SERVER}.${DOMAIN} | grep rackconnect_automation_feature_provison_public_ip | grep ENABLED > /dev/null 2>&1 | |
READY=$? | |
done | |
} | |
function update_dns () { | |
AWSCMD="route53 -z ${DOMAIN} -c --type A --values $(rack servers instance get --name ${SERVER}.${DOMAIN} --fields publicipv4 | awk '{print $2}') --name ${SERVER}.${DOMAIN} --ttl 300 --no-wait" | |
echo ${AWSCMD} | |
${AWSCMD} | |
} | |
case $CENTOS in | |
6) | |
CENTOS_IMAGE=fabe045f-43f8-4991-9e6c-5cabd617538c | |
;; | |
7) | |
CENTOS_IMAGE=6595f1b7-e825-4bd2-addc-c7b1c803a37f | |
;; | |
*) | |
echo "Valid \$CENTOS values are 6 or 7" | |
exit 1 | |
;; | |
esac | |
case $CPU in | |
1|2|4|8) | |
FLAVOR=performance1-${CPU} | |
;; | |
15|30|60|90|120) | |
FLAVOR=performance2-${CPU} | |
;; | |
*) | |
echo "Valid values are" | |
echo "1|2|4|8 for performance1" | |
echo "15|30|60|90|120 for performance2" | |
exit 1 | |
;; | |
esac | |
case $DOMAIN in | |
fcuat.co.uk) | |
KEYPAIR="UAT" | |
;; | |
fundingcircle.co.uk) | |
KEYPAIR="marcus" | |
;; | |
*) | |
echo "verify your domain name: ${DOMAIN}" | |
exit 1 | |
;; | |
esac | |
#echo Domain: ${DOMAIN}, Server: ${SERVER} | |
RSCMD="rack servers instance create --name ${SERVER}.${DOMAIN} --image-id ${CENTOS_IMAGE} --flavor-id ${FLAVOR} --keypair ${KEYPAIR}" | |
echo ${RSCMD} | |
${RSCMD} | |
wait_rackconnect | |
update_dns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment