-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdemo-install.sh
400 lines (349 loc) · 12.9 KB
/
demo-install.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
root_check() {
if ! [ $(id -u) = 0 ]; then
echo "=====> this script must be run as root"
exit 1
fi
}
distro_check() {
if command -v apt-get &> /dev/null; then
pkg_mgr="apt-get"
apt-get update
elif command -v yum &> /dev/null; then
pkg_mgr="yum"
yum install -y firewalld
elif [ "$(uname)" == "Darwin" ]; then
pkg_mgr="mac"
fi
}
check_for_pip() {
if command -v pip &> /dev/null; then
echo "=====> python-pip is already installed "
else
echo "=====> python-pip is missing, installing "
if [ $pkg_mgr = "yum" ]; then
if ! yum repolist | grep epel; then
echo "=====> epel repo is required for python-pip install, installing epel "
yum install -y epel-release
fi
echo "=====> installing python-pip "
yum install -y python-pip
elif [ $pkg_mgr = "apt-get" ]; then
apt-get install -y python-pip
elif [ $pkg_mgr = "mac" ]; then
easy_install pip
fi
fi
}
check_for_dockerpy() {
if python -c "import docker" &> /dev/null; then
echo "=====> docker-py already installed"
else
echo "=====> docker-py is missing, installing"
pip install docker-py --upgrade
fi
}
check_for_avisdk() {
pip install avisdk --upgrade
}
check_for_ansible() {
if command -v ansible &> /dev/null; then
echo "=====> ansible is already installed"
currentver="$(ansible --version | grep -m 1 ansible | awk '{split($0,a,"ansible"); print a[2]}')"
requiredver="2.6.4"
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -n | head -n1)" = "$requiredver" ]; then
echo "=====> ansible version greater than 2.6.4"
else
echo "=====> ansible version less than 2.6.4"
pip install 'ansible==2.6.4' --upgrade
fi
else
echo "=====> ansible is missing, installing"
pip install 'ansible==2.6.4' --upgrade
fi
}
check_for_ansible_roles() {
if ansible-galaxy list avinetworks.docker | grep "not found" &> /dev/null; then
echo "=====> ansible avinetworks.docker role not installed"
ansible-galaxy install avinetworks.docker
else
echo "=====> ansible avinetworks.docker role already installed"
fi
if ansible-galaxy list avinetworks.avicontroller | grep "not found" &> /dev/null; then
echo "=====> ansible avinetworks.avicontroller role not installed"
ansible-galaxy install avinetworks.avicontroller
else
echo "=====> ansible avinetworks.avicontroller role already installed"
fi
if ansible-galaxy list avinetworks.avisdk | grep "not found" &> /dev/null; then
echo "=====> ansible avinetworks.avisdk role not installed"
ansible-galaxy install avinetworks.avisdk
else
echo "=====> ansible avinetworks.avisdk role already installed"
fi
if ansible-galaxy list avinetworks.aviconfig | grep "not found" &> /dev/null; then
echo "=====> ansible avinetworks.aviconfig role not installed"
ansible-galaxy install avinetworks.aviconfig
else
echo "=====> ansible avinetworks.aviconfig role already installed"
fi
}
check_for_unzip() {
if command -v unzip &> /dev/null; then
echo "=====> unzip is already installed"
else
echo "=====> unzip is missing, installing"
if [ $pkg_mgr = "yum" ]; then
yum install -y unzip
elif [ $pkg_mgr = "apt-get" ]; then
apt-get install -y unzip
fi
fi
}
check_for_curl() {
if command -v curl &> /dev/null; then
echo "=====> curl is already installed"
else
echo "=====> curl is missing, installing"
if [ $pkg_mgr = "yum" ]; then
yum install -y curl
else
apt-get install -y curl
fi
fi
}
check_for_unbuffer() {
if command -v unbuffer &> /dev/null; then
echo "=====> unbuffer is already installed"
else
echo "=====> unbuffer is missing, installing"
if [ $pkg_mgr = "yum" ]; then
yum install -y expect
else
apt-get install -y expect-dev
fi
fi
}
check_for_cleanup() {
for a in "${cmd_args[@]}"; do
if [[ "$a" == "cleanup" ]]; then
download_files
demo=$(docker inspect --format '{{ index .Config.Labels "demo"}}' avicontroller)
ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/demo_cleanup.yml
exit 0
#if [ "$demo" == "default" ]; then
# ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demo_single_host_delete.yml
# exit 0
#elif [ "$demo" == "kubernetes" ]; then
# ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demo_single_host_kubernetes_delete.yml
# exit 0
#elif [ "$demo" == "openshift" ]; then
# ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demo_single_host_openshift_delete.yml
# exit 0
#fi
fi
done
}
check_for_change_version() {
for a in "${cmd_args[@]}"; do
if [[ "$a" == "change_version" ]]; then
export AVI_VERSION_CHANGE="true"
demo=$(docker inspect --format '{{ index .Config.Labels "demo"}}' avicontroller)
retrieve_avi_versions
download_files
if [[ "$demo" == "default" ]]; then
ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/nocloud/nocloud_change_ver.yml
exit 0
elif [[ "$demo" == "kubernetes" ]]; then
ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/kubernetes/kubernetes_controller_change_ver.yml
exit 0
elif [[ "$demo" == "openshift" ]]; then
ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/openshift/openshift_controller_change_ver.yml
exit 0
fi
fi
done
}
dependency_check() {
echo "=====> Checking for dependencies"
check_for_pip
check_for_ansible
check_for_dockerpy
check_for_avisdk
check_for_ansible_roles
check_for_unzip
check_for_curl
check_for_unbuffer
rm -rf /usr/local/lib/python2.7/dist-packages/ansible/modules/network/avi
rm -rf /usr/lib/python2.7/site-packages/ansible/modules/network/avi
}
download_files() {
curl -sSLk https://github.com/avinetworks/demo-in-a-box/archive/master.zip --output avidemo.zip
unzip -nq avidemo.zip
}
playbook_install_demo() {
echo "=====> Begin executing ansible playbooks to install demo"
for a in "${cmd_args[@]}"; do
if [[ "$a" == "kubernetes" ]]; then
result=$(unbuffer ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/kubernetes/demo_kubernetes.yml | tee /dev/tty)
if [[ $result =~ "failed=1" ]]; then
echo "=====> ERROR: install script encountered an error"
exit 1
else
return 0
fi
elif [[ "$a" == "openshift" ]]; then
result=$(unbuffer ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/openshift/demo_openshift.yml | tee /dev/tty)
if [[ $result =~ "failed=1" ]]; then
echo "=====> ERROR: install script encountered an error"
exit 1
else
return 0
fi
elif [[ "$a" == "nocloud" ]]; then
result=$(unbuffer ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/nocloud/demo_nocloud.yml | tee /dev/tty)
if [[ $result =~ "failed=1" ]]; then
echo "=====> ERROR: install script encountered an error"
exit 1
else
return 0
fi
fi
done
result=$(unbuffer ansible-playbook -i demo-in-a-box-master/hosts demo-in-a-box-master/demos/nocloud/demo_nocloud.yml | tee /dev/tty)
if [[ $result =~ "failed=1" ]]; then
echo "=====> ERROR: install script encountered an error"
exit 1
else
return 0
fi
}
playbook_metrics_install() {
echo "=====> Begin executing ansible playbooks to install metrics"
ansible-playbook -i demo-in-a-box-master/demos/metrics/metrics_hosts demo-in-a-box-master/demos/metrics/metrics_install.yml
}
playbook_metrics_delete() {
echo "=====> Begin executing ansible playbooks to delete metrics"
ansible-playbook -i demo-in-a-box-master/demos/metrics/metrics_hosts demo-in-a-box-master/demos/metrics/metrics_delete.yml
}
playbook_splunk_install() {
echo "=====> Begin executing ansible playbooks to install splunk"
ansible-playbook -i demo-in-a-box-master/splunk/splunk_hosts demo-in-a-box-master/splunk/splunk/splunk-install.yml
ansible-playbook -i demo-in-a-box-master/splunk/splunk_hosts demo-in-a-box-master/splunk/alertconfig/app.yml
}
check_for_args() {
for a in "${cmd_args[@]}"; do
if [[ "$a" == "grafana" ]]; then
playbook_metrics_install
elif [[ "$a" == "grafana-delete" ]]; then
playbook_metrics_delete
elif [[ "$a" == "splunk-install" ]]; then
playbook_splunk_install
fi
done
}
retrieve_avi_versions() {
for a in "${cmd_args[@]}"; do
if [[ "$a" == "version" ]] || [[ "$a" == "change_version" ]]; then
echo
echo "=====> Select the Avi version to deploy"
echo
versions=`curl -s https://hub.docker.com/v2/repositories/avinetworks/controller/tags/?page_size=20 | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep name | awk '{split($0,a,"\"name\":"); print a[2]}' | sed "s/\"//g" | sed "s/ //g" | sed "/latest/d"`
SAVEIFS=$IFS
IFS=$'\n'
versions=($versions)
IFS=$SAVEIFS
select selection in "${versions[@]}"; do
choice="${selection}"
[[ -n $choice ]] && break
done < /dev/tty
export AVI_VERSION="$choice"
echo
echo "=====> Version $choice selected"
echo
fi
done
}
set_controller_sizes() {
INDEX=0
for a in "${cmd_args[@]}"; do
#echo "processing arg $a ${INDEX}"
if [[ "$a" == "controller-memory" ]]; then
echo
export AVI_CONTROLLER_MEMORY="${cmd_args[INDEX+1]}"
echo "=====> Using Controller Memory ${AVI_CONTROLLER_MEMORY} GB"
echo
break
fi
let INDEX=${INDEX}+1
done
}
conclusion() {
default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
default_ip=$(ip addr show dev "$default_iface" | awk '$1 ~ /^inet/ { sub("/.*", "", $2); print $2 }' | grep -v :)
echo
echo
echo "==========> Avi Controller ============"
echo "---------------------------------------"
echo "==========> https://$default_ip"
echo "==========> username: admin"
echo "==========> password: AviDemo1!"
echo
echo
echo
for a in "${cmd_args[@]}"; do
if [[ "$a" == "grafana" ]]; then
echo "==========> Grafana Info ==========="
echo "---------------------------------------"
echo "==========> GUI https://$default_ip:3000"
echo "==========> username: admin"
echo "==========> password: AviDemo1!"
echo
echo
echo
break
fi
done
for a in "${cmd_args[@]}"; do
if [[ "$a" == "kubernetes" ]]; then
echo "==========> Kubernetes Info ==========="
echo "---------------------------------------"
echo "==========> GUI http://$default_ip:30000"
#echo "==========> Demo Portal https://<server_ip>:8008"
echo
echo
echo
return 0
elif [[ "$a" == "openshift" ]]; then
echo "==========> Openshift Info ==========="
echo "---------------------------------------"
echo "==========> GUI https://$default_ip:8443"
echo "==========> username: admin"
echo "==========> password: AviDemo1!"
echo
echo
echo
return 0
fi
done
echo "==========> RDP Server Info ==========="
echo "---------------------------------------"
echo "==========> $default_ip:3389"
echo "==========> username: admin"
echo "==========> password: AviDemo1!"
echo
echo
}
#-----------------------------------
root_check
#----- cmd args are passed with -s
cmd_args=("$@")
check_for_cleanup
check_for_change_version
retrieve_avi_versions
set_controller_sizes
distro_check
dependency_check
download_files
playbook_install_demo
check_for_args
conclusion