forked from Juniper/contrail-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contrail_config_functions
949 lines (845 loc) · 31.6 KB
/
contrail_config_functions
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
# vim: syntax=sh
source functions
function replace_cassandra_conf()
{
if [ ! -z "$CASSANDRA_IP" ]
then
sudo sed -i -e 's/listen_address:.*/listen_address: '$CASSANDRA_IP'/' /etc/cassandra/cassandra.yaml
sudo sed -i -e 's/rpc_address:.*/rpc_address: '$CASSANDRA_IP'/' /etc/cassandra/cassandra.yaml
fi
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
seeds=${seeds}""$ip","
done
seeds=${seeds::-1}
sudo sed -i -e 's/seeds:.*/seeds: "'$seeds'"/' /etc/cassandra/cassandra.yaml
}
function replace_api_server_conf()
{
file="/etc/contrail/contrail-api.conf"
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
zookeeper_server=""
for ip in ${ZOOKEEPER_IP_LIST[@]};
do
zookeeper_server=${zookeeper_server}""$ip","
done
zookeeper_server=${zookeeper_server::-1}
port=0
if $USE_CERTS ; then
port=8444
else
port=8443
fi
check_replace_value $file DEFAULTS ifmap_server_ip $IFMAP_IP
check_replace_value $file DEFAULTS ifmap_server_port $port
check_replace_value $file DEFAULTS multi_tenancy $MULTI_TENANCY
check_replace_value $file DEFAULTS disc_server_ip $DISCOVERY_IP
check_replace_value $file DEFAULTS cassandra_server_list $cassandra_server
check_replace_value $file DEFAULTS zk_server_ip $zookeeper_server
check_replace_value $file DEFAULTS zk_server_port 2181
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file DEFAULTS ifmap_username 'api-server'
check_replace_value $file DEFAULTS ifmap_password 'api-server'
check_replace_value $file DEFAULTS listen_ip_addr '0.0.0.0'
check_replace_value $file DEFAULTS listen_port 8082
check_replace_value $file DEFAULTS log_file '/var/log/contrail/api.log'
check_replace_value $file DEFAULTS disc_server_port 5998
check_replace_value $file DEFAULTS auth keystone
check_replace_value $file DEFAULTS redis_server_port 6379
fi
check_replace_value $file SECURITY use_certs $USE_CERTS
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file SECURITY keyfile '/etc/contrail/ssl/private_keys/apiserver_key.pem'
check_replace_value $file SECURITY certfile '/etc/contrail/ssl/certs/apiserver.pem'
check_replace_value $file SECURITY ca_certs '/etc/contrail/ssl/certs/ca.pem'
fi
check_replace_value $file KEYSTONE auth_host $OPENSTACK_IP
check_replace_value $file KEYSTONE admin_user $CONTRAIL_ADMIN_USERNAME
check_replace_value $file KEYSTONE admin_password $ADMIN_PASSWORD
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
check_replace_value $file KEYSTONE auth_port 5000
check_replace_value $file KEYSTONE auth_protocol http
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file KEYSTONE memcache_servers '127.0.0.1:11211'
fi
}
function check_replace_value()
{
file=$1
section=$2
key=$3
value=$4
if [[ -n "$value" ]]; then
if [[ -n "$section" ]]; then
iniset $file $section $key $value
else
iniset $file "DEFAULTS" $key $value
fi
fi
}
function replace_contrail_plugin_conf()
{
file="/etc/contrail/contrail_plugin.ini"
temp_location="/etc/quantum/plugins/contrail/contrail_plugin.ini"
check_replace_value $file APISERVER api_server_ip $CFGM_IP
check_replace_value $file APISERVER multi_tenancy $MULTI_TENANCY
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file APISERVER api_server_port 8082
fi
#un-comment if keystone ip present
#check_replace_value $file APISERVER auth_url http://$KEYSTONE_IP:5000/v2.0
#check_replace_value $file APISERVER admin_token $CONTRAIL_ADMIN_TOKEN
check_replace_value $file KEYSTONE admin_user $CONTRAIL_ADMIN_USERNAME
check_replace_value $file KEYSTONE admin_password $ADMIN_PASSWORD
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
check_replace_value $file KEYSTONE auth_url http://$OPENSTACK_IP:5000/v2.0
cp $file $temp_location
}
function replace_contrail_schema_conf()
{
file="/etc/contrail/contrail-schema.conf"
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
zookeeper_server=""
for ip in ${ZOOKEEPER_IP_LIST[@]};
do
zookeeper_server=${zookeeper_server}""$ip","
done
zookeeper_server=${zookeeper_server::-1}
port=0
if $USE_CERTS ; then
port=8444
else
port=8443
fi
check_replace_value $file DEFAULTS ifmap_server_ip $CFGM_IP
check_replace_value $file DEFAULTS ifmap_server_port $port
check_replace_value $file DEFAULTS api_server_ip $CFGM_IP
check_replace_value $file DEFAULTS disc_server_ip $DISCOVERY_IP
check_replace_value $file DEFAULTS cassandra_server_list $cassandra_server
check_replace_value $file DEFAULTS zk_server_ip $zookeeper_server
check_replace_value $file DEFAULTS zk_server_port 2181
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file DEFAULTS ifmap_username 'schema-transformer'
check_replace_value $file DEFAULTS ifmap_password 'schema-transformer'
check_replace_value $file DEFAULTS api_server_port 8082
check_replace_value $file DEFAULTS log_file '/var/log/contrail/schema.log'
check_replace_value $file DEFAULTS disc_server_port 5998
fi
check_replace_value $file SECURITY use_certs $USE_CERTS
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file SECURITY ca_certs '/etc/contrail/ssl/certs/ca.pem'
check_replace_value $file SECURITY certfile '/etc/contrail/ssl/certs/schema_xfer.pem'
check_replace_value $file SECURITY keyfile '/etc/contrail/ssl/private_keys/schema_xfer_key.pem'
fi
check_replace_value $file KEYSTONE admin_user $CONTRAIL_ADMIN_USERNAME
check_replace_value $file KEYSTONE admin_password $ADMIN_PASSWORD
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
}
function replace_svc_monitor_conf()
{
file="/etc/contrail/svc-monitor.conf"
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
zookeeper_server=""
for ip in ${ZOOKEEPER_IP_LIST[@]};
do
zookeeper_server=${zookeeper_server}""$ip","
done
zookeeper_server=${zookeeper_server::-1}
port=0
if $USE_CERTS ; then
port=8444
else
port=8443
fi
check_replace_value $file DEFAULTS ifmap_server_ip $CFGM_IP
check_replace_value $file DEFAULTS ifmap_server_port $port
check_replace_value $file DEFAULTS api_server_ip $CFGM_IP
check_replace_value $file DEFAULTS disc_server_ip $DISCOVERY_IP
check_replace_value $file DEFAULTS disc_server_port 5998
check_replace_value $file DEFAULTS cassandra_server_list $cassandra_server
check_replace_value $file DEFAULTS zk_server_ip $zookeeper_server
check_replace_value $file DEFAULTS zk_server_port 2181
check_replace_value $file DEFAULTS ifmap_username 'svc_monitor'
check_replace_value $file DEFAULTS ifmap_password 'svc_monitor'
check_replace_value $file DEFAULTS rabbit_user $RABBIT_USER
check_replace_value $file DEFAULTS rabbit_password $RABBIT_PASSWORD
check_replace_value $file SECURITY ca_certs '/etc/contrail/ssl/certs/ca.pem'
check_replace_value $file SECURITY certfile '/etc/contrail/ssl/certs/svc_monitor.pem'
check_replace_value $file SECURITY keyfile '/etc/contrail/ssl/private_keys/svc_monitor_key.pem'
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file DEFAULTS ifmap_username 'svc-monitor'
check_replace_value $file DEFAULTS ifmap_password 'svc-monitor'
check_replace_value $file DEFAULTS api_server_port 8082
check_replace_value $file DEFAULTS log_file '/var/log/contrail/svc-monitor.log'
fi
check_replace_value $file SECURITY use_certs $USE_CERTS
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file SECURITY ca_certs '/etc/contrail/ssl/certs/ca.pem'
check_replace_value $file SECURITY certfile '/etc/contrail/ssl/certs/svc_monitor.pem'
check_replace_value $file SECURITY keyfile '/etc/contrail/ssl/private_keys/svc_monitor_key.pem'
fi
check_replace_value $file KEYSTONE admin_user $CONTRAIL_ADMIN_USERNAME
check_replace_value $file KEYSTONE admin_password $ADMIN_PASSWORD
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file KEYSTONE memcache_servers '127.0.0.1:11211'
fi
}
function replace_discovery_conf()
{
file="/etc/contrail/contrail-discovery.conf"
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
zookeeper_server=""
for ip in ${ZOOKEEPER_IP_LIST[@]};
do
zookeeper_server=${zookeeper_server}""$ip","
done
zookeeper_server=${zookeeper_server::-1}
check_replace_value $file DEFAULTS zk_server_ip $zookeeper_server
check_replace_value $file DEFAULTS listen_ip_addr $CFGM_IP
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file DEFAULTS zk_server_port 2181
check_replace_value $file DEFAULTS listen_port 5998
check_replace_value $file DEFAULTS log_local 'True'
check_replace_value $file DEFAULTS log_file '/var/log/contrail/discovery.log'
fi
check_replace_value $file DEFAULTS cassandra_server_list $cassandra_server
# minimim time to allow client to cache service information (seconds)
#check_replace_value $file DEFAULTS ttl_min 300
# maximum time to allow client to cache service information (seconds)
#check_replace_value $file DEFAULTS ttl_max 1800
# maximum hearbeats to miss before server will declare publisher out of
# service.
#check_replace_value $file DEFAULTS hc_max_miss 3
# use short TTL for agressive rescheduling if all services are not up
#check_replace_value $file DEFAULTS ttl_short 1
######################################################################
# Other service specific knobs ...
# use short TTL for agressive rescheduling if all services are not up
# ttl_short=1
# specify policy to use when assigning services
# policy = [load-balance | round-robin | fixed]
######################################################################
}
function replace_vnc_api_lib_conf()
{
file="/etc/contrail/vnc_api_lib.ini"
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file global WEB_SERVER '127.0.0.1'
check_replace_value $file global WEB_PORT 8082 ; connection to api-server directly
check_replace_value $file global BASE_URL '/'
check_replace_value $file auth AUTHN_TYPE 'keystone'
check_replace_value $file auth AUTHN_PORT 5000
check_replace_value $file auth AUTHN_URL '/v2.0/tokens'
fi
check_replace_value $file auth AUTHN_SERVER $OPENSTACK_IP
}
function replace_ContrailPlugin_conf()
{
file="/etc/contrail/ContrailPlugin.ini"
check_replace_value $file APISERVER api_server_ip $CFGM_IP
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file APISERVER api_server_port 8082
check_replace_value $file APISERVER multi_tenancy False
fi
check_replace_value $file KEYSTONE admin_user $CONTRAIL_ADMIN_USERNAME
check_replace_value $file KEYSTONE admin_password $ADMIN_PASSWORD
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
check_replace_value $file KEYSTONE admin_tenant_name $CONTRAIL_ADMIN_TENANT
check_replace_value $file KEYSTONE auth_host $OPENSTACK_IP
check_replace_value $file KEYSTONE auth_url http://$OPENSTACK_IP:5000/v2.0
}
function replace_contrail_control_conf()
{
file="/etc/contrail/contrail-control.conf"
port=0
CERT_OPTS=""
if [[ -n $PUPPET_SERVER ]]; then
CERTDIR='/var/lib/puppet/ssl'
else
CERTDIR='/etc/contrail/ssl'
fi
if $USE_CERTS ; then
port=8444
CERT_OPTS="--use-certs=$CERTDIR"
else
port=8443
fi
if [[ $CONTROL_IP = "localhost" ]]; then
CONTROL_IP="127.0.0.1"
fi
if [[ $COLLECTOR_IP = "localhost" ]]; then
COLLECTOR_IP="127.0.0.1"
fi
if [ $USE_DISCOVERY = "False" ]; then
check_replace_value $file IFMAP server_url https://$IFMAP_IP:$port
else
inicomment $file IFMAP server_url
fi
check_replace_value $file IFMAP user $CONTROL_IP
check_replace_value $file IFMAP password $CONTROL_IP
check_replace_value $file DISCOVERY server $DISCOVERY_IP
check_replace_value $file DISCOVERY port 5998
if [ $USE_DISCOVERY = "False" ]; then
check_replace_value $file DEFAULT collectors $COLLECTOR_IP:8086
else
inicomment $file DEFAULT collectors
fi
check_replace_value $file DEFAULT hostname `hostname`
check_replace_value $file DEFAULT log_file '/var/log/contrail/control.log'
check_replace_value $file DEFAULT hostip $CONTROL_IP
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file DEFAULT bgp_port 179
check_replace_value $file DEFAULT CERT_OPTS $CERT_OPTS
fi
}
function replace_contrail_collector_conf()
{
file="/etc/contrail/contrail-collector.conf"
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
if [[ $COLLECTOR_IP = "localhost" ]]; then
COLLECTOR_IP="127.0.0.1"
fi
check_replace_value $file DEFAULT log_file '/var/log/contrail/contrail-collector.log'
check_replace_value $file DEFAULT log_local 1
check_replace_value $file DEFAULT cassandra_server_list $cassandra_server
check_replace_value $file DEFAULT hostip $COLLECTOR_IP
check_replace_value $file DEFAULT hostname `hostname`
check_replace_value $file DISCOVERY server $DISCOVERY_IP
}
function replace_contrail_analytics_api_conf()
{
file="/etc/contrail/contrail-analytics-api.conf"
check_replace_value $file DEFAULTS log_file '/var/log/contrail/contrail-analytics-api.log'
check_replace_value $file DEFAULTS host_ip $COLLECTOR_IP
cassandra_server=""
for ip in ${CASSANDRA_IP_LIST[@]};
do
cassandra_server=${cassandra_server}""$ip":9160 "
done
check_replace_value $file DEFAULTS cassandra_server_list $cassandra_server
check_replace_value $file DISCOVERY disc_server_ip $DISCOVERY_IP
check_replace_value $file DISCOVERY server $DISCOVERY_IP
check_replace_value $file DISCOVERY port 5998
}
function replace_contrail_dns_conf()
{
file="/etc/contrail/dns/contrail-dns.conf"
named_log="/var/log/contrail/contrail-named.log"
rndc_secret="xvysmOR8lnUQRBcunkC6vg=="
if [ $USE_DISCOVERY = "False" ]; then
check_replace_value $file IFMAP server_url $IFMAP_IP
check_replace_value $file DEFAULT collectors $COLLECTOR_IP
else
inicomment $file IFMAP server_url
inicomment $file DEFAULT collectors
fi
check_replace_value $file IFMAP user ${CONTROL_IP}.dns
check_replace_value $file IFMAP password ${CONTROL_IP}.dns
check_replace_value $file DISCOVERY server $DISCOVERY_IP
check_replace_value $file DISCOVERY port 5998
check_replace_value $file DEFAULT hostip $CONTROL_IP
check_replace_value $file DEFAULT hostname `hostname`
check_replace_value $file DEFAULT log_file '/var/log/contrail/contrail-dns.log'
check_replace_value $file DEFAULT log_level 'SYS_NOTICE'
check_replace_value $file DEFAULT log_local 1
check_replace_value $file DEFAULT named_log_file $named_log
check_replace_value $file DEFAULT rndc_secret $rndc_secret
check_replace_value $file DEFAULT rndc_config_file 'contrail-rndc.conf'
# log file must be created with correct permissions for named to start
touch $named_log
sudo chown $(id -u):root $named_log
# https://bugs.launchpad.net/opencontrail/+bug/1479323
mkdir -p ${CONTRAIL_SRC}/build/var/run/named/
sudo chown root:root ${CONTRAIL_SRC}/build/var/run/named/
}
function check_dev()
{
interface=$1
arr=$(ifconfig | awk '{print $1}')
if [[ " ${arr[*]} " == *"$interface"* ]]; then
echo "interface found"
else
echo "interface not found try another interface"
fi
}
function remove_spaces()
{
file=$1
section=$2
sed -i "s/\[$section\]//g" $file
sed -i "s/ //g" $file
}
function replace_contrail_compute_conf()
{
file="/etc/contrail/contrail-compute.conf"
if [[ -f $file ]]; then
rm $file
fi
value=$(check_dev $PHYSICAL_INTERFACE)
if [[ $value = "interface found" ]];then
check_replace_value $file "" LOG /var/log/contrail.log
check_replace_value $file "" CONFIG /etc/contrail/agent.conf
check_replace_value $file "" prog /usr/bin/vnswad
check_replace_value $file "" kmod vrouter.ko
check_replace_value $file "" pname vnswad
check_replace_value $file "" LIBDIR /usr/lib64
check_replace_value $file "" VHOST_CFG /etc/sysconfig/network-scripts/ifcfg-vhost0
check_replace_value $file "" VROUTER_LOGFILE --log-file=/var/log/vrouter.log
check_replace_value $file "" COLLECTOR $COLLECTOR_IP
check_replace_value $file "" dev $PHYSICAL_INTERFACE
remove_spaces $file DEFAULTS
else
echo "interface not found try another interface inside else"
exit 1
fi
}
function get_dns_servers()
{
dns_list=$(grep "^nameserver\\>" /etc/resolv.conf | awk '{print $2}')
echo $dns_list
}
function get_domain_search_list()
{
domain_list=''
domin_list=$(grep ^"search" /etc/resolv.conf | awk '{$1="";print $0}')
if [[ $? -eq 1 ]]; then
domin_list=grep ^"domain" /etc/resolv.conf | awk '{$1=""; print $0}'
fi
echo $domin_list
}
function get_if_mtu()
{
mtu=''
interface=$1
mtu=$(ifconfig $interface|grep MTU | awk 'BEGIN{FS=OFS="MTU"}{print $2}'|awk 'BEGIN{FS=OFS=":"}{print $2}'|awk '{print $1}')
if [[ $mtu -eq 1500 ]]; then
mtu=''
fi
echo $mtu
}
function find_gateway()
{
interface=$1
gateway=$(netstat -rn | grep ^"0.0.0.0" | grep $interface | awk '{ print $2 }')
echo $gateway
}
function get_Mask()
{
interface=$1
if is_ubuntu; then
mask=$(ifconfig $interface|grep Mask | awk 'BEGIN{FS=OFS="Mask"}{print $2}'|awk 'BEGIN{FS=OFS=":"}{print $2}')
echo $mask
else
mask=$(ifconfig $interface|sed -ne 's/.*[[net]*]*mask[: ]*\([0-9.]*\).*/\1/i p')
echo $mask
fi
}
function get_management_ip()
{
interface=$1
if is_ubuntu; then
management_ip=$(ifconfig $interface|grep -e addr| awk 'BEGIN{FS=OFS="net addr"}{print $2}'|awk '{print $1}'|awk 'BEGIN{FS=OFS=":"}{print $2}')
echo $management_ip
else
management_ip=$(ifconfig $interface|sed -ne 's/.*inet [[addr]*]*[: ]*\([0-9.]*\).*/\1/i p')
echo $management_ip
fi
}
function get_intf_ip()
{
interface=$1
ip=''
interface_list=$(sudo netstat -i | awk '{print $1}'|sed -n '1,2!p')
for inf in ${interface_list[@]}
do
if [[ "$inf" == "$interface" ]]; then
ip=$(get_management_ip $inf)
echo $ip
fi
done
if [[ -z $ip ]]; then
echo "$interface not configured"
fi
}
function get_device_by_ip()
{
ip=$1
interface=""
interface_list=$(sudo netstat -i | awk '{print $1}'|sed -n '1,2!p')
for inf in ${interface_list[@]}
do
if [[ $inf == "pkt1" ]]; then
interface=""
else
if [[ "$ip" == "$(get_management_ip $inf)" ]]; then
if [[ "$interface" == "vhost0" ]]; then
:
fi
interface=$inf
echo $interface
fi
fi
done
if [[ -z $interface ]]; then
echo "$ip not configured"
fi
}
function _rewrite_ifcfg_file()
{
filename=$1
dev=$2
prsv_cfg=$3
bond=false
mac=''
temp_dir_name="/tmp"
if [[ -d "/sys/class/net/$dev/bonding" ]]; then
bond=true
fi
mac=$(get_Mac $dev)
ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-$dev"
if is_fedora ; then
echo "#Contrail-$dev" >> $ifcfg_file
echo "ONBOOT=yes" >> $ifcfg_file
echo "DEVICE="$dev"" >> $ifcfg_file
echo "BOOTPROTO=dhcp" >> $ifcfg_file
fi
if [[ ! -f $ifcfg_file ]]; then
ifcfg_file=$temp_dir_name'/ifcfg-'$dev
rm $ifcfg_file
echo "#Contrail-$dev" >> $ifcfg_file
echo "TYPE=Ethernet" >> $ifcfg_file
echo "ONBOOT=yes" >> $ifcfg_file
echo "DEVICE="$dev"" >> $ifcfg_file
echo "USERCTL=yes" >> $ifcfg_file
echo "NM_CONTROLLED=no" >> $ifcfg_file
echo "HWADDR=$mac" >> $ifcfg_file
fi
for dcfg in ${prsv_cfg[@]}
do
$dcfg >> $ifcfg_file
done
new_f_lines=()
remove_items=('IPADDR','NETMASK','PREFIX','GATEWAY','HWADDR','DNS1','DNS2','BOOTPROTO','NM_CONTROLLED','#Contrail')
remove_items+=("DEVICE")
new_f_lines+=("#Contrail-$dev")
new_f_lines+=("DEVICE=$dev")
f_lines=()
while read line; do
f_lines+=($line)
done < $ifcfg_file
for line in ${f_lines[@]}
do
found=false
for text in ${remove_items[@]}
do
if echo "$line" | grep -q "$text"; then
found=true
fi
done
if [[ $found ]]; then
new_f_lines+=($line)
fi
done
if [[ $bond ]]; then
new_f_lines+=("SUBCHANNELS=1,2,3")
#new_f_lines+=()
else
new_f_lines+=("HWADDR=$mac")
fi
if [[ -f $filename ]]; then
sudo rm $filename
fi
for line in ${new_f_lines[@]}
do
echo $line >> $filename
done
}
function migrate_routes()
{
:
}
function get_Mac()
{
interface=$1
if is_ubuntu; then
mac=$(ifconfig $interface|grep HWaddr | awk '{print $5}')
elif is_fedora; then
mac=$(ifconfig $interface|grep ether | awk '{print $2}')
fi
echo $mac
}
function replace_contrail_vrouter_agent_conf()
{
file="/etc/contrail/contrail-vrouter-agent.conf"
cidr=$(get_management_ip $PHYSICAL_INTERFACE)/24
gateway=$(find_gateway $PHYSICAL_INTERFACE)
if [ $USE_DISCOVERY = "False" ]; then
check_replace_value $file CONTROL-NODE server $CFGM_IP
else
inicomment $file CONTROL-NODE server
fi
check_replace_value $file NETWORKS control_network_ip $CFGM_IP
check_replace_value $file VIRTUAL-HOST-INTERFACE ip $cidr
check_replace_value $file VIRTUAL-HOST-INTERFACE name vhost0
check_replace_value $file VIRTUAL-HOST-INTERFACE gateway $gateway
check_replace_value $file VIRTUAL-HOST-INTERFACE physical_interface $PHYSICAL_INTERFACE
check_replace_value $file COLLECTOR port 8080
if [ $USE_DISCOVERY = "False" ]; then
check_replace_value $file COLLECTOR server $CFGM_IP
else
inicomment $file COLLECTOR server
fi
check_replace_value $file DISCOVERY server $DISCOVERY_IP
if [ $CONTRAIL_VGW_INTERFACE -a $CONTRAIL_VGW_PUBLIC_SUBNET -a $CONTRAIL_VGW_PUBLIC_NETWORK ]; then
check_replace_value $file GATEWAY-0 interface $CONTRAIL_VGW_INTERFACE
check_replace_value $file GATEWAY-0 ip_blocks $CONTRAIL_VGW_PUBLIC_SUBNET
check_replace_value $file GATEWAY-0 routing_instance $CONTRAIL_VGW_PUBLIC_NETWORK
fi
}
function replace_irond_basic_auth_users()
{
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
file="/etc/ifmap-server/basicauthusers.properties"
file1="/etc/ifmap-server/publisher.properties"
sudo chown `whoami`:`whoami` $file
sudo chown `whoami`:`whoami` $file1
sudo chmod 664 $file
sudo chmod 664 $file1
else
if is_ubuntu; then
file="$CONTRAIL_SRC/build/packages/ifmap-server/basicauthusers.properties"
file1="$CONTRAIL_SRC/build/packages/ifmap-server/publisher.properties"
else
file="/opt/stack/contrail/third_party/irond-0.3.0-bin/basicauthusers.properties"
file1="/opt/stack/contrail/third_party/irond-0.3.0-bin/publisher.properties"
fi
sudo chown `whoami`:`whoami` $file
sudo chown `whoami`:`whoami` $file1
sudo chmod 664 $file
sudo chmod 664 $file1
fi
sudo grep -q ^"# Contrail" $file
value=$?
if [[ $value -eq 1 ]]; then
sudo echo "$CONTROL_IP=$CFGM_IP--0000000001-1" >> $file1
fi
sed -i '/^# Contrail/Q' $file
echo '# Contrail users' >> $file
sudo echo 'api-server:api-server' >> $file
sudo echo 'schema-transformer:schema-transformer' >> $file
sudo echo 'svc_monitor:svc_monitor' >> $file
for ip in ${CONTROL_IP_LIST[@]};
do
sudo echo "$ip:$ip" >> $file
done
for ip in ${DNS_IP_LIST[@]};
do
sudo echo "$ip.dns:$ip.dns" >> $file
done
}
function write_default_pmac()
{
file="/etc/contrail/default_pmac"
mac=$(get_Mac)
echo $mac >> $file
}
function write_ifcfg-vhost0()
{
vhost_file="/etc/contrail/ifcfg-vhost0"
value=$(check_dev 'vhost0')
if [[ $value = "interface found" ]];then
ip=$(get_management_ip vhost0)
else
ip=$(get_management_ip $PHYSICAL_INTERFACE)
fi
if [[ -f $vhost_file ]]; then
sudo rm $vhost_file
fi
echo "#Contrail vhost0" >> $vhost_file
echo "DEVICE=vhost0" >> $vhost_file
#echo "ONBOOT=yes" >> $vhost_file
echo "ONBOOT=no" >> $vhost_file
#echo "BOOTPROTO=static" >> $vhost_file
echo "BOOTPROTO=none" >> $vhost_file
echo "IPV6INIT=no" >> $vhost_file
echo "USERCTL=yes" >> $vhost_file
echo "HWADDR=$(get_Mac $PHYSICAL_INTERFACE)" >> $vhost_file
#echo "TYPE=Ethernet" >> $vhost_file
echo "IPADDR=$ip" >> $vhost_file
echo "NETMASK=$(get_Mask $PHYSICAL_INTERFACE)" >> $vhost_file
echo "GATEWAY=$(find_gateway $PHYSICAL_INTERFACE)" >> $vhost_file
echo "NM_CONTROLLED=no" >>$vhost_file
echo "#NETWORK MANAGER BUG WORKAROUND" >> $vhost_file
echo "SUBCHANNELS=1,2,3" >> $vhost_file
}
function write_qemu_conf()
{
file="/etc/libvirt/qemu.conf"
temp_file="qemu.conf"
sudo grep -q ^"cgroup_device_acl" $file
value=$?
if [[ $value -eq 1 ]] ; then
sudo cp $file $temp_file
sudo chown `whoami` $temp_file
sudo echo "cgroup_device_acl = [" >> $temp_file
sudo echo ' "/dev/null", "/dev/full", "/dev/zero",' >> $temp_file
sudo echo ' "/dev/random", "/dev/urandom",' >> $temp_file
sudo echo ' "/dev/ptmx", "/dev/kvm", "/dev/kqemu",' >> $temp_file
sudo echo ' "/dev/rtc", "/dev/hpet","/dev/net/tun",' >> $temp_file
sudo echo "]" >> $temp_file
sudo mv $temp_file $file
fi
}
function replace_in_file()
{
file=$1
regexp=$2
replace=$3
sed -i 's|^.*\b'"$regexp"'.*\b|'"$replace"'|g' $file
}
function contains_elements()
{
role=()
roles+=$1
search_string=$2
match=$(echo "${roles[@]:0}" | grep -o $search_string)
[[ ! -z $match ]] && echo "found"
}
function fixup_config_files()
{
multi_net=false
#roles=${roles:-('config', 'openstack', 'control', 'compute', 'collector', 'webui')}
if [[ ! -d "/etc/contrail" ]]; then
sudo mkdir -p /etc/contrail
sudo chown `whoami` /etc/contrail
fi
if [[ ! -d "/etc/quantum/plugins/contrail" ]]; then
sudo mkdir -p /etc/quantum/plugins/contrail
sudo chown `whoami` /etc/quantum/plugins/contrail
fi
COMPUTE_IP=$(get_management_ip $PHYSICAL_INTERFACE)
if [[ -z $SERVICE_TOKEN ]]; then
SERVICE_TOKEN=$(sudo openssl rand -hex 10)
$SERVICE_TOKEN > /etc/contrail/service.token
fi
# Disable selinux
sudo sed 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config > config.new
sudo mv config.new /etc/selinux/config
setenforce 0
# Disable iptables
if [[ "$DISTRO" != "trusty" ]]; then
sudo chkconfig iptables off
else
sudo sysv-rc-conf iptables off
fi
sudo iptables --flush
sudo rm /etc/contrail/ctrl-details
echo 'SERVICE_TOKEN='$SERVICE_TOKEN >> "/etc/contrail/ctrl-details"
echo 'ADMIN_PASSWORD='$ADMIN_PASSWORD >> "/etc/contrail/ctrl-details"
echo 'CONTROLLER='$OPENSTACK_IP >> "/etc/contrail/ctrl-details"
echo 'QUANTUM='$CFGM_IP >> "/etc/contrail/ctrl-details"
echo 'COMPUTE='$COMPUTE_IP >> "/etc/contrail/ctrl-details"
echo 'CONTROLLER_MGMT='$CFGM_IP >> "/etc/contrail/ctrl-details"
if [ "$INSTALL_PROFILE" = "ALL" ]; then
REDIS_WEBUI="/etc/contrail/redis-webui.conf"
if [[ -f /etc/redis/redis.conf ]]; then
REDIS_CONF="/etc/redis/redis.conf"
else
REDIS_CONF="/etc/redis.conf"
fi
sudo sed 's/bind 127.0.0.1.*/#bind 127.0.0.1/g' $REDIS_CONF > redis.conf.new
sudo mv redis.conf.new $REDIS_CONF
sudo cp $REDIS_CONF $REDIS_WEBUI
replace_in_file $REDIS_WEBUI 'pidfile /var/run/redis/redis.pid' 'pidfile /var/run/redis/redis-webui.pid'
replace_in_file $REDIS_WEBUI 'port 6379' 'port 6383'
replace_in_file $REDIS_WEBUI 'logfile /var/log/redis/redis-server.log' 'logfile /var/log/redis/redis-webui.log'
replace_in_file $REDIS_WEBUI 'dbfilename dump.rdb' 'dbfilename dump-webui.rdb'
fi
if [[ $NON_MGMT_IP ]]; then
if [[ $NON_MGMT_IP != $COMPUTE_IP ]]; then
multi_net=true
vhost_ip=$NON_MGMT_IP
fi
fi
if [[ $PHYSICAL_INTERFACE ]];then
if [[ $(check_dev $PHYSICAL_INTERFACE) = "interface found" ]]; then
dev=$PHYSICAL_INTERFACE
else
echo "PHYSICAL INTERFACE NOT CONFIGURED"
fi
else
dev=$(get_device_by_ip $vhost_ip)
if [[ $multi_net ]]; then
compute_dev=$(get_device_by_ip $COMPUTE_IP)
fi
fi
if [[ $dev ]] && [[ $dev != "vhost0" ]]; then
mac=$(get_Mac $dev)
netmask=$(get_Mask $dev)
if [[ $multi_net ]]; then
gateway=$NON_MGMT_GW
else
gateway=$(find_gateway $dev)
fi
fi
i=0
if [[ ! multi_net ]]; then
if [[ $gateway ]]; then
echo "GATEWAY=$gateway" >> "/etc/contrail/ifcfg-vhost0"
fi
dns_list=()
dns_list+=$(get_dns_servers $dev)
for dns in ${dns_list[@]}
do
echo "DNS$i=$dev" >> "/etc/contrail/ifcfg-vhost0"
i=$((i+1))
done
domain_list=$(get_domain_search_list)
if [[ domain_list ]]; then
echo "DOMAIN=$domin_list" >> "/etc/contrail/ifcfg-vhost0"
fi
fi
prsv_cfg=()
mtu=$(get_if_mtu $dev)
if [[ $mtu ]]; then
dcfg="MTU=$mtu"
echo "$dcfg" >> "/etc/contrail/ifcfg-vhost0"
prsv_cfg+=(dcfg)
fi
sudo mv /etc/contrail/ifcfg-vhost0 /etc/sysconfig/network-scripts/ifcfg-vhost0
if [[ -f "/etc/sysconfig/network-scripts/ifcfg-$dev.rpmsave" ]]; then
sudo cp /etc/sysconfig/network-scripts/ifcfg-$dev /etc/sysconfig/network-scripts/ifcfg-$dev.rpmsave
fi
_rewrite_ifcfg_file /etc/contrail/ifcfg-$dev $dev $prsv_cfg
if [[ multi_net ]]; then
#migrate_routes $dev
:
fi
if [[ "$DISTRO" != "trusty" ]]; then
sudo chkconfig network on
else
sudo sysv-rc-conf network on
fi
}