forked from stefanoalei/CEM-sap-program
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc
executable file
·1232 lines (1068 loc) · 25.4 KB
/
poc
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
image_path=/opt/vm-image
instance_path=/var/lib/libvirt/instance
virsh pool-info lv 2>&1 > /dev/null
if (( $? )); then
# No pool 'lv', use the new name.
volume_pool=poc
else
# Pool 'lv' is already created, stay with it.
volume_pool=lv
fi
image_cirros=cirros-0.4.0-x86_64-disk.img
image_centos=CentOS-7-x86_64-GenericCloud-1805.qcow2
image_vqfx_re=jinstall-vqfx-10-f-19.4R1.10-poc.qcow2
image_vqfx_pfe=vqfx-19.4R1-2019010209-pfe-qemu.qcow
image_vmx_re=vmx-re-18.3r1.9.qcow2
image_vmx_re_hdd=vmx-re-hdd.qcow2
image_vmx_re_usb=metadata-usb-re.img
image_vmx_pfe=vFPC-20180829.img
source poc.conf
source role
source inventory
source utils/vm.func
source hypervisor/hypervisor.func
source underlay/$poc_underlay.func
source cluster/$poc_cluster/$poc_cluster.func
get_host_os()
{
cat /etc/os-release | awk -F \" "/^NAME/"'{print $2}'
}
host_os=$(get_host_os)
create_bridge_centos()
{
local name=$1
local output
ip -br link show dev $name > /dev/null 2>&1
if (( $? == 0 )); then
return
fi
echo "Create bridge $name..."
brctl addbr $name
ip link set dev $name up
# Enable LLDP.
echo 16384 > /sys/class/net/$name/bridge/group_fwd_mask
cat << __EOF__ > /etc/sysconfig/network-scripts/ifcfg-$name
DEVICE=$name
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.6.8.254
NETMASK=255.255.255.0
__EOF__
if [ "$name" == "br-int" ]; then
ip addr add 10.6.8.254/24 dev $name
cat << __EOF__ >> /etc/sysconfig/network-scripts/ifcfg-$name
BOOTPROTO=static
IPADDR=10.6.8.254
NETMASK=255.255.255.0
__EOF__
elif [ "$name" == "br-r1" ]; then
ip addr add 10.6.11.100/24 dev $name
cat << __EOF__ >> /etc/sysconfig/network-scripts/ifcfg-$name
BOOTPROTO=static
IPADDR=10.6.11.100
NETMASK=255.255.255.0
__EOF__
else
cat << __EOF__ >> /etc/sysconfig/network-scripts/ifcfg-$name
BOOTPROTO=none
__EOF__
fi
}
create_bridge_ubuntu()
{
local name=$1
local output
ip -br link show dev $name > /dev/null 2>&1
if (( $? == 0 )); then
return
fi
echo "Create bridge $name..."
brctl addbr $name
ip link set dev $name up
if [ "$name" == "br-int" ]; then
ip addr add 10.6.8.254/24 dev $name
elif [ "$name" == "br-r1" ]; then
ip addr add 10.6.11.100/24 dev $name
fi
# Enable LLDP.
echo 16384 > /sys/class/net/$name/bridge/group_fwd_mask
}
create_bridge()
{
local name=$1
if [ "$host_os" == "CentOS Linux" ]; then
create_bridge_centos $name
elif [ "$host_os" == "Ubuntu" ]; then
create_bridge_ubuntu $name
fi
}
delete_bridge_centos()
{
local name=$1
local port
echo "Delete bridge $name..."
ip -br link show dev $name > /dev/null 2>&1
if (( $? )); then
return
fi
port=$(brctl show $name | awk "/$name/"'{print $4'})
if [ "$port" == "" ]; then
ip link delete $name
rm -f /etc/sysconfig/network-scripts/ifcfg-$name
fi
}
delete_bridge_ubuntu()
{
local name=$1
local port
echo "Delete bridge $name..."
ip -br link show dev $name > /dev/null 2>&1
if (( $? )); then
return
fi
port=$(brctl show $name | awk "/$name/"'{print $4'})
if [ "$port" == "" ]; then
ip link delete $name
fi
}
delete_bridge()
{
local name=$1
if [ "$host_os" == "CentOS Linux" ]; then
delete_bridge_centos $name
elif [ "$host_os" == "Ubuntu" ]; then
delete_bridge_ubuntu $name
fi
}
create_veth()
{
local name=$1
local output
local a
echo "Create veth $name..."
IFS=','; a=(${name}); unset IFS
ip link add ${a[0]} type veth peer name ${a[1]}
ip link set dev ${a[0]} up
ip link set dev ${a[1]} up
}
delete_veth()
{
local name=$1
local a
echo "Delete veth $name..."
IFS=','; a=(${name}); unset IFS
ip -br link show dev ${a[0]} > /dev/null 2>&1
if (( $? == 0 )); then
ip link delete ${a[0]}
fi
}
create_underlay_link()
{
local name
echo "Create underlay links..."
for name in $underlay_br_list; do
create_bridge $name
done
for name in $underlay_veth_list; do
create_veth $name
done
}
delete_underlay_link()
{
local name
echo "Delete underlay links..."
for name in $underlay_br_list; do
delete_bridge $name
done
for name in $underlay_veth_list; do
delete_veth $name
done
}
create_cluster_link()
{
local name
echo "Create cluster links..."
for name in $cluster_br_list; do
create_bridge $name
done
}
delete_cluster_link()
{
local name
echo "Delete cluster links..."
for name in $cluster_br_list; do
delete_bridge $name
done
}
enable_snat()
{
local dev
local cidr
local addr
echo "Enable SNAT..."
# Take the device of default route.
dev=$(ip route list exact 0/0 | awk '{print $5}')
iptables -t nat -S | grep $dev > /dev/null 2>&1
if (( $? )); then
cidr=$(ip -f inet -br addr show dev $dev | awk '{print $3}')
IFS='/'; a=(${cidr}); unset IFS
addr=${a[0]}
iptables -t nat -A POSTROUTING -o $dev -j SNAT --to $addr
fi
}
disable_snat()
{
local args
echo "Disable SNAT..."
iptables -t nat -S | grep SNAT > /dev/null 2>&1
if (( $? == 0 )); then
args=$(iptables -t nat -S | awk "/SNAT/"'{$1="-D"; print $0}')
iptables -t nat $args
fi
}
build_dhcp_conf()
{
local list
local arr
local addr
echo "Build /etc/dhcp/dhcpd.conf."
cat << __EOF__ > /etc/dhcp/dhcpd.conf
subnet 10.6.8.0 netmask 255.255.255.0 {
option routers 10.6.8.254;
option subnet-mask 255.255.255.0;
option broadcast-address 10.6.8.255;
__EOF__
list=$(virsh list --all | awk "/-re/"'{print $2}')
for name in $list; do
mac=$(virsh domiflist $name | awk "/br-int/"'{print $5}')
arr=(${vm_address_list[$name]})
addr=${arr[0]}
cat << __EOF__ >> /etc/dhcp/dhcpd.conf
host $name {
hardware ethernet $mac;
fixed-address $addr;
}
__EOF__
done
echo } >> /etc/dhcp/dhcpd.conf
echo "Restart DHCP server."
if [ "$host_os" == "CentOS Linux" ]; then
systemctl restart dhcpd
elif [ "$host_os" == "Ubuntu" ]; then
systemctl restart isc-dhcp-server
fi
}
stop_dhcp_server()
{
echo "Stop DHCP server."
if [ "$host_os" == "CentOS Linux" ]; then
systemctl stop dhcpd
elif [ "$host_os" == "Ubuntu" ]; then
systemctl stop isc-dhcp-server
fi
}
add_host_in_hosts()
{
local arr
arr=(${vm_address_list[$1]})
echo "${arr[0]} $1" >> /etc/hosts
if [ -n "${arr[1]}" ]; then
echo "${arr[1]} $1" >> /etc/hosts
fi
}
delete_host_in_hosts()
{
sed -i -e "/$1/d" /etc/hosts
}
initialize_vqfx()
{
local arr=(${vm_address_list[$1-re]})
local host=${arr[0]}
local idx
local sets
echo "Initialize $1."
# key_pub=$(cat /root/.ssh/id_rsa.pub)
# sshpass -p Juniper ssh $host "cli -c 'configure; \
#set system host-name $1; \
#set system root-authentication ssh-rsa \"$key_pub\"; \
#delete interfaces; \
#set interfaces em0 unit 0 family inet address $host/24; \
#set interfaces em1 unit 0 family inet address 169.254.0.2/24; \
#commit'"
sets="set system host-name $1; \
delete interfaces; \
delete vlans; \
set interfaces em0 unit 0 family inet address $host/24; \
set interfaces em1 unit 0 family inet address 169.254.0.2/24;"
# for idx in {0..7}; do
# mac=$(virsh domiflist $1-re | awk "/-xe$idx/"'{print $5}')
# if [ $mac ]; then
# sets+="set interfaces xe-0/0/$idx mac $mac;"
# fi
# done
ssh $host "cli -c 'configure; $sets; commit'"
echo "Upload factory configuration."
file=vqfx-10000-factory.conf
ssh $host "rm -f /etc/config/$file"
scp underlay/$file $host:/etc/config/$file
}
get_serial_number()
{
local port_offset=$(get_vm_console_port "$1-re")
local port=$((6000 + $port_offset))
(
sleep 1; echo "root"
sleep 1; echo "Juniper"
sleep 1; echo "cli -c 'show chassis hardware'"
sleep 1; echo exit
) | telnet 127.0.0.1 $port | awk "/Chassis/"'{print $2}'
}
get_em0()
{
local port=$1
(
sleep 1; echo "root"
sleep 1; echo "Juniper"
sleep 1; echo "cli -c 'show interface em0 terse'"
sleep 1; echo exit
) | telnet 127.0.0.1 $port | awk "/em0.0/"'{print $1}'
}
get_xe0()
{
local port=$1
(
sleep 1; echo "root"
sleep 1; echo "Juniper"
sleep 1; echo "cli -c 'show interface xe-0/0/0 terse'"
sleep 1; echo exit
) | telnet 127.0.0.1 $port | awk "/xe-0\/0\/0.16386/"'{print $1}'
}
get_lldp_neighbor()
{
local port=$1
(
sleep 1; echo "root"
sleep 1; echo "Juniper"
sleep 1; echo "cli -c 'show lldp neighbor'"
sleep 1; echo exit
) | telnet 127.0.0.1 $port | awk "/xe-/"'{print $1}'
}
wait_for_vqfx_zero()
{
local name=$1
local port_offset=$(get_vm_console_port "$name-re")
local port=$((6000 + $port_offset))
local interface
while (( 1 )); do
echo
echo "Check $name RE on $port..."
interface=$(get_em0 $port)
echo "interface: $interface"
if [ "$interface" == "em0.0" ]; then
break
fi
sleep 5
done
while (( 1 )); do
echo
echo "Check $name PFE on $port..."
interface=$(get_xe0 $port)
echo "interface: $interface"
if [ "$interface" == "xe-0/0/0.16386" ]; then
break
fi
sleep 5
done
}
zeroize_vqfx()
{
local name=$1
local arr=(${vm_address_list[$name-re]})
local host=${arr[0]}
local port_offset=$(get_vm_console_port "$name-re")
local port=$((6000 + $port_offset))
local wait=$2
clear
(
sleep 1; echo "root"
sleep 1; echo "Juniper"
sleep 1; echo "cli"
sleep 2; echo "request system zeroize"
sleep 1; echo "yes"
) | telnet 127.0.0.1 $port
if [ -n "$wait" ]; then
sleep 10
wait_for_vqfx_zero $name
fi
}
check_lldp_neighbor()
{
local name=$1
local arr=(${vm_address_list[$name-re]})
local host=${arr[0]}
local port_offset=$(get_vm_console_port "$name-re")
local port=$((6000 + $port_offset))
while (( 1 )); do
echo
echo "Check LLDP neighbor on $name..."
output=$(get_lldp_neighbor $port)
if [ -z $output ]; then
echo "No neighbor"
else
echo "Neighbor is on $output."
break
fi
sleep 5
done
}
zeroize_vqfx_all()
{
local name
for name in $vqfx_list; do
zeroize_vqfx $name
done
echo "Waiting for 10 seconds..."
sleep 10
for name in $vqfx_list; do
wait_for_vqfx_zero $name
done
# Restart vqfx PFE to bring up LLDP.
for name in $vqfx_list; do
echo "Stop $name-pfe..."
virsh destroy $name-pfe
done
for name in $vqfx_list; do
echo "Start $name-pfe..."
virsh start $name-pfe
done
echo "Waiting for 30 seconds..."
sleep 30
# Check LLDP neighbor.
for name in $vqfx_list; do
check_lldp_neighbor $name
done
echo "Create job-create-fabirc.yaml..."
build_job_create_fabric_yaml
}
build_job_create_fabric_yaml()
{
local file=job-create-fabric.yaml
local dst=../contrail-toolbox/config/$file
cp cluster/$poc_cluster/$file $dst
for name in $vqfx_list; do
sn=$(get_serial_number $name)
echo " - serial_number: \"$sn\"" >> $dst
echo " supplemental_day_0_cfg: cfg" >> $dst
echo " hostname: $name" >> $dst
done
}
initialize_vmx()
{
local arr=(${vm_address_list[$1-re]})
local host=${arr[0]}
local idx
local sets
echo "Initialize $1."
# key_pub=$(cat /root/.ssh/id_rsa.pub)
# sshpass -p Juniper ssh $host "cli -c 'configure; \
#set system host-name $1; \
#set system root-authentication ssh-rsa \"$key_pub\"; \
#delete interfaces; \
#set interfaces fxp0 unit 0 family inet address $host/24; \
#commit'"
sets="set system host-name $1; \
delete interfaces; \
set interfaces fxp0 unit 0 family inet address $host/24;"
# for idx in {0..7}; do
# mac=$(virsh domiflist $1-pfe | awk "/-ge$idx/"'{print $5}')
# if [ $mac ]; then
# sets+="set interfaces ge-0/0/$idx mac $mac;"
# fi
# done
ssh $host "cli -c 'configure; $sets; commit'"
cat << __EOF__ > /tmp/conf
set chassis auto-image-upgrade
set interfaces fxp0 unit 0 family inet dhcp
__EOF__
ssh $host "rm -f /etc/config/mx-autoimage.conf"
scp /tmp/conf $host:/etc/config/mx-autoimage.conf
}
zeroize_vmx()
{
local arr=(${vm_address_list[$1-re]})
local host=${arr[0]}
ssh $host "cli -c 'configure; load factory-default; commit'"
}
zeroize_vmx_all()
{
local name
for name in $vmx_list; do
zeroize_vmx $name
done
}
add_license_vmx()
{
local arr=(${vm_address_list[$1-re]})
local host=${arr[0]}
local license="E435890758 aeaqic aiagij cpabsc idycyi giydco bqgiyd \
sdapoz gvqlkk ovxgs4 dfojcx mylma4 uhfs7p \
etdlfc ex2i5k 4mo4fa ew2xbz ujzbol 4fl44z \
ya3md2 drdgjf preowc 5ubrju kyq"
ssh $host "echo $license > license"
ssh $host "cli -c 'request system license add license'"
}
launch_vmx()
{
local name=$1
echo "Launch vMX $name..."
launch_vm $name-re
launch_vm $name-pfe
wait_for_host $name-re
initialize_vmx $name
add_license_vmx $name
stop_dhcp_server
}
launch_vmx_all()
{
local name
for name in $vmx_list; do
launch_vmx $name
done
}
delete_vmx()
{
local name=$1
echo "Delete vMX $name..."
delete_vm $name-re
rm -f $instance_path/$name-re-hdd.qcow2 \
$instance_path/$name-re-usb.qcow2
delete_vm $name-pfe
}
delete_vmx_all()
{
for name in $vmx_list; do
delete_vmx $name
done
}
launch_vqfx()
{
local name=$1
echo "Launch vQFX $name..."
launch_vm $name-re
launch_vm $name-pfe
wait_for_host $name-re
initialize_vqfx $name
stop_dhcp_server
}
launch_vqfx_all()
{
local name
for name in $vqfx_list; do
launch_vqfx $name
done
}
delete_vqfx()
{
local name=$1
echo "Delete vQFX $name..."
delete_vm $name-re
delete_vm $name-pfe
}
delete_vqfx_all()
{
for name in $vqfx_list; do
delete_vqfx $name
done
}
configure_vmx()
{
local name=$(echo $1 | sed "s/-/_/g")
echo "Configure vMX $name..."
configure_$name
}
configure_vmx_all()
{
local name
for name in $vmx_list; do
configure_vmx $name
done
}
configure_vqfx()
{
local name=$(echo $1 | sed "s/-/_/g")
echo "Configure vQFX $name..."
configure_$name
}
configure_vqfx_all()
{
local name
for name in $vqfx_list; do
configure_vqfx $name
done
}
launch_bms_all()
{
local name
for name in $bms_list; do
launch_vm $name
done
}
delete_bms_all()
{
local name
for name in $bms_list; do
delete_vm $name
done
}
add_underlay_host()
{
local name
for name in $vqfx_list; do
add_host_in_hosts "$name-re"
done
for name in $vmx_list; do
add_host_in_hosts "$name-re"
done
}
delete_underlay_host()
{
local name
for name in $vqfx_list; do
delete_host_in_hosts "$name-re"
done
for name in $vmx_list; do
delete_host_in_hosts "$name-re"
done
}
build_underlay()
{
create_underlay_link
enable_snat
launch_vqfx_all
launch_vmx_all
launch_bms_all
configure_vqfx_all
configure_vmx_all
post_underlay
add_underlay_host
}
delete_underlay()
{
delete_bms_all
delete_vmx_all
delete_vqfx_all
disable_snat
delete_underlay_link
delete_underlay_host
}
upload_instances_yaml()
{
local host=$1
local src=$2
if [ -z "$src" ]; then src=instances.yaml; fi
scp cluster/$poc_cluster/$src $host:.
}
upgrade_kernel()
{
local name=$1
local arr=(${vm_address_list[$name]})
local host=${arr[0]}
local wait=$2
echo "Upgrade kernel on $name..."
if [ -e /opt/kernel ]; then
scp -r /opt/kernel $host:.
ssh $host "yum install -y kernel/*.rpm"
ssh $host "rm -fr kernel"
else
ssh $host "yum upgrade -y kernel"
fi
ssh $host "reboot"
if [ -n "$wait" ]; then
wait_for_host $name
fi
}
check_playbook_result()
{
local rc_list
local rc
rc_list=$(tail -n 80 poc.log | grep -A 30 "PLAY RECAP" | \
awk "/failed/"'{print $6}')
for rc in $rc_list; do
if [ "$rc" != "failed=0" ]; then return 1; fi
done
}
copy_ssh_key()
{
echo "Copy SSH key..."
scp ~/.ssh/id_rsa ~/.ssh/id_rsa.pub ~/.ssh/config $1:/root/.ssh/
}
configure_haproxy()
{
local dev
local cidr
echo "# Configure HAProxy..."
dev=$(ip route list exact 0/0 | awk '{print $5}')
cidr=$(ip -f inet -br addr show dev $dev | awk '{print $3}')
IFS='/'; a=(${cidr}); unset IFS
rm -f /etc/haproxy/haproxy.cfg
cp cluster/$poc_cluster/haproxy.cfg /etc/haproxy/haproxy.cfg
sed -i -e "s/__address__/${a[0]}/" /etc/haproxy/haproxy.cfg
systemctl restart haproxy
}
install_openstack_deployer()
{
local host=$1
copy_ssh_key $host
scp cluster/builder $host:.
scp poc.conf $host:.
ssh $host "./builder install-deployer"
}
install_kubernetes_deployer()
{
local host=$1
copy_ssh_key $host
scp cluster/builder $host:.
scp poc.conf $host:.
ssh $host "./builder install-deployer"
}
load_playbook()
{
local playbook=$1
local host=$2
echo "Upload playbook..."
if [ -n "$playbook" ]; then
scp playbook/$playbook $host:./playbook.tgz
ssh $host "tar -xzf playbook.tgz; rm -f playbook.tgz"
fi
}
run_playbook()
{
local host=$1
local op=$2
echo "Run playbook......"
ssh $host "./builder $2"
check_playbook_result
if (( $? )); then return 1; fi
}
run_playbook_openshift()
{
local host=$1
echo "Run playbook......"
scp cluster/$poc_cluster/poc.yaml $host:./openshift-ansible/inventory/
ssh $host sed -i \
-e "s/__registry_username__/$registry_username/" \
-e "s/__registry_password__/$registry_password/" \
-e "s/__contrail_version__/$contrail_version/" \
./openshift-ansible/inventory/poc.yaml
ssh $host "cd openshift-ansible; \
ansible-playbook -i inventory/poc.yaml \
playbooks/prerequisites.yml"
check_playbook_result
if (( $? )); then return 1; fi
ssh $host "cd openshift-ansible; \
ansible-playbook -i inventory/poc.yaml \
playbooks/deploy_cluster.yml"
check_playbook_result
if (( $? )); then return 1; fi
}
configure_openstack()
{
host=$1
echo "Configure OpenStack on $host..."
scp $image_path/$image_cirros $host:/etc/kolla/kolla-toolbox/
ssh $host "docker exec -u root kolla_toolbox \
bash -c \"source /var/lib/kolla/config_files/admin-openrc.sh; \
openstack flavor create \
--id 1 --disk 1 --ram 512 --vcpus 1 --public m1.tiny\""
ssh $host "docker exec -u root kolla_toolbox \
bash -c \"source /var/lib/kolla/config_files/admin-openrc.sh; \
openstack image create \
--container-format bare --disk-format qcow2 --public \
--file /var/lib/kolla/config_files/$image_cirros cirros\""
ssh $host "rm -f /etc/kolla/kolla-toolbox/$image_cirros"
}
install_command()
{
local host=$1
echo "Install Contrail Command..."
scp poc.conf $host:.
scp cluster/builder $host:.
ssh $host "./builder install-command"
scp cluster/$poc_cluster/command_servers.yml $host:.
}
delete_command()
{
local host=$1
echo "Delete Contrail Command..."
scp cluster/builder $host:.
scp poc.conf $host:.
ssh $host "./builder delete-command"
}
add_cluster_host()
{
local name
for name in $server_list; do
add_host_in_hosts "$name"
done
}
delete_cluster_host()
{
local name
for name in $server_list; do
delete_host_in_hosts "$name"
done
}
build_cluster()
{
local name
create_cluster_link
enable_snat
for name in $server_list; do
launch_vm $name
check_vm $name
if (( $? )); then return 1; fi
done
for name in $server_list; do
wait_for_host $name
done
pre_cluster
launch_builder
deploy
if (( $? )); then return 1; fi
post_cluster
add_cluster_host
}
delete_cluster()
{
local name
for name in $server_list; do
delete_vm $name
done
delete_builder
disable_snat