def load_conf(xfile, options=None, envvar=None): signal.signal(signal.SIGTERM, stop) signal.signal(signal.SIGINT, stop) conf = {'_config_directory': None} if os.path.exists(xfile): with open(xfile, 'r') as f: conf = parse_conf(load_yaml(f)) conf['_config_directory'] = os.path.dirname(os.path.abspath(xfile)) elif envvar and os.environ.get(envvar): c = StringIO(os.environ[envvar]) conf = parse_conf(load_yaml(c.getvalue())) c.close() conf['_config_directory'] = None for x in ('modules', 'plugins'): conf = import_conf_files(x, conf) init_modules(conf) init_plugins(conf) if not conf.get('dns'): conf['dns'] = {} if conf['dns'] and conf['dns'].get('domains'): for name, domain_cfg in viewitems(conf['dns']['domains']): cfg = {'rrsets': [], 'vars': {}} for x in ('vars', 'rrsets'): if isinstance(cfg[x], list): append_func = getattr(cfg[x], 'extend') else: append_func = getattr(cfg[x], 'update') if domain_cfg.get("import_%s" % x): append_func( import_file(domain_cfg["import_%s" % x], conf['_config_directory'], cfg)) if x in domain_cfg: append_func(domain_cfg[x]) if not cfg['rrsets']: cfg = None if cfg: conf['dns']['domains'][name] = cfg if not options or not isinstance(options, object): return conf for def_option in iterkeys(get_default_options()): if getattr(options, def_option, None) is None \ and def_option in conf['general']: setattr(options, def_option, conf['general'][def_option]) setattr(options, 'configuration', conf) return options
def load_conf(xfile, options = None): signal.signal(signal.SIGTERM, stop) signal.signal(signal.SIGINT, stop) config_dir = os.path.dirname(os.path.abspath(xfile)) with open(xfile, 'r') as f: conf = parse_conf(load_yaml(f)) for name, module in six.iteritems(MODULES): LOG.info("module init: %r", name) module.init(conf) for x in ('module', 'plugin', 'filter'): path = conf['general'].get('%ss_path' % x) if path and os.path.isdir(path): DwhoLibLoader.load_dir(x, path) if not conf.get('endpoints'): raise CovenantConfigurationError("Missing 'endpoints' section in configuration") for name, ept_cfg in six.iteritems(conf['endpoints']): cfg = {'general': copy.copy(conf['general']), 'covenant': {'endpoint_name': name, 'config_dir': config_dir}, 'vars' : {}} metrics = [] probes = [] if 'plugin' not in ept_cfg: raise CovenantConfigurationError("Missing 'plugin' option in endpoint: %r" % name) if ept_cfg['plugin'] not in PLUGINS: raise CovenantConfigurationError("Invalid plugin %r in endpoint: %r" % (ept_cfg['plugin'], name)) cfg['covenant']['plugin_name'] = ept_cfg['plugin'] if ept_cfg.get('import_vars'): cfg['vars'].update(import_file(ept_cfg['import_vars'], config_dir, cfg)) if 'vars' in ept_cfg: cfg['vars'].update(copy.deepcopy(ept_cfg['vars'])) if ept_cfg.get('import_metrics'): metrics.extend(import_file(ept_cfg['import_metrics'], config_dir, cfg)) if 'metrics' in ept_cfg: metrics.extend(copy.deepcopy(ept_cfg['metrics'])) if ept_cfg.get('import_probes'): probes.extend(import_file(ept_cfg['import_probes'], config_dir, cfg)) if 'probes' in ept_cfg: probes.extend(copy.deepcopy(ept_cfg['probes'])) if not metrics and not probes: raise CovenantConfigurationError("Missing 'metrics' or 'probes' option in endpoint: %r" % name) if metrics and probes: raise CovenantConfigurationError("'metrics' and 'probes' aren't allowed in a same endpoint: %r" % name) cfg['credentials'] = None if ept_cfg.get('credentials'): cfg['credentials'] = ept_cfg['credentials'] cfg['metrics'] = metrics cfg['probes'] = probes endpoint = PLUGINS[ept_cfg['plugin']](name) ENDPOINTS.register(endpoint) LOG.info("endpoint init: %r", name) endpoint.init(cfg) LOG.info("endpoint safe_init: %r", name) endpoint.safe_init() DWHO_THREADS.append(endpoint.at_stop) if not options or not isinstance(options, object): return conf for def_option in six.iterkeys(get_default_options()): if getattr(options, def_option, None) is None \ and def_option in conf['general']: setattr(options, def_option, conf['general'][def_option]) setattr(options, 'configuration', conf) return options
def load_conf(xfile, options=None): signal.signal(signal.SIGTERM, stop) signal.signal(signal.SIGINT, stop) config_dir = os.path.dirname(os.path.abspath(xfile)) with open(xfile, 'r') as f: conf = parse_conf(load_yaml(f)) for name, module in MODULES.iteritems(): LOG.info("module init: %r", name) module.init(conf) for x in ('module', 'plugin'): path = conf['general'].get('%ss_path' % x) if path and os.path.isdir(path): DwhoLibLoader.load_dir(x, path) if not conf.get('endpoints'): raise FdReplayConfigurationError( "Missing 'endpoints' section in configuration") for name, ept_cfg in conf['endpoints'].iteritems(): cfg = { 'general': dict(conf['general']), 'fd-replay': { 'endpoint_name': name, 'config_dir': config_dir }, 'vars': {}, 'config': {} } if 'plugin' not in ept_cfg: raise FdReplayConfigurationError( "Missing 'plugin' option in endpoint: %r" % name) if ept_cfg['plugin'] not in PLUGINS: raise FdReplayConfigurationError( "Invalid plugin %r in endpoint: %r" % (ept_cfg['plugin'], name)) cfg['fd-replay']['plugin_name'] = ept_cfg['plugin'] for x in ('config', 'vars'): if ept_cfg.get("import_%s" % x): cfg[x].update( import_file(ept_cfg["import_%s" % x], config_dir, cfg)) if x in ept_cfg: cfg[x].update(dict(ept_cfg[x])) cfg['credentials'] = None if ept_cfg.get('credentials'): cfg['credentials'] = ept_cfg['credentials'] endpoint = PLUGINS[ept_cfg['plugin']](name) ENDPOINTS.register(endpoint) LOG.info("endpoint init: %r", name) endpoint.init(cfg) LOG.info("endpoint safe_init: %r", name) endpoint.safe_init() DWHO_THREADS.append(endpoint.at_stop) if not options or not isinstance(options, object): return conf for def_option in get_default_options().iterkeys(): if getattr(options, def_option, None) is None \ and def_option in conf['general']: setattr(options, def_option, conf['general'][def_option]) setattr(options, 'configuration', conf) return options