X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=config%2Fgen-sfa-cm-config.py;h=62f72ded15212f3b844cce6c689def3a028c7638;hb=0a9902d2a55a0a9ac03601345c4284293669012b;hp=8c2787159bf06d789949ae509dcdb0d17a868a5c;hpb=eede29d50da023aa04527429c75514b5692ba097;p=sfa.git diff --git a/config/gen-sfa-cm-config.py b/config/gen-sfa-cm-config.py old mode 100644 new mode 100755 index 8c278715..62f72ded --- a/config/gen-sfa-cm-config.py +++ b/config/gen-sfa-cm-config.py @@ -1,40 +1,55 @@ #!/usr/bin/python import os import sys +import socket sys.path.append('/usr/share/plc_api') from sfa.util.config import Config as SfaConfig from PLC.Config import Config as PlcConfig sfa_config = SfaConfig() plc_config = PlcConfig() +default_host = socket.gethostbyname(socket.gethostname()) all_vars = ['SFA_CONFIG_DIR', 'SFA_DATA_DIR', 'SFA_INTERFACE_HRN', - 'SFA_CM_SLICE_PREFIX', 'SFA_REGISTRY_HOST', 'SFA_REGISTRY_PORT', - 'SFA_AGGREGATE_HOST', 'SFA_AGGREGATE_PORT', + 'SFA_CM_SLICE_PREFIX', 'SFA_REGISTRY_HOST', 'SFA_REGISTRY_PORT', + 'SFA_AGGREGATE_HOST', 'SFA_AGGREGATE_PORT', 'SFA_SM_HOST', 'SFA_SM_PORT', - 'SFA_CM_ENABLED', 'SFA_CM_HOST', 'SFA_CM_PORT'] + 'SFA_CM_ENABLED', 'SFA_CM_HOST', 'SFA_CM_PORT', 'SFA_CM_TYPE', 'SFA_CM_SLICE_PREFIX', + 'SFA_API_LOGLEVEL'] + defaults = { 'SFA_CM_ENABLED': '1', 'SFA_CM_HOST': 'localhost', 'SFA_CM_PORT': '12346', - 'SFA_CM_SLICE_PREFIX': plc_config.PLC_SLICE_PREFIX - } - + 'SFA_CM_SLICE_PREFIX': plc_config.PLC_SLICE_PREFIX, + 'SFA_CM_TYPE': 'pl', + 'SFA_API_LOGLEVEL': '0' +} + +host_defaults = { + 'SFA_REGISTRY_HOST': default_host, + 'SFA_AGGREGATE_HOST': default_host, + 'SFA_SM_HOST': default_host, +} + const_dict = {} for key in all_vars: - value = "" + value = "" + if key in defaults: value = defaults[key] elif hasattr(sfa_config, key): value = getattr(sfa_config, key) + # sfa_config may specify localhost instead of a resolvalbe host or ip + # if so replace this with the host's address + if key in host_defaults and value in ['localhost', '127.0.0.1']: + value = host_defaults[key] const_dict[key] = value filename = sfa_config.config_path + os.sep + 'sfa_component_config' conffile = open(filename, 'w') -format='%s="%s"\n' +format = '%s="%s"\n' for var in all_vars: conffile.write(format % (var, const_dict[var])) -conffile.close() - - +conffile.close()