-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfootlocker-bootstrap.sh
executable file
·196 lines (160 loc) · 7.55 KB
/
footlocker-bootstrap.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
#mass footlocker bootstrap - arbitrary hosts and providers
#jim@gonkulator.io 10/20/2015
#define functions
usage()
{
echo ""
echo "Usage: $0 provider instances"
echo "e.g., $0 aws 3"
echo "This would build a total of three nodes on AWS. One build node and two footlocker hosts for cnvm's"
echo ""
echo "See https://github.com/gonkulator/cnvm for spceifics on configuration for each provider"
echo ""
echo "Valid provider values are:"
echo "aws - Amazon Web Services"
echo "azure - Microsoft Azure"
echo "digital_ocean - Digital Ocean"
echo "google - Google Compute Engine"
echo "virtualbox - Oracle VirtualBox"
echo "vmware_fusion - VMWare Fusion [requires addl vagrant license]"
echo "vmware_workstation - VMWare Workstation [requires addl vagrant license]"
echo ""
echo "You can also execute: $0 hybrid-demo virtualbox [aws|digital_ocean|azure|vmware_fusion|vmware_workstation|google]"
echo "This will create 3 nodes, two on virtualbox and a third on the provider of your choice to show inter-cloud/hypervisor capabilities!"
echo "See https://github.com/gonkulator/cnvm for details!"
exit 1
}
ssh_master_command()
#arg is $1 which is simply what to excute remote side - figuring out all all of the
#necessary port information etc by poking vagrant
{
ssh -p ${masterport} -i ${mastersshkey} ${masteruser}@${masterip} -o LogLevel=FATAL -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes $*
}
scp_master_command()
#arg is $1 which is simply what to excute remote side - figuring out all all of the
#necessary port information etc by poking vagrant
{
scp -P ${masterport} -i ${mastersshkey} -o LogLevel=FATAL -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes $*
}
ssh_node_command()
{
ssh -p ${targetport} -i ${targetkey} ${targetuser}@${targetip} -o LogLevel=FATAL -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes $*
}
scp_node_command()
{
scp -P ${targetport} -i ${targetkey} -o LogLevel=FATAL -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes $*
}
get_host_type()
{
export NODETYPE=$(vagrant status $1 | grep $1 | awk '{print $3}' | tr -d '()')
}
get_host_ssh_info()
{
hostip=$(cat sshconfigs/$1-sshconfig | grep HostName | awk '{print $2}')
hostuser=$(cat sshconfigs/$1-sshconfig | grep User\ | awk '{print $2}')
hostsshkey=$(cat sshconfigs/$1-sshconfig | grep IdentityFile | awk '{print $2}')
hostport=$(cat sshconfigs/$1-sshconfig | grep Port\ | awk '{print $2}')
}
get_host_ip()
{
cat sshconfigs/$1-sshconfig | grep HostName | awk '{print $2}'
}
get_host_ip_virtualbox()
{
VboxManage guestproperty get $(cat .vagrant/machines/$1/virtualbox/id) /VirtualBox/GuestInfo/Net/1/V4/IP | sed s/Value:\ //g
}
#main
if [ $# -lt 2 ]; then
if [ "$1" == "hybrid-demo" ]; then
:
else
usage
exit 1
fi
fi
#export NUM_FOOTLOCKERS=$2
#zero the host state files
touch thehosts
touch therunninghosts
>thehosts
>therunninghosts
#if we are running the split hybrid demo - create two local virtualbox instances and a third instance of provider type $3 - also do contextual reloads
if [ $1 = "hybrid-demo" ] ; then
vagrant up cnvm-host-00 --provider=$2
# export providertype=$2 && vagrant reload cnvm-host-00
vagrant up cnvm-host-01 --provider=$2
# export providertype=$2 && vagrant reload cnvm-host-01
vagrant up cnvm-host-02 --provider=$3
# export providertype=$3 && vagrant reload cnvm-host-02
else
export NUM_FOOTLOCKERS=$2
vagrant up --provider=$1 && export providertype=$1
# vagrant reload
fi
#mkdir the sshconfigs dir and dump all the ssh-config info into it
mkdir -p sshconfigs
for i in $(cat therunninghosts) ; do
vagrant ssh-config ${i} > sshconfigs/${i}-sshconfig
done
#vagrant ssh-config cnvm-host-00 > sshconfigs/cnvm-host-00-sshconfig
masterip=$(cat sshconfigs/cnvm-host-00-sshconfig | grep HostName | awk '{print $2}')
masteruser=$(cat sshconfigs/cnvm-host-00-sshconfig | grep User\ | awk '{print $2}')
mastersshkey=$(cat sshconfigs/cnvm-host-00-sshconfig | grep IdentityFile | awk '{print $2}')
masterport=$(cat sshconfigs/cnvm-host-00-sshconfig | grep Port\ | awk '{print $2}')
#setup the master node, get its ssh keys and copy them local to workstation
ssh-keyscan -p ${masterport} -t rsa ${masterip} >> ~/.ssh/known_hosts
ssh_master_command 'sudo cp id_rsa* /root/.ssh && sudo chown root /root/.ssh/id_rsa && sudo chown root /root/.ssh/id_rsa.pub'
scp_master_command ${masteruser}@${masterip}:./id_rsa* ./thekeys
echo "Retrieved cnvm-host-00 ssh-keys"
#define the target nodes (all that are not cnvm-host-00 - which is the build node)
targetnodes=($(cat therunninghosts | grep -v cnvm-host-00))
#create an array of nodes to be built/manipulated and copy the build-nodes root key to each of them and put it in ~root/.ssh/authorized_keys
echo "Target nodes are: ${targetnodes[@]}"
for i in ${targetnodes[@]}; do
targetip=$(cat sshconfigs/$i-sshconfig | grep HostName | awk '{print $2}')
targetuser=$(cat sshconfigs/$i-sshconfig | grep User\ | awk '{print $2}')
targetkey=$(cat sshconfigs/$i-sshconfig | grep IdentityFile | awk '{print $2}')
targetport=$(cat sshconfigs/$i-sshconfig | grep Port\ | awk '{print $2}')
echo "Connecting to $i to do the key needful..."
ssh-keyscan -p ${targetport} -t rsa ${targetip} >> ~/.ssh/known_hosts
ssh_node_command mkdir nodekeys
scp_node_command ./thekeys/* ${targetuser}@${targetip}:./nodekeys
ssh_node_command 'sudo ~/nodekeys/keyupdate.sh'
done
#build a list of targets to go ssh-keyscan based on dumping vagrant ssh-config for each node into the sshconfigs directory
keyscantargets=$(cd ./sshconfigs && for i in $(ls) ; do cat $i | grep HostName\ | awk '{print $2}' ;done | xargs)
for i in ${targetnodes[@]}; do
targetip=$(cat sshconfigs/$i-sshconfig | grep HostName | awk '{print $2}')
targetuser=$(cat sshconfigs/$i-sshconfig | grep User\ | awk '{print $2}')
targetkey=$(cat sshconfigs/$i-sshconfig | grep IdentityFile | awk '{print $2}')
targetport=$(cat sshconfigs/$i-sshconfig | grep Port\ | awk '{print $2}')
ssh_node_command "sudo ~/nodekeys/keyscanner.sh ${keyscantargets}"
done
#copy up the keyupdate and keyscanner scripts to the master node and keyscan each of the build targets
echo "Keyscanning master to targets..."
scp_master_command thekeys/*.sh ${masteruser}@${masterip}:.
ssh_master_command "sudo ~/keyscanner.sh ${keyscantargets}"
#build the list of footlocker targets to be built based off of parsing the ssh-configs
echo "Kicking off Cloud Native VM footlocker builds..."
#virtualbox is special - so get the private network ip's of the arbitrary nodes using vboxmanage and plug them in here otherwise carry on...
#BUILDNODETYPE=$(get_host_type cnvm-host-00)
targetnodeips=($(for i in ${targetnodes[@]}; do get_host_type ${i} ; if [ "$NODETYPE" == virtualbox ] ; then get_host_ip_virtualbox ${i} ; else get_host_ip ${i} ; fi ; done))
footlockertargets=$(echo ${targetnodeips[@]} | sed s/\ /,/g)
#ssh into the build node and pull the ansible container that will bootstrap all the footlocker hosts
echo "Pulling build container...."
ssh_master_command "docker pull stlalpha/theansible"
echo "Building...."
#ssh into the build node and execute the ansible container with the NODES arg set to the footlocker targets list yoiu built above
ssh_master_command "sudo docker run -v /root/.ssh/id_rsa:/keys/priv -v /root/.ssh/id_rsa.pub:/keys/pub -e NODES=${footlockertargets} stlalpha/theansible"
#cleanup - unless you set debug then leave the logs laying around so you can figure out whats going on
if [ "$3" != "debug" ] ; then
echo "Cleaning up..."
rm sshconfigs/*
rm thekeys/id_rsa*
rm thehosts
rm therunninghosts
echo "Done."
else
echo "done"
fi