forked from huntergdavis/CloudScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-server-rackspace.sh
executable file
·87 lines (70 loc) · 2.75 KB
/
create-server-rackspace.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
while getopts "n:h:d:r:k:" opt;
do
case $opt in
n) hostname=$OPTARG ;;
d) SERVER_SIZE=$OPTARG ;;
r) IMAGE_NAME=$OPTARG ;;
k) PUBLIC_KEY=$OPTARG ;;
h) echo "Usage: create-server-rackspace -n SERVERNAME -k security_key_name (optional -d 'size' parameter maps to rackspace size option, optional -r 'image instance name')"; exit 1 ;;
*) echo "Usage: create-server-rackspace -n SERVERNAME -k security_key_name (optional -d 'size' parameter maps to rackspace size option, optional -r 'image instance name')"; exit 1 ;;
esac
done
if [ -z $hostname ];
then
echo "Must have a hostname set!"
exit 0;
fi
# we must now log into rackspace and create a server
# we use the rscurl controller script for this
# it requires us to have RACKSPACE_USERNAME and RACKSPACE_API_KEY environment variables set
echo "Logging into Rackspace using environment variables"
echo "To change this, you will need to replace the RACKSPACE_USERNAME and RACKSPACE_API_KEY env variables"
if [ -z "$RACKSPACE_USERNAME" ];
then
echo "Must have set RACKSPACE_USERNAME env variable"
exit 0;
fi
if [ -z "$RACKSPACE_API_KEY" ];
then
echo "Must have set RACKSPACE_API_KEY env variable"
exit 0;
fi
# uncomment to test if aws is working
#./rscurl.sh -a $RACKSPACE_API_KEY -u $RACKSPACE_USERNAME -c list-flavors
if [ -z "$SERVER_SIZE" ];
then
echo "Defaulting to default rackspace server size 4 (2048)"
SERVER_SIZE_ARGUMENT=4;
else
SERVER_SIZE_ARGUMENT=$SERVER_SIZE;
fi
if [ -z "$IMAGE_NAME" ];
then
echo "Defaulting to default rackspace instance of 118 (centos 32-bit linux)"
RACKSPACE_INSTANCE_ARGUMENT=118;
else
RACKSPACE_INSTANCE_ARGUMENT=$IMAGE_NAME;
fi
# have rackspace create a new server instance
echo "Create Server Instance $hostname"
SERVER_CREATED=`./rscurl.sh -a $RACKSPACE_API_KEY -u $RACKSPACE_USERNAME -c create-server -i $RACKSPACE_INSTANCE_ARGUMENT -f $SERVER_SIZE_ARGUMENT -n $hostname`
#list the server and make sure it's connecting using the servername key we passed in
if [ -z "$SERVER_CREATED" ];
then
echo "Problem With Server Creation";
echo "Server not Created on rackspace";
echo "Log Into Rackspace Console and Debug!";
echo "Rackspace ERROR, Not Created"
exit 0;
fi
# use AWK to pull out the new server password
export SERVERNAME=`echo $SERVER_CREATED | awk '{print $20}' | tr -d '[\" \"]'`
export SERVERPASS=`echo $SERVER_CREATED | awk '{print $19}' | tr -d '\" \"'`
# sleep for 5 seconds to let the ip address proliferate
echo "pinging till server is finished building, please be very patient"
while true; do ping -c 1 $SERVERNAME > /dev/null && break ; done
# print the server name for the script
echo "IP: $SERVERNAME PASS: $SERVERPASS"
#exit 1;
# secure the server
./secure-server-rackspace.sh -s $SERVERNAME -p $SERVERPASS -k $PUBLIC_KEY