def load_configuration(): """Load configuration from files""" ### set config.BASE['INSTALL_PREFIX'] from POLARIS_INSTALL_PREFIX env try: config.BASE['INSTALL_PREFIX'] = \ os.environ['POLARIS_INSTALL_PREFIX'] except KeyError: raise Exception('POLARIS_INSTALL_PREFIX env is not set') ### optionally load BASE configuration ### base_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-pdns.yaml') if os.path.isfile(base_config_file): with open(base_config_file) as fp: base_config = yaml.load(fp) if base_config: # validate and set values for k in base_config: if k not in config.BASE: raise Exception('unknown configuration option "{}"' .format(k)) else: config.BASE[k] = base_config[k] ### optionally load TOPOLOGY_MAP configuration ### topology_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-topology.yaml') if os.path.isfile(topology_config_file): with open(topology_config_file) as fp: topology_config = yaml.load(fp) if topology_config: config.TOPOLOGY_MAP = \ topology.config_to_map(topology_config)
def load_configuration(): """Load configuration from files""" LOG.debug('loading Polaris health configuration') # set config.BASE['INSTALL_PREFIX'] from POLARIS_INSTALL_PREFIX env try: config.BASE['INSTALL_PREFIX'] = \ os.environ['POLARIS_INSTALL_PREFIX'] except KeyError: log_msg = 'POLARIS_INSTALL_PREFIX env is not set' LOG.error(log_msg) raise Error(log_msg) # optionally load BASE configuration base_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-health.yaml') if os.path.isfile(base_config_file): with open(base_config_file) as fp: base_config = yaml.load(fp) if base_config: # validate and set values for k in base_config: if k not in config.BASE: log_msg = ('unknown configuration option "{}"' .format(k)) LOG.error(log_msg) raise Error(log_msg) else: config.BASE[k] = base_config[k] # hard set file paths based on INSTALL_PREFIX config.BASE['PID_FILE'] = os.path.join( config.BASE['INSTALL_PREFIX'], 'run', 'polaris-health.pid') config.BASE['CONTROL_SOCKET_FILE'] = os.path.join( config.BASE['INSTALL_PREFIX'], 'run', 'polaris-health.controlsocket') # load LB configuration lb_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-lb.yaml') if not os.path.isfile(lb_config_file): log_msg = '{} does not exist'.format(lb_config_file) LOG.error(log_msg) raise Error(log_msg) else: with open(lb_config_file) as fp: config.LB = yaml.load(fp) # optionally load TOPOLOGY_MAP configuration topology_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-topology.yaml') if os.path.isfile(topology_config_file): with open(topology_config_file) as fp: topology_config = yaml.load(fp) if topology_config: config.TOPOLOGY_MAP = topology.config_to_map(topology_config)
def load_configuration(): """Load configuration from files""" LOG.debug('loading Polaris health configuration') ### set config.BASE['INSTALL_PREFIX'] from POLARIS_INSTALL_PREFIX env try: config.BASE['INSTALL_PREFIX'] = \ os.environ['POLARIS_INSTALL_PREFIX'] except KeyError: log_msg = 'POLARIS_INSTALL_PREFIX env is not set' LOG.error(log_msg) raise Error(log_msg) ### optionally load BASE configuration ### base_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-health.yaml') if os.path.isfile(base_config_file): with open(base_config_file) as fp: base_config = yaml.load(fp) if base_config: # validate and set values for k in base_config: if k not in config.BASE: log_msg =('unknown configuration option "{}"' .format(k)) LOG.error(log_msg) raise Error(log_msg) else: config.BASE[k] = base_config[k] # hard set file paths based on INSTALL_PREFIX config.BASE['PID_FILE'] = os.path.join( config.BASE['INSTALL_PREFIX'], 'run', 'polaris-health.pid') config.BASE['CONTROL_SOCKET_FILE'] = os.path.join( config.BASE['INSTALL_PREFIX'], 'run', 'polaris-health.controlsocket') ### load LB configuration ### lb_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-lb.yaml') if not os.path.isfile(lb_config_file): log_msg = '{} does not exist'.format(lb_config_file) LOG.error(log_msg) raise Error(log_msg) else: with open(lb_config_file) as fp: config.LB = yaml.load(fp) ### optionally load TOPOLOGY_MAP configuration ### topology_config_file = os.path.join( config.BASE['INSTALL_PREFIX'], 'etc', 'polaris-topology.yaml') if os.path.isfile(topology_config_file): with open(topology_config_file) as fp: topology_config = yaml.load(fp) if topology_config: config.TOPOLOGY_MAP = topology.config_to_map(topology_config)