Merge branch 'noslicemgr' into geni-v3
[sfa.git] / config / gen-sfa-cm-config.py
1 #!/usr/bin/python
2 import os
3 import sys
4 import socket
5 sys.path.append('/usr/share/plc_api')
6 from sfa.util.config import Config as SfaConfig
7 from PLC.Config import Config as PlcConfig
8
9 sfa_config = SfaConfig()
10 plc_config = PlcConfig()
11 default_host = socket.gethostbyname(socket.gethostname())
12 all_vars = ['SFA_CONFIG_DIR', 'SFA_DATA_DIR', 'SFA_INTERFACE_HRN',
13             'SFA_CM_SLICE_PREFIX', 'SFA_REGISTRY_HOST', 'SFA_REGISTRY_PORT',
14             'SFA_AGGREGATE_HOST', 'SFA_AGGREGATE_PORT',
15             'SFA_CM_ENABLED', 'SFA_CM_HOST', 'SFA_CM_PORT', 'SFA_CM_TYPE', 'SFA_CM_SLICE_PREFIX',
16             'SFA_API_LOGLEVEL']
17
18 defaults = {
19     'SFA_CM_ENABLED': '1',
20     'SFA_CM_HOST': 'localhost',
21     'SFA_CM_PORT': '12346',
22     'SFA_CM_SLICE_PREFIX': plc_config.PLC_SLICE_PREFIX,
23     'SFA_CM_TYPE': 'pl',
24     'SFA_API_LOGLEVEL': '0'
25 }
26
27 host_defaults = {
28     'SFA_REGISTRY_HOST': default_host,
29     'SFA_AGGREGATE_HOST': default_host,
30 }
31
32 const_dict = {}
33 for key in all_vars:
34     value = ""
35
36     if key in defaults:
37         value = defaults[key]
38     elif hasattr(sfa_config, key):
39         value = getattr(sfa_config, key)
40         # sfa_config may specify localhost instead of a resolvalbe host or ip
41         # if so replace this with the host's address
42         if key in host_defaults and value in ['localhost', '127.0.0.1']:
43             value = host_defaults[key]
44     const_dict[key] = value
45
46 filename = sfa_config.config_path + os.sep + 'sfa_component_config'
47 conffile = open(filename, 'w')
48 format = '%s="%s"\n'
49
50 for var in all_vars:
51     conffile.write(format % (var, const_dict[var]))
52
53 conffile.close()