Exemplo n.º 1
0
    def __init__(self,
                 spec_file_name,
                 config_handler,
                 command_handler,
                 cc_session=None,
                 handle_logging_config=True,
                 socket_file=None):
        """Initialize a ModuleCCSession. This does *NOT* send the
           specification and request the configuration yet. Use start()
           for that once the ModuleCCSession has been initialized.

           specfile_name is the path to the specification file.

           config_handler and command_handler are callback functions,
           see set_config_handler and set_command_handler for more
           information on their signatures.

           cc_session can be used to pass in an existing CCSession,
           if it is None, one will be set up. This is mainly intended
           for testing purposes.

           handle_logging_config: if True, the module session will
           automatically handle logging configuration for the module;
           it will read the system-wide Logging configuration and call
           the logger manager to apply it. It will also inform the
           logger manager when the logging configuration gets updated.
           The module does not need to do anything except initializing
           its loggers, and provide log messages. Defaults to true.

           socket_file: If cc_session was none, this optional argument
           specifies which socket file to use to connect to msgq. It
           will be overridden by the environment variable
           MSGQ_SOCKET_FILE. If none, and no environment variable is
           set, it will use the system default.
        """
        module_spec = isc.config.module_spec_from_file(spec_file_name)
        ConfigData.__init__(self, module_spec)

        self._module_name = module_spec.get_module_name()

        self.set_config_handler(config_handler)
        self.set_command_handler(command_handler)

        if not cc_session:
            self._session = Session(socket_file)
        else:
            self._session = cc_session
        self._session.group_subscribe(self._module_name, CC_INSTANCE_WILDCARD)

        self._remote_module_configs = {}
        self._remote_module_callbacks = {}

        self._notification_callbacks = {}
        self._last_notif_id = 0

        if handle_logging_config:
            self.add_remote_config(
                path_search('logging.spec', bind10_config.PLUGIN_PATHS),
                default_logconfig_handler)