-
Notifications
You must be signed in to change notification settings - Fork 23
/
setup.py
executable file
·2118 lines (1917 loc) · 118 KB
/
setup.py
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
import argparse
import ConfigParser
import platform
import os
import sys
import time
import re
import string
import socket
import netifaces, netaddr
import subprocess
import fnmatch
import struct
import shutil
import json
from pprint import pformat
import xml.etree.ElementTree as ET
import platform
#dist = platform.dist()[0]
#if dist == 'centos':
# _tgt_path = os.path.abspath(os.path.dirname(sys.argv[0]))
# subprocess.call("sudo pip-python install %s/contrail_setup_utils/pycrypto-2.6.tar.gz" %(_tgt_path), shell=True)
# subprocess.call("sudo pip-python install %s/contrail_setup_utils/paramiko-1.11.0.tar.gz" %(_tgt_path), shell=True)
# subprocess.call("sudo pip-python install %s/contrail_setup_utils/Fabric-1.7.0.tar.gz" %(_tgt_path), shell=True)
# subprocess.call("sudo pip-python install %s/contrail_setup_utils/zope.interface-3.7.0.tar.gz" %(_tgt_path), shell=True)
import tempfile
from fabric.api import local, env, run
from fabric.operations import get, put
from fabric.context_managers import lcd, settings, hide
from fabric.api import local, env, run
from fabric.operations import get, put
from fabric.context_managers import lcd, settings
# Get Environment Stuff
env.password='c0ntrail123'
if os.getenv('PASSWORD') :
env.password=os.getenv('PASSWORD')
env.admin_username='admin'
if os.getenv('ADMIN_USERNAME') :
env.admin_username=os.getenv('ADMIN_USERNAME')
env.admin_token='contrail123'
if os.getenv('ADMIN_TOKEN') :
env.admin_token=os.getenv('ADMIN_TOKEN')
env.admin_tenant ='admin'
if os.getenv('ADMIN_TENANT') :
env.admin_tenant=os.getenv('ADMIN_TENANT')
# TODO following keystone credentials hardcoded
ks_admin_user = env.admin_username
ks_admin_password = env.admin_token
ks_admin_tenant_name = env.admin_tenant
contrail_bin_dir = '/opt/contrail/bin'
from contrail_config_templates import api_server_conf_template
from contrail_config_templates import quantum_conf_template
from contrail_config_templates import schema_transformer_conf_template
from contrail_config_templates import svc_monitor_conf_template
from contrail_config_templates import bgp_param_template
from contrail_config_templates import dns_param_template
from contrail_config_templates import vnswad_conf_template
from contrail_config_templates import discovery_conf_template
from contrail_config_templates import vizd_param_template
from contrail_config_templates import qe_param_template
from contrail_config_templates import opserver_param_template
from contrail_config_templates import vnc_api_lib_ini_template
from contrail_config_templates import agent_param_template
from contrail_config_templates import contrail_api_ini_template
from contrail_config_templates import contrail_api_ini_centos_template
from contrail_config_templates import contrail_api_svc_template
from contrail_config_templates import contrail_discovery_ini_template
from contrail_config_templates import contrail_discovery_ini_centos_template
from contrail_config_templates import contrail_discovery_svc_template
from contrail_config_templates import database_nodemgr_param_template
from contrail_config_templates import contrail_nodemgr_database_template
from contrail_config_templates import ifmap_ifmap_template
from contrail_config_templates import ifmap_basicauthusers_template
from contrail_config_templates import ifmap_authorization_template
from contrail_config_templates import ifmap_publisher_template
from contrail_config_templates import ifmap_log4j_template
from contrail_config_templates import keepalived_conf_template
from contrail_config_templates import galera_param_template
from contrail_config_templates import cmon_param_template
from contrail_config_templates import cmon_conf_template
from contrail_config_templates import wsrep_conf_template
from contrail_config_templates import wsrep_conf_centos_template
CONTRAIL_FEDORA_TEMPL = string.Template("""
[contrail_fedora_repo]
name=Contrail Fedora Repo
baseurl=file://$__contrail_fedora_path__
enabled=1
gpgcheck=0
""")
CONTRAIL_DEMO_TEMPL = string.Template("""
[contrail_demo_repo]
name=Contrail Demo Repo
baseurl=file://$__contrail_demo_path__
enabled=1
gpgcheck=0
""")
CASSANDRA_CONF = '/etc/cassandra/conf'
CASSANDRA_CONF_FILE = 'cassandra.yaml'
CASSANDRA_ENV_FILE = 'cassandra-env.sh'
class ExtList (list):
def findex (self, fun):
for i, x in enumerate (self):
if fun (x):
return i
raise LookupError, 'No matching element in list'
class Setup(object):
def __init__(self, args_str = None):
self._args = None
if not args_str:
args_str = ' '.join(sys.argv[1:])
self._parse_args(args_str)
self._setup_tgt_path = os.path.abspath(os.path.dirname(sys.argv[0]))
self._temp_dir_name = tempfile.mkdtemp()
self._fixed_qemu_conf = False
#end __init__
def _parse_args(self, args_str):
'''
Eg. python setup.py --role config --role control --cfgm_ip 127.0.0.1
[--use_certs [--puppet_server <fqdn>]] [--multi_tenancy]
'''
# Source any specified config/ini file
# Turn off help, so we print all options in response to -h
conf_parser = argparse.ArgumentParser(add_help = False)
conf_parser.add_argument("-c", "--conf_file",
help="Specify config file", metavar="FILE")
args, remaining_argv = conf_parser.parse_known_args(args_str.split())
global_defaults = {
'use_certs': False,
'puppet_server': None,
}
cfgm_defaults = {
'cfgm_ip': '127.0.0.1',
'keystone_ip': '127.0.0.1',
'service_token': '',
'n_api_workers': '1',
'multi_tenancy': False,
'haproxy': False,
'region_name': None,
'ks_auth_protocol':'http',
'ks_auth_port':'35357',
'ks_insecure':'False',
'amqp_server_ip': '127.0.0.1',
'manage_neutron' : True,
'contrail_internal_vip' : None,
}
openstack_defaults = {
'cfgm_ip': '127.0.0.1',
'service_token': '',
'haproxy': False,
'ks_auth_protocol':'http',
'amqp_server_ip': '127.0.0.1',
'quantum_service_protocol':'http',
'mgmt_self_ip' : None,
'internal_vip' : None,
'external_vip' : None,
}
control_node_defaults = {
'cfgm_ip': '127.0.0.1',
'collector_ip': '127.0.0.1',
'control_ip': '127.0.0.1',
}
compute_node_defaults = {
'compute_ip': '127.0.0.1',
'keystone_ip': '127.0.0.1',
'ks_auth_protocol':'http',
'service_token': '',
'haproxy': False,
'ncontrols' : 2,
'physical_interface': None,
'non_mgmt_ip': None,
'non_mgmt_gw': None,
'vgw_public_subnet': None,
'vgw_public_vn_name': None,
'vgw_intf_list': None,
'vgw_gateway_routes': None,
'amqp_server_ip': '127.0.0.1',
'amqp_server_ip_list': '127.0.0.1',
'quantum_service_protocol': 'http',
'no_contrail_openstack' : False
}
collector_defaults = {
'cfgm_ip': '127.0.0.1',
'self_collector_ip': '127.0.0.1',
}
database_defaults = {
'database_dir' : '/usr/share/cassandra',
'database_listen_ip' : '127.0.0.1',
'cfgm_ip': '127.0.0.1',
}
if args.conf_file:
config = ConfigParser.SafeConfigParser()
config.read([args.conf_file])
global_defaults.update(dict(config.items("GLOBAL")))
cfgm_defaults.update(dict(config.items("CFGM")))
openstack_defaults.update(dict(config.items("OPENSTACK")))
control_node_defaults.update(dict(config.items("CONTROL-NODE")))
compute_node_defaults.update(dict(config.items("COMPUTE-NODE")))
collector_defaults.update(dict(config.items("COLLECTOR")))
database_defaults.update(dict(config.items("DATABASE")))
# Override with CLI options
# Don't surpress add_help here so it will handle -h
parser = argparse.ArgumentParser(
# Inherit options from config_parser
parents=[conf_parser],
# print script description with -h/--help
description=__doc__,
# Don't mess with format of description
formatter_class=argparse.RawDescriptionHelpFormatter,
)
all_defaults = {'global': global_defaults,
'cfgm': cfgm_defaults,
'openstack': openstack_defaults,
'control-node': control_node_defaults,
'compute-node': compute_node_defaults,
'collector': collector_defaults,
'database': database_defaults,
}
parser.set_defaults(**all_defaults)
parser.add_argument("--role", action = 'append',
help = "Role of server (config, openstack, control, compute, collector, webui, database")
parser.add_argument("--cfgm_ip", help = "IP Address of Configuration Node")
parser.add_argument("--mgmt_self_ip", help = "Managment IP Address of any Node")
parser.add_argument("--openstack_ip", help = "IP Address of Openstack Node")
parser.add_argument("--internal_vip", help = "Internal VIP Address of HA Openstack Nodes")
parser.add_argument("--external_vip", help = "External VIP Address of HA Openstack Nodes")
parser.add_argument("--contrail_internal_vip", help = "Internal VIP Address of HA config Nodes")
parser.add_argument("--keystone_ip", help = "IP Address of Keystone Node")
parser.add_argument("--openstack_mgmt_ip", help = "Management IP Address of Openstack Node")
parser.add_argument("--collector_ip", help = "IP Address of Collector Node")
parser.add_argument("--discovery_ip", help = "IP Address of Discovery Node")
parser.add_argument("--control_ip", help = "IP Address of first Control Node (for control role)")
parser.add_argument("--ncontrols", help = "Number of Control Nodes in the system (for compute role)")
parser.add_argument("--compute_ip", help = "IP Address of Compute Node (for compute role)")
parser.add_argument("--service_token", help = "The service password to access keystone")
parser.add_argument("--region_name", help = "The Region Name in Openstack")
parser.add_argument("--haproxy", help = "Enable haproxy", action="store_true")
parser.add_argument("--no_contrail_openstack", help = "Do not provision contrail Openstack in compute node", action="store_true")
parser.add_argument("--manage_neutron", help = "Provision neutron in Keystone", action="store_true")
parser.add_argument("--physical_interface", help = "Name of the physical interface to use")
parser.add_argument("--non_mgmt_ip", help = "IP Address of non-management interface(fabric network) on the compute node")
parser.add_argument("--non_mgmt_gw", help = "Gateway Address of the non-management interface(fabric network) on the compute node")
parser.add_argument("--use_certs", help = "Use certificates for authentication",
action="store_true")
parser.add_argument("--vgw_public_subnet", help = "Subnet of the virtual network used for public access")
parser.add_argument("--vgw_public_vn_name", help = "Fully-qualified domain name (FQDN) of the routing-instance that needs public access")
parser.add_argument("--vgw_intf_list", help = "List of virtual getway intreface")
parser.add_argument("--vgw_gateway_routes", help = "Static route to be configured in agent configuration for VGW")
parser.add_argument("--ks_auth_protocol", help = "Protocol to use while talking to Keystone")
parser.add_argument("--ks_auth_port", help = "Port to use while talking to Keystone",default='35357')
parser.add_argument("--ks_admin_token", help = "Admin token to be used while talking to keystone",)
parser.add_argument("--ks_insecure", help = "Option to connect to keystone in secure/insecure mode when using https")
parser.add_argument("--quantum_service_protocol", help = "Protocol of quantum/neutron for nova to use ", default='http')
parser.add_argument("--amqp_server_ip", help = "IP of the AMQP Server used to configure openstack components",)
parser.add_argument("--amqp_server_ip_list", help = "IP list of the AMQP Server used to configure openstack components",
nargs = '+', type = str)
parser.add_argument("--puppet_server", help = "FQDN of Puppet Master")
parser.add_argument("--multi_tenancy", help = "Enforce resource permissions (implies keystone token validation)",
action="store_true")
parser.add_argument("--cassandra_ip_list", help = "IP Addresses of Cassandra Nodes", nargs = '+', type = str)
parser.add_argument("--zookeeper_ip_list", help = "IP Addresses of Zookeeper servers", nargs = '+', type = str)
parser.add_argument("--database_index", help = "Index of this database node")
parser.add_argument("--galera_ip_list", help = "IP Addresses of Galera servers", nargs = '+', type = str)
parser.add_argument("--openstack_ip_list", help = "IP Addresses of openstack Servers", nargs = '+', type = str)
parser.add_argument("--openstack_index", help = "Index of this openstack node", type = int)
parser.add_argument("--cfgm_index", help = "Index of this cfgm node", type = int)
parser.add_argument("--num_nodes", help = "Number of available nodes", type = int)
parser.add_argument("--quantum_port", help = "Quantum server port", default='9696')
parser.add_argument("--n_api_workers",
help="Number of API/discovery worker processes to be launched",
default='1')
parser.add_argument("--database_listen_ip", help = "Listen IP Address of database node", default = '127.0.0.1')
pdist = platform.dist()[0]
if pdist == 'fedora' or pdist == 'centos' or pdist == 'redhat':
parser.add_argument("--database_dir", help = "Directory where database binary exists", default = '/usr/share/cassandra')
if pdist == 'Ubuntu':
parser.add_argument("--database_dir", help = "Directory where database binary exists", default = '/etc/cassandra')
parser.add_argument("--data_dir", help = "Directory where database stores data")
parser.add_argument("--analytics_data_dir", help = "Directory where database stores data")
parser.add_argument("--ssd_data_dir", help = "Directory where database stores data")
parser.add_argument("--database_initial_token", help = "Initial token for database node")
parser.add_argument("--database_seed_list", help = "List of seed nodes for database", nargs='+')
parser.add_argument("--num_collector_nodes", help = "Number of Collector Nodes", type = int)
parser.add_argument("--self_collector_ip", help = "Self IP of Collector Node")
parser.add_argument("--analytics_data_ttl", help = "TTL in hours of analytics data stored in database", type = int, default = 24 * 2)
parser.add_argument("--analytics_syslog_port", help = "Listen port for analytics syslog server", type = int, default = -1)
parser.add_argument("--storage-master", help = "IP Address of storage master node")
parser.add_argument("--storage-hostnames", help = "Host names of storage nodes", nargs='+', type=str)
parser.add_argument("--storage-hosts", help = "IP Addresses of storage nodes", nargs='+', type=str)
parser.add_argument("--storage-host-tokens", help = "Passwords of storage nodes", nargs='+', type=str)
parser.add_argument("--storage-disk-config", help = "Disk list to be used for distributed storage", nargs="+", type=str)
parser.add_argument("--storage-ssd-disk-config", help = "SSD Disk list to be used for distributed storage", nargs="+", type=str)
parser.add_argument("--storage-local-disk-config", help = "Disk list to be used for local storage", nargs="+", type=str)
parser.add_argument("--storage-local-ssd-disk-config", help = "SSD Disk list to be used for local storage", nargs="+", type=str)
parser.add_argument("--storage-nfs-disk-config", help = "Disk list to be used for local storage", nargs="+", type=str)
parser.add_argument("--storage-journal-config", help = "Disk list to be used for distributed storage journal", nargs="+", type=str)
parser.add_argument("--storage-directory-config", help = "Directories to be sued for distributed storage", nargs="+", type=str)
parser.add_argument("--collector-hosts", help = "IP Addresses of collector nodes", nargs='+', type=str)
parser.add_argument("--collector-host-tokens", help = "Passwords of collector nodes", nargs='+', type=str)
parser.add_argument("--cfg-host", help = "IP Address of config node")
parser.add_argument("--live-migration", help = "Live migration enabled")
parser.add_argument("--nfs-live-migration", help = "NFS for Live migration enabled")
parser.add_argument("--nfs-livem-subnet", help = "Subnet for NFS for Live migration VM", nargs="+", type=str)
parser.add_argument("--nfs-livem-image", help = "Image for NFS for Live migration VM", nargs="+", type=str)
parser.add_argument("--nfs-livem-host", help = "Image for NFS for Live migration VM", nargs="+", type=str)
parser.add_argument("--nfs-livem-mount", help = "Mount of external NFS server", nargs="+", type=str)
parser.add_argument("--add-storage-node", help = "Dynamic addition of storage node")
parser.add_argument("--storage-webui-ip", help = "IP Address of storage webui node")
parser.add_argument("--storage-webui-mode", help = "Config mode Storage WebUI Status")
parser.add_argument("--storage-master-ip", help = "IP Address of storage master node")
parser.add_argument("--storage-setup-mode", help = "Storage configuration mode")
parser.add_argument("--vmware", help = "Vmware ESXI IP", type=str)
parser.add_argument("--vmware_username", help = "Vmware ESXI Username", type=str)
parser.add_argument("--vmware_passwd", help = "Vmware ESXI Password", type=str)
parser.add_argument("--vmware_vmpg_vswitch", help = "Vmware VMPG vswitch name", type=str)
self._args = parser.parse_args(remaining_argv)
#end _parse_args
def _template_substitute(self, template, vals):
data = template.safe_substitute(vals)
return data
#end _template_substitute
def _template_substitute_write(self, template, vals, filename):
data = self._template_substitute(template, vals)
outfile = open(filename, 'w')
outfile.write(data)
outfile.close()
#end _template_substitute_write
def _replaces_in_file(self, file, replacement_list):
rs = [ (re.compile(regexp), repl) for (regexp, repl) in replacement_list]
file_tmp = file + ".tmp"
with open(file, 'r') as f:
with open(file_tmp, 'w') as f_tmp:
for line in f:
for r, replace in rs:
match = r.search(line)
if match:
line = replace + "\n"
f_tmp.write(line)
shutil.move(file_tmp, file)
#end _replaces_in_file
def replace_in_file(self, file, regexp, replace):
self._replaces_in_file(file, [(regexp, replace)])
#end replace_in_file
def setup_crashkernel_params(self):
local(r"sed -i 's/crashkernel=.*\([ | \"]\)/crashkernel=384M-2G:64M,2G-16G:128M,16G-:256M\1/g' /etc/grub.d/10_linux")
local("update-grub")
def enable_kernel_core (self):
'''
enable_kernel_core:
update grub file
install grub2
enable services
'''
gcnf = ''
with open ('/etc/default/grub', 'r') as f:
gcnf = f.read ()
p = re.compile ('\s*GRUB_CMDLINE_LINUX')
el = ExtList (gcnf.split ('\n'))
try:
i = el.findex (p.match)
exec (el[i])
el[i] = 'GRUB_CMDLINE_LINUX="%s crashkernel=128M"' % (
' '.join (filter (lambda x: not x.startswith (
'crashkernel='), GRUB_CMDLINE_LINUX.split ())))
exec (el[i])
el[i] = 'GRUB_CMDLINE_LINUX="%s kvm-intel.nested=1"' % (
' '.join (filter (lambda x: not x.startswith (
'kvm-intel.nested='), GRUB_CMDLINE_LINUX.split ())))
with open ('%s/grub' % self._temp_dir_name, 'w') as f:
f.write ('\n'.join (el))
f.flush ()
local ('sudo mv %s/grub /etc/default/grub' % (self._temp_dir_name))
local ('sudo /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg')
if 'compute' in self._args.role :
local ('for s in abrt-vmcore abrtd kdump; do chkconfig ${s} on; done')
except LookupError:
print 'Improper grub file, kernel crash not enabled'
#end enable_kernel_core
def setup_repo(self):
with lcd("/etc/yum.repos.d/"):
ls_out = local("find . -maxdepth 1 -type f -name '*'", capture = True)
existing_repos = [ repo for repo in ls_out.split() if not re.match('./contrail*', repo) ]
if existing_repos:
with settings(warn_only = True):
local("sudo mkdir saved-repos")
for repo in existing_repos:
if repo == 'saved-repos':
continue
local("sudo mv %s saved-repos" %(repo))
self._template_substitute_write(CONTRAIL_FEDORA_TEMPL,
{'__contrail_fedora_path__': self._setup_tgt_path},
'%s/contrail_fedora.repo' %(self._temp_dir_name))
self._template_substitute_write(CONTRAIL_DEMO_TEMPL,
{'__contrail_demo_path__': self._setup_tgt_path},
'%s/contrail_demo.repo' %(self._temp_dir_name))
local("sudo mv %s/contrail_fedora.repo ." %(self._temp_dir_name))
local("sudo mv %s/contrail_demo.repo ." %(self._temp_dir_name))
with lcd("%s" %(self._setup_tgt_path)):
local("sudo createrepo .")
#end setup_repo
def install_packages(self):
local("sudo yum clean all")
if 'config' in self._args.role:
local("sudo yum -y install openstack-quantum contrail-config openstack-quantum-contrail mysql qpid-cpp-server mysql-server")
if 'openstack' in self._args.role:
local("sudo yum -y install openstack-nova openstack-cinder openstack-glance openstack-keystone mysql qpid-cpp-server openstack_dashboard mysql-server")
if 'control' in self._args.role:
local("sudo yum -y install contrail-control")
if 'collector' in self._args.role:
local("sudo yum -y install contrail-analytics")
if 'compute' in self._args.role :
local("sudo yum -y install contrail-vrouter openstack-utils openstack-nova-compute")
#end install_packages
def find_gateway (self, dev):
gateway = ''
gateway = local("netstat -rn | grep ^\"0.0.0.0\" | grep %s | awk '{ print $2 }'" % dev,
capture = True).strip()
return gateway
#end find_gateway
def get_dns_servers (self, dev):
dns_list = local("grep \"^nameserver\\>\" /etc/resolv.conf | awk '{print $2}'",
capture = True)
return dns_list.split()
#end get_dns_servers
def get_domain_search_list (self):
domain_list = ''
domain_list = local("grep ^\"search\" /etc/resolv.conf | awk '{$1=\"\";print $0}'", capture = True).strip()
if not domain_list:
domain_list = local("grep ^\"domain\" /etc/resolv.conf | awk '{$1=\"\"; print $0}'", capture = True).strip()
return domain_list
def get_if_mtu (self, dev):
mtu = local("ifconfig %s | grep mtu | awk '{ print $NF }'" % dev,
capture = True).strip ()
if not mtu:
# for debian
mtu = local(
r"ifconfig %s | grep MTU | sed 's/.*MTU.\([0-9]\+\).*/\1/g'" % dev,
capture = True).strip ()
if mtu and mtu != '1500': return mtu
return ''
#end if_mtu
def get_device_by_ip (self, ip):
for i in netifaces.interfaces ():
try:
if i == 'pkt1':
continue
if netifaces.ifaddresses (i).has_key (netifaces.AF_INET):
if ip == netifaces.ifaddresses (i)[netifaces.AF_INET][0][
'addr']:
if i == 'vhost0':
print "vhost0 is already present!"
# raise RuntimeError, 'vhost0 already running with %s'%ip
return i
except ValueError,e:
print "Skipping interface %s" % i
raise RuntimeError, '%s not configured, rerun w/ --physical_interface' % ip
#end get_device_by_ip
def get_secondary_device(self, primary):
for i in netifaces.interfaces ():
try:
if i == 'pkt1':
continue
if i == primary:
continue
if i == 'vhost0':
continue
if not netifaces.ifaddresses (i).has_key (netifaces.AF_INET):
return i
except ValueError,e:
print "Skipping interface %s" % i
raise RuntimeError, '%s not configured, rerun w/ --physical_interface' % ip
#end get_secondary_device
def _is_string_in_file(self, string, filename):
f_lines=[]
if os.path.isfile( filename ):
fd=open(ifcfg_file)
f_lines=fd.readlines()
fd.close()
#end if
found= False
for line in f_lines:
if string in line:
found= True
return found
#end _is_string_in_file
def _rewrite_ifcfg_file(self, filename, dev, prsv_cfg):
bond = False
mac = ''
temp_dir_name = self._temp_dir_name
vlan = False
if os.path.isfile ('/proc/net/vlan/%s' % dev):
vlan_info = open('/proc/net/vlan/config').readlines()
match = re.search('^%s.*\|\s+(\S+)$'%dev, "\n".join(vlan_info), flags=re.M|re.I)
if not match:
raise RuntimeError, 'Configured vlan %s is not found in /proc/net/vlan/config'%dev
phydev = match.group(1)
vlan = True
if os.path.isdir ('/sys/class/net/%s/bonding' % dev):
bond = True
# end if os.path.isdir...
mac = netifaces.ifaddresses(dev)[netifaces.AF_LINK][0]['addr']
ifcfg_file='/etc/sysconfig/network-scripts/ifcfg-%s' %(dev)
if not os.path.isfile( ifcfg_file ):
ifcfg_file = temp_dir_name + 'ifcfg-' + dev
with open (ifcfg_file, 'w') as f:
f.write ('''#Contrail %s
TYPE=Ethernet
ONBOOT=yes
DEVICE="%s"
USERCTL=yes
NM_CONTROLLED=no
HWADDR=%s
''' % (dev, dev, mac))
for dcfg in prsv_cfg:
f.write(dcfg+'\n')
if vlan:
f.write('VLAN=yes\n')
fd=open(ifcfg_file)
f_lines=fd.readlines()
fd.close()
local("sudo rm -f %s" %ifcfg_file)
new_f_lines=[]
remove_items=['IPADDR', 'NETMASK', 'PREFIX', 'GATEWAY', 'HWADDR',
'DNS1', 'DNS2', 'BOOTPROTO', 'NM_CONTROLLED', '#Contrail']
remove_items.append('DEVICE')
new_f_lines.append('#Contrail %s\n' % dev)
new_f_lines.append('DEVICE=%s\n' % dev)
for line in f_lines:
found=False
for text in remove_items:
if text in line:
found=True
if not found:
new_f_lines.append(line)
new_f_lines.append('NM_CONTROLLED=no\n')
if bond:
new_f_lines.append('SUBCHANNELS=1,2,3\n')
else:
new_f_lines.append('HWADDR=%s\n' % mac)
fdw=open(filename,'w')
fdw.writelines(new_f_lines)
fdw.close()
def migrate_routes(self, device):
'''
Sample output of /proc/net/route :
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
p4p1 00000000 FED8CC0A 0003 0 0 0 00000000 0 0 0
'''
temp_dir_name = self._temp_dir_name
cfg_file = '/etc/sysconfig/network-scripts/route-vhost0'
tmp_file = '%s/route-vhost0'%(temp_dir_name)
with open(tmp_file, 'w') as route_cfg_file:
for route in open('/proc/net/route', 'r').readlines():
if route.startswith(device):
route_fields = route.split()
destination = int(route_fields[1], 16)
gateway = int(route_fields[2], 16)
flags = int(route_fields[3], 16)
mask = int(route_fields[7], 16)
if flags & 0x2:
if destination != 0:
route_cfg_file.write(socket.inet_ntoa(struct.pack('I', destination)))
route_cfg_file.write('/' + str(bin(mask).count('1')) + ' ')
route_cfg_file.write('via ')
route_cfg_file.write(socket.inet_ntoa(struct.pack('I', gateway)) + ' ')
route_cfg_file.write('dev vhost0')
#end if detination...
#end if flags &...
#end if route.startswith...
#end for route...
#end with open...
local("sudo mv -f %s %s" %(tmp_file, cfg_file))
#delete the route-dev file
if os.path.isfile('/etc/sysconfig/network-scripts/route-%s'%device):
os.unlink('/etc/sysconfig/network-scripts/route-%s'%device)
#end def migrate_routes
def _rewrite_net_interfaces_file(self, dev, mac, vhost_ip, netmask, gateway_ip):
with settings(warn_only = True):
result = local('grep \"iface vhost0\" /etc/network/interfaces')
if result.succeeded :
print "Interface vhost0 is already present in /etc/network/interfaces"
print "Skipping rewrite of this file"
return
#endif
vlan = False
if os.path.isfile ('/proc/net/vlan/%s' % dev):
vlan_info = open('/proc/net/vlan/config').readlines()
match = re.search('^%s.*\|\s+(\S+)$'%dev, "\n".join(vlan_info), flags=re.M|re.I)
if not match:
raise RuntimeError, 'Configured vlan %s is not found in /proc/net/vlan/config'%dev
phydev = match.group(1)
vlan = True
# Replace strings matching dev to vhost0 in ifup and ifdown parts file
# Any changes to the file/logic with static routes has to be
# reflected in setup-vnc-static-routes.py too
ifup_parts_file = os.path.join(os.path.sep, 'etc', 'network', 'if-up.d', 'routes')
ifdown_parts_file = os.path.join(os.path.sep, 'etc', 'network', 'if-down.d', 'routes')
if os.path.isfile(ifup_parts_file) and os.path.isfile(ifdown_parts_file):
with settings(warn_only = True):
local("sudo sed -i 's/%s/vhost0/g' %s" %(dev, ifup_parts_file))
local("sudo sed -i 's/%s/vhost0/g' %s" %(dev, ifdown_parts_file))
temp_intf_file = '%s/interfaces' %(self._temp_dir_name)
local("cp /etc/network/interfaces %s" %(temp_intf_file))
with open('/etc/network/interfaces', 'r') as fd:
cfg_file = fd.read()
if not self._args.non_mgmt_ip:
# remove entry from auto <dev> to auto excluding these pattern
# then delete specifically auto <dev>
local("sed -i '/auto %s/,/auto/{/auto/!d}' %s" %(dev, temp_intf_file))
local("sed -i '/auto %s/d' %s" %(dev, temp_intf_file))
# add manual entry for dev
local("echo 'auto %s' >> %s" %(dev, temp_intf_file))
local("echo 'iface %s inet manual' >> %s" %(dev, temp_intf_file))
local("echo ' pre-up ifconfig %s up' >> %s" %(dev, temp_intf_file))
local("echo ' post-down ifconfig %s down' >> %s" %(dev, temp_intf_file))
if vlan:
local("echo ' vlan-raw-device %s' >> %s" %(phydev, temp_intf_file))
if 'bond' in dev.lower():
iters = re.finditer('^\s*auto\s', cfg_file, re.M)
indices = [match.start() for match in iters]
matches = map(cfg_file.__getslice__, indices, indices[1:] + [len(cfg_file)])
for each in matches:
each = each.strip()
if re.match('^auto\s+%s'%dev, each):
string = ''
for lines in each.splitlines():
if 'bond-' in lines:
string += lines+os.linesep
local("echo '%s' >> %s" %(string, temp_intf_file))
else:
continue
local("echo '' >> %s" %(temp_intf_file))
else:
#remove ip address and gateway
with settings(warn_only = True):
local("sed -i '/iface %s inet static/, +2d' %s" % (dev, temp_intf_file))
local("sed -i '/auto %s/ a\iface %s inet manual\\n pre-up ifconfig %s up\\n post-down ifconfig %s down\' %s"% (dev, dev, dev, dev, temp_intf_file))
# populte vhost0 as static
local("echo '' >> %s" %(temp_intf_file))
local("echo 'auto vhost0' >> %s" %(temp_intf_file))
local("echo 'iface vhost0 inet static' >> %s" %(temp_intf_file))
local("echo ' pre-up %s/if-vhost0' >> %s" %(contrail_bin_dir, temp_intf_file))
local("echo ' netmask %s' >> %s" %(netmask, temp_intf_file))
local("echo ' network_name application' >> %s" %(temp_intf_file))
if vhost_ip:
local("echo ' address %s' >> %s" %(vhost_ip, temp_intf_file))
if (not self._args.non_mgmt_ip) and gateway_ip:
local("echo ' gateway %s' >> %s" %(gateway_ip, temp_intf_file))
domain = self.get_domain_search_list()
if domain:
local("echo ' dns-search %s' >> %s" %(domain, temp_intf_file))
dns_list = self.get_dns_servers(dev)
if dns_list:
local("echo -n ' dns-nameservers' >> %s" %(temp_intf_file))
for dns in dns_list:
local("echo -n ' %s' >> %s" %(dns, temp_intf_file))
local("echo '\n' >> %s" %(temp_intf_file))
# move it to right place
local("sudo mv -f %s /etc/network/interfaces" %(temp_intf_file))
#end _rewrite_net_interfaces_file
def fixup_config_files(self):
pdist = platform.dist()[0]
temp_dir_name = self._temp_dir_name
hostname = socket.gethostname()
cfgm_ip = self._args.cfgm_ip
collector_ip = self._args.collector_ip
use_certs = True if self._args.use_certs else False
contrail_openstack = not(getattr(self._args, 'no_contrail_openstack', False))
nova_conf_file = "/etc/nova/nova.conf"
cinder_conf_file = "/etc/cinder/cinder.conf"
if (os.path.isdir("/etc/openstack_dashboard")):
dashboard_setting_file = "/etc/openstack_dashboard/local_settings"
else:
dashboard_setting_file = "/etc/openstack-dashboard/local_settings"
if pdist == 'Ubuntu':
local("ln -sf /bin/true /sbin/chkconfig")
# TODO till post of openstack-horizon.spec is fixed...
if 'openstack' in self._args.role:
if pdist == 'fedora' or pdist == 'centos' or pdist == 'redhat':
local("sudo sed -i 's/ALLOWED_HOSTS =/#ALLOWED_HOSTS =/g' %s" %(dashboard_setting_file))
if os.path.exists(nova_conf_file):
local("sudo sed -i 's/rpc_backend = nova.openstack.common.rpc.impl_qpid/#rpc_backend = nova.openstack.common.rpc.impl_qpid/g' %s" \
% (nova_conf_file))
if os.path.exists(cinder_conf_file):
local("sudo sed -i 's/rpc_backend = cinder.openstack.common.rpc.impl_qpid/#rpc_backend = cinder.openstack.common.rpc.impl_qpid/g' %s" \
% (cinder_conf_file))
"""
glance_ver = local('rpm -q --qf "%{VERSION}\n" openstack-glance')
local('sed -ibak "s/max_connections.*/max_connections=10000/" %s' % self.mysql_conf)
"""
# Put hostname/ip mapping into /etc/hosts to avoid DNS resolution failing at bootup (Cassandra can fail)
if 'database' in self._args.role:
database_listen_ip = self._args.database_listen_ip
hosts_entry = '%s %s' %(database_listen_ip, hostname)
with settings( warn_only= True) :
local('grep -q \'%s\' /etc/hosts || echo \'%s\' >> /etc/hosts' %(database_listen_ip, hosts_entry))
if contrail_openstack:
# Disable selinux
with lcd(temp_dir_name):
with settings(warn_only = True):
local("sudo sed 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config > config.new")
local("sudo mv config.new /etc/selinux/config")
local("setenforce 0")
# cleanup in case move had error
local("rm config.new")
# Disable iptables
with settings(warn_only = True):
local("sudo chkconfig iptables off")
local("sudo iptables --flush")
# usable core dump
initf = '/etc/sysconfig/init'
with settings(warn_only = True):
local("sudo sed '/DAEMON_COREFILE_LIMIT=.*/d' %s > %s.new" %(initf, initf))
local("sudo mv %s.new %s" %(initf, initf))
if pdist == 'centos' or pdist == 'fedora' or pdist == 'redhat':
core_unlim = "echo DAEMON_COREFILE_LIMIT=\"'unlimited'\""
local("%s >> %s" %(core_unlim, initf))
if pdist == 'Ubuntu':
local('mkdir -p /var/crash')
#Core pattern
pattern= 'kernel.core_pattern = /var/crashes/core.%e.%p.%h.%t'
ip_fwd_setting = 'net.ipv4.ip_forward = 1'
sysctl_file = '/etc/sysctl.conf'
print pattern
with settings( warn_only= True) :
local('grep -q \'%s\' /etc/sysctl.conf || echo \'%s\' >> /etc/sysctl.conf' %(pattern, pattern))
local("sudo sed 's/net.ipv4.ip_forward.*/%s/g' %s > /tmp/sysctl.new" %(ip_fwd_setting,sysctl_file))
local("sudo mv /tmp/sysctl.new %s" %(sysctl_file))
local("rm /tmp/sysctl.new")
local('sysctl -p')
local('mkdir -p /var/crashes')
try:
if pdist == 'fedora' or pdist == 'centos' or pdist == 'redhat':
self.enable_kernel_core ()
if pdist == 'Ubuntu':
self.setup_crashkernel_params()
except Exception as e:
print "Ignoring failure kernel core dump"
with settings(warn_only = True):
# analytics venv instalation
if os.path.exists('/opt/contrail/analytics-venv/archive') and os.path.exists('/opt/contrail/analytics-venv/bin/activate'):
with lcd("/opt/contrail/analytics-venv/archive"):
if os.listdir('/opt/contrail/analytics-venv/archive'):
local("bash -c 'source ../bin/activate && pip install *'")
# api venv instalation
if os.path.exists('/opt/contrail/api-venv/archive') and os.path.exists('/opt/contrail/api-venv/bin/activate'):
with lcd("/opt/contrail/api-venv/archive"):
if os.listdir('/opt/contrail/api-venv/archive'):
local("bash -c 'source ../bin/activate && pip install *'")
# vrouter venv instalation
if os.path.exists('/opt/contrail/vrouter-venv/archive') and os.path.exists('/opt/contrail/vrouter-venv/bin/activate'):
with lcd("/opt/contrail/vrouter-venv/archive"):
if os.listdir('/opt/contrail/vrouter-venv/archive'):
local("bash -c 'source ../bin/activate && pip install *'")
# control venv instalation
if os.path.exists('/opt/contrail/control-venv/archive') and os.path.exists('/opt/contrail/control-venv/bin/activate'):
with lcd("/opt/contrail/control-venv/archive"):
if os.listdir('/opt/contrail/control-venv/archive'):
local("bash -c 'source ../bin/activate && pip install *'")
# database venv instalation
if os.path.exists('/opt/contrail/database-venv/archive') and os.path.exists('/opt/contrail/database-venv/bin/activate'):
with lcd("/opt/contrail/database-venv/archive"):
if os.listdir('/opt/contrail/database-venv/archive'):
local("bash -c 'source ../bin/activate && pip install *'")
if 'openstack' in self._args.role:
pdist = platform.dist()[0]
if pdist in ['Ubuntu']:
mysql_conf = '/etc/mysql/my.cnf'
elif pdist in ['centos', 'redhat']:
mysql_conf = '/etc/my.cnf'
local('sed -i -e "s/bind-address/#bind-address/" %s' % mysql_conf)
self.service_token = self._args.service_token
if not self.service_token:
local("sudo ./contrail_setup_utils/setup-service-token.sh")
with settings(warn_only = True):
#comment out parameters from /etc/nova/api-paste.ini
local("sudo sed -i 's/auth_host = /;auth_host = /' /etc/nova/api-paste.ini")
local("sudo sed -i 's/auth_port = /;auth_port = /' /etc/nova/api-paste.ini")
local("sudo sed -i 's/auth_protocol = /;auth_protocol = /' /etc/nova/api-paste.ini")
local("sudo sed -i 's/admin_tenant_name = /;admin_tenant_name = /' /etc/nova/api-paste.ini")
local("sudo sed -i 's/admin_user = /;admin_user = /' /etc/nova/api-paste.ini")
local("sudo sed -i 's/admin_password = /;admin_password = /' /etc/nova/api-paste.ini")
#comment out parameters from /etc/cinder/api-paste.ini
local("sudo sed -i 's/auth_host = /;auth_host = /' /etc/cinder/api-paste.ini")
local("sudo sed -i 's/auth_port = /;auth_port = /' /etc/cinder/api-paste.ini")
local("sudo sed -i 's/auth_protocol = /;auth_protocol = /' /etc/cinder/api-paste.ini")
local("sudo sed -i 's/admin_tenant_name = /;admin_tenant_name = /' /etc/cinder/api-paste.ini")
local("sudo sed -i 's/admin_user = /;admin_user = /' /etc/cinder/api-paste.ini")
local("sudo sed -i 's/admin_password = /;admin_password = /' /etc/cinder/api-paste.ini")
if (contrail_openstack and 'compute' in self._args.role):
with settings(warn_only = True):
if pdist == 'Ubuntu':
cmd = "dpkg -l | grep 'ii' | grep nova-compute | grep -v vif | grep -v nova-compute-kvm | awk '{print $3}'"
nova_compute_version = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
if (nova_compute_version != "2:2013.1.3-0ubuntu1"):
local("openstack-config --set /etc/nova/nova.conf DEFAULT neutron_admin_auth_url http://%s:5000/v2.0" % self._args.keystone_ip)
if os.path.exists(nova_conf_file):
local("sudo sed -i 's/rpc_backend = nova.openstack.common.rpc.impl_qpid/#rpc_backend = nova.openstack.common.rpc.impl_qpid/g' %s" \
% (nova_conf_file))
if ('config' in self._args.role or
(contrail_openstack and 'compute' in self._args.role) or
'openstack' in self._args.role):
# check if service token passed as argument else
# get service token from openstack(role) node and fix local config
self.service_token = self._args.service_token
self.haproxy = self._args.haproxy
keystone_ip = self._args.keystone_ip
ks_auth_protocol = self._args.ks_auth_protocol
compute_ip = self._args.compute_ip
cfgm_ip = self._args.cfgm_ip
quantum_port = self._args.quantum_port
quantum_service_protocol = self._args.quantum_service_protocol
if not self.service_token:
with settings(host_string = 'root@%s' %(keystone_ip), password = env.password):
get("/etc/contrail/service.token", temp_dir_name)
tok_fd = open('%s/service.token' %(temp_dir_name))
self.service_token = tok_fd.read().strip()
tok_fd.close()
local("cp -f %s/service.token /etc/contrail/service.token" % temp_dir_name)
local("rm %s/service.token" %(temp_dir_name))
local("echo 'SERVICE_TOKEN=%s' >> %s/ctrl-details"
%(self.service_token, temp_dir_name))
local("echo 'AUTH_PROTOCOL=%s' >> %s/ctrl-details"
%(ks_auth_protocol, temp_dir_name))
local("echo 'QUANTUM_PROTOCOL=%s' >> %s/ctrl-details"
%(quantum_service_protocol, temp_dir_name))
local("echo 'ADMIN_TOKEN=%s' >> %s/ctrl-details" %(ks_admin_password, temp_dir_name))
local("echo 'CONTROLLER=%s' >> %s/ctrl-details" %(keystone_ip, temp_dir_name))
if self._args.mgmt_self_ip:
local("echo 'SELF_MGMT_IP=%s' >> %s/ctrl-details" %(self._args.mgmt_self_ip, temp_dir_name))
if self._args.openstack_ip_list:
local("echo 'MEMCACHED_SERVERS=%s' >> %s/ctrl-details" % (':11211,'.join(self._args.openstack_ip_list) + ':11211', temp_dir_name))
#if 'compute' in self._args.role:
# local("echo 'AMQP_SERVER=%s' >> %s/ctrl-details" % (':5672,'.join(self._args.amqp_server_ip_list) + ':5672', temp_dir_name))
#else:
# local("echo 'AMQP_SERVER=%s' >> %s/ctrl-details" % (self._args.amqp_server_ip, temp_dir_name))
local("echo 'AMQP_SERVER=%s' >> %s/ctrl-details" % (self._args.amqp_server_ip, temp_dir_name))
if self.haproxy:
local("echo 'QUANTUM=127.0.0.1' >> %s/ctrl-details" %(temp_dir_name))
else:
local("echo 'QUANTUM=%s' >> %s/ctrl-details" %(cfgm_ip, temp_dir_name))
local("echo 'QUANTUM_PORT=%s' >> %s/ctrl-details" %(quantum_port,
temp_dir_name))
local("echo 'COMPUTE=%s' >> %s/ctrl-details" %(compute_ip, temp_dir_name))
if 'compute' in self._args.role:
local("echo 'CONTROLLER_MGMT=%s' >> %s/ctrl-details" %(self._args.openstack_mgmt_ip, temp_dir_name))
if self._args.vmware:
local("echo 'VMWARE_IP=%s' >> %s/ctrl-details" %(self._args.vmware, temp_dir_name))
local("echo 'VMWARE_USERNAME=%s' >> %s/ctrl-details" %(self._args.vmware_username, temp_dir_name))
local("echo 'VMWARE_PASSWD=%s' >> %s/ctrl-details" %(self._args.vmware_passwd, temp_dir_name))
local("echo 'VMWARE_VMPG_VSWITCH=%s' >> %s/ctrl-details" %(self._args.vmware_vmpg_vswitch, temp_dir_name))
if self._args.internal_vip:
local("echo 'INTERNAL_VIP=%s' >> %s/ctrl-details" % (self._args.internal_vip, temp_dir_name))
if self._args.contrail_internal_vip:
local("echo 'CONTRAIL_INTERNAL_VIP=%s' >> %s/ctrl-details" % (self._args.contrail_internal_vip, temp_dir_name))
if self._args.external_vip:
local("echo 'EXTERNAL_VIP=%s' >> %s/ctrl-details" % (self._args.external_vip, temp_dir_name))
if self._args.openstack_index:
local("echo 'OPENSTACK_INDEX=%s' >> %s/ctrl-details" % (self._args.openstack_index, temp_dir_name))
local("sudo cp %s/ctrl-details /etc/contrail/ctrl-details" %(temp_dir_name))
local("rm %s/ctrl-details" %(temp_dir_name))
if os.path.exists("/etc/neutron/neutron.conf"):
openstack_network_conf_file = "/etc/neutron/neutron.conf"
network_service = "neutron"
local("sudo sed -i 's/rpc_backend\s*=\s*%s.openstack.common.rpc.impl_qpid/#rpc_backend = %s.openstack.common.rpc.impl_qpid/g' %s" \
% (network_service, network_service, openstack_network_conf_file))
elif os.path.exists("/etc/quantum/quantum.conf"):
openstack_network_conf_file = "/etc/quantum/quantum.conf"
network_service = "quantum"
local("sudo sed -i 's/rpc_backend\s*=\s*%s.openstack.common.rpc.impl_qpid/#rpc_backend = %s.openstack.common.rpc.impl_qpid/g' %s" \
% (network_service, network_service, openstack_network_conf_file))
if 'database' in self._args.role:
if pdist == 'fedora' or pdist == 'centos' or pdist == 'redhat':
CASSANDRA_CONF = '/etc/cassandra/conf'
CASSANDRA_CONF_FILE = 'cassandra.yaml'
CASSANDRA_ENV_FILE = 'cassandra-env.sh'
if pdist == 'Ubuntu':
CASSANDRA_CONF = '/etc/cassandra/'
CASSANDRA_CONF_FILE = 'cassandra.yaml'
CASSANDRA_ENV_FILE = 'cassandra-env.sh'
listen_ip = self._args.database_listen_ip
cassandra_dir = self._args.database_dir
initial_token = self._args.database_initial_token
seed_list = self._args.database_seed_list
data_dir = self._args.data_dir
analytics_data_dir = self._args.analytics_data_dir
ssd_data_dir = self._args.ssd_data_dir
if not cassandra_dir:
raise ArgumentError('Undefined cassandra directory')
conf_dir = CASSANDRA_CONF
cnd = os.path.exists(conf_dir)
conf_file = os.path.join(conf_dir, CASSANDRA_CONF_FILE)
cnd = cnd and os.path.exists(conf_file)
if not cnd:
raise ArgumentError('%s does not appear to be a cassandra source directory' % cassandra_dir)
self.replace_in_file(conf_file, 'listen_address: ', 'listen_address: ' + listen_ip)
self.replace_in_file(conf_file, 'cluster_name: ', 'cluster_name: \'Contrail\'')
self.replace_in_file(conf_file, 'rpc_address: ', 'rpc_address: ' + listen_ip)