adding SFA_CM_TYPE to the default CM configuration
[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_SM_HOST', 'SFA_SM_PORT',
16             'SFA_CM_ENABLED', 'SFA_CM_HOST', 'SFA_CM_PORT', 'SFA_CM_TYPE']
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     }
25
26 host_defaults = {
27     'SFA_REGISTRY_HOST': default_host,
28     'SFA_AGGREGATE_HOST': default_host,
29     'SFA_SM_HOST': default_host,    
30     }
31      
32 const_dict = {}
33 for key in all_vars:
34     value = ""
35     
36            
37     if key in defaults:
38         value = defaults[key]
39     elif hasattr(sfa_config, key):
40         value = getattr(sfa_config, key)
41         # sfa_config may specify localhost instead of a resolvalbe host or ip
42         # if so replace this with the host's address
43         if key in host_defaults and value in ['localhost', '127.0.0.1']:
44             value = host_defaults[key] 
45     const_dict[key] = value
46
47 filename = sfa_config.config_path + os.sep + 'sfa_component_config'
48 conffile = open(filename, 'w')
49 format='%s="%s"\n'
50
51 for var in all_vars:
52     conffile.write(format % (var, const_dict[var]))
53
54 conffile.close() 
55     
56