X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Fcmd%2Fpolicy_module_agent.py;fp=osm_policy_module%2Fcmd%2Fpolicy_module_agent.py;h=050cf32021d063243b4835697adb31decbfcb8d1;hb=a14cf16181c8b39f12c872c486e0b292c0068944;hp=49c7d3a40a3a3f154d6c23c80ef31ce524842b14;hpb=a96898dfaf088ac15560d15a7dcaf982c671ac2f;p=osm%2FPOL.git diff --git a/osm_policy_module/cmd/policy_module_agent.py b/osm_policy_module/cmd/policy_module_agent.py index 49c7d3a..050cf32 100644 --- a/osm_policy_module/cmd/policy_module_agent.py +++ b/osm_policy_module/cmd/policy_module_agent.py @@ -21,6 +21,7 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## +import argparse import asyncio import logging import sys @@ -31,27 +32,28 @@ from osm_policy_module.core.database import DatabaseManager def main(): - cfg = Config.instance() - log_formatter_str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' - logging.basicConfig(stream=sys.stdout, - format=log_formatter_str, - datefmt='%m/%d/%Y %I:%M:%S %p', - level=logging.getLevelName(cfg.OSMPOL_LOG_LEVEL)) - kafka_logger = logging.getLogger('kafka') - kafka_logger.setLevel(logging.getLevelName(cfg.OSMPOL_KAFKA_LOG_LEVEL)) - kafka_formatter = logging.Formatter(log_formatter_str) - kafka_handler = logging.StreamHandler(sys.stdout) - kafka_handler.setFormatter(kafka_formatter) - kafka_logger.addHandler(kafka_handler) + parser = argparse.ArgumentParser(prog='osm-policy-agent') + parser.add_argument('--config-file', nargs='?', help='POL configuration file') + args = parser.parse_args() + cfg = Config(args.config_file) + + root = logging.getLogger() + root.setLevel(logging.getLevelName(cfg.get('global', 'loglevel'))) + ch = logging.StreamHandler(sys.stdout) + ch.setLevel(logging.getLevelName(cfg.get('global', 'loglevel'))) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', '%m/%d/%Y %I:%M:%S %p') + ch.setFormatter(formatter) + root.addHandler(ch) + log = logging.getLogger(__name__) - log.info("Config: %s", vars(cfg)) - log.info("Syncing database...") + log.debug("Config: %s", cfg.conf) + log.info("Initializing database...") db_manager = DatabaseManager() - db_manager.create_tables() - log.info("Database synced correctly.") + db_manager.init_db(cfg) + log.info("Database initialized correctly.") log.info("Starting policy module agent...") loop = asyncio.get_event_loop() - agent = PolicyModuleAgent(loop) + agent = PolicyModuleAgent(cfg, loop) agent.run()