예제 #1
0
 def __init__(self, env):
     super().__init__()
     self.log = FullLogger()
     self.configuration = Configuration()
     self.mechanism_drivers = \
         self.configuration.environment['mechanism_drivers']
     self.env = env
     self.had_errors = False
     self.monitoring_config = self.db.monitoring_config_templates
     try:
         self.env_monitoring_config = self.configuration.get('Monitoring')
     except IndexError:
         self.env_monitoring_config = {}
     self.local_host = self.env_monitoring_config.get('server_ip', '')
     self.scripts_prepared_for_host = {}
     self.replacements = self.env_monitoring_config
     self.inv = InventoryMgr()
     self.config_db = self.db[self.inv.get_coll_name('monitoring_config')]
     self.provision = self.provision_levels['none']
     if self.env_monitoring_config:
         provision = self.env_monitoring_config.get('provision', 'none')
         provision = str.lower(provision)
         self.provision =\
             self.provision_levels.get(provision,
                                       self.provision_levels['none'])
예제 #2
0
 def __init__(self, env: str, inventory_collection: str):
     super().__init__()
     self.inv = InventoryMgr()
     self.inv.set_collections(inventory_collection)
     self.env = env
     self.log = FullLogger(env=env)
     self.handlers = {}
예제 #3
0
 def __init__(self, environments_collection="environments_config"):
     super().__init__()
     self.db_client = MongoAccess()
     self.db = MongoAccess.db
     self.inv = InventoryMgr()
     self.collection = self.inv.collections.get(environments_collection)
     self.env_name = None
     self.environment = None
     self.configuration = None
     self.log = FullLogger()
 def __init__(self, args):
     super().__init__()
     self.log = FullLogger()
     self.log.set_loglevel(args.loglevel)
     self.env = args.env
     try:
         self.conf = Configuration(args.mongo_config)
         self.inv = InventoryMgr()
         self.inv.log.set_loglevel(args.loglevel)
         self.inv.set_collections(args.inventory)
     except FileNotFoundError:
         sys.exit(1)
예제 #5
0
 def __init__(self,
              log_directory: str = None,
              mongo_config_file: str = None):
     super().__init__()
     if log_directory:
         FileLogger.LOG_DIRECTORY = log_directory
     MongoAccess.config_file = mongo_config_file
     self.log = FullLogger()
     self.conf = None
     self.inv = None
     self.collection = None
     self._update_document = None
     self.interval = self.MIN_INTERVAL
예제 #6
0
 def __init__(self, mongo_config="", ldap_config="",
              log_level="", inventory="", token_lifetime=86400):
     MongoAccess.set_config_file(mongo_config)
     self.inv = InventoryMgr()
     self.inv.set_collections(inventory)
     self.log = FullLogger()
     self.log.set_loglevel(log_level)
     self.ldap_access = LDAPAccess(ldap_config)
     Token.set_token_lifetime(token_lifetime)
     self.middleware = AuthenticationMiddleware()
     self.app = falcon.API(middleware=[self.middleware])
     self.app.add_error_handler(CalipsoApiException)
     self.set_routes(self.app)
예제 #7
0
 def __init__(self):
     self.get_args()
     MongoAccess.set_config_file(self.args.mongo_config)
     MongoAccess.__init__(self)
     self.log = FullLogger()
     self.log.set_loglevel(self.args.loglevel)
     self.conf = Configuration()
     self.inv = InventoryMgr()
     self.inv.set_collections(self.args.inventory)
     stats_coll = self.inv.get_coll_name('statistics')
     self.stats = self.db[stats_coll]
     # consume messages from topic
     self.consumer = KafkaConsumer('VPP.stats',
                                   group_id='calipso_test',
                                   auto_offset_reset=self.args.offset,
                                   bootstrap_servers=['localhost:9092'])
예제 #8
0
파일: auth.py 프로젝트: wherego2000/calipso
 def __init__(self):
     super().__init__()
     self.inv = InventoryMgr()
     self.log = FullLogger()
     self.tokens_coll = self.inv.collections['api_tokens']
     self.ldap_access = LDAPAccess()
예제 #9
0
    def listen(args: dict = None):

        args = setup_args(args, DefaultListener.DEFAULTS, get_args)
        if 'process_vars' not in args:
            args['process_vars'] = {}

        env_name = args["env"]
        inventory_collection = args["inventory"]

        MongoAccess.set_config_file(args["mongo_config"])
        inv = InventoryMgr()
        inv.set_collections(inventory_collection)
        conf = Configuration(args["environments_collection"])
        conf.use_env(env_name)

        event_handler = EventHandler(env_name, inventory_collection)
        event_queues = []

        env_config = conf.get_env_config()
        common_metadata_file = os.path.join(env_config.get('app_path', '/etc/calipso'),
                                            'config',
                                            DefaultListener.COMMON_METADATA_FILE)

        # import common metadata
        import_metadata(event_handler, event_queues, common_metadata_file)

        # import custom metadata if supplied
        if args["metadata_file"]:
            import_metadata(event_handler, event_queues, args["metadata_file"])

        logger = FullLogger()
        logger.set_loglevel(args["loglevel"])

        amqp_config = conf.get("AMQP")
        connect_url = 'amqp://{user}:{pwd}@{host}:{port}//' \
            .format(user=amqp_config["user"],
                    pwd=amqp_config["pwd"],
                    host=amqp_config["host"],
                    port=amqp_config["port"])

        with Connection(connect_url) as conn:
            try:
                print(conn)
                conn.connect()
                args['process_vars']['operational'] = OperationalStatus.RUNNING
                terminator = SignalHandler()
                worker = \
                    DefaultListener(connection=conn,
                                    event_handler=event_handler,
                                    event_queues=event_queues,
                                    retry_limit=args["retry_limit"],
                                    consume_all=args["consume_all"],
                                    inventory_collection=inventory_collection,
                                    env_name=env_name)
                worker.run()
                if terminator.terminated:
                    args.get('process_vars', {})['operational'] = \
                        OperationalStatus.STOPPED
            except KeyboardInterrupt:
                print('Stopped')
                args['process_vars']['operational'] = OperationalStatus.STOPPED
            except Exception as e:
                logger.log.exception(e)
                args['process_vars']['operational'] = OperationalStatus.ERROR
            finally:
                # This should enable safe saving of shared variables
                time.sleep(0.1)
예제 #10
0
 def __init__(self):
     super().__init__()
     self.log = FullLogger()
     self.inv = InventoryMgr()
예제 #11
0
 def __init__(self, config_file_path=""):
     super().__init__()
     self.log = FullLogger()
     self.ldap_params = self.get_ldap_params(config_file_path)
     self.server = self.connect_ldap_server()
예제 #12
0
 def __init__(self):
     super().__init__()
     self.env = None
     self.log = FullLogger()
     self.configuration = None