Exemple #1
0
 def add_remote_config_by_name(self, module_name,
                               config_update_callback=None):
     """
     This does the same as add_remote_config, but you provide the module name
     instead of the name of the spec file.
     """
     seq = self._session.group_sendmsg(create_command(COMMAND_GET_MODULE_SPEC,
                                                      { "module_name":
                                                      module_name }),
                                       "ConfigManager")
     try:
         answer, env = self._session.group_recvmsg(False, seq)
     except isc.cc.SessionTimeout:
         raise ModuleCCSessionError("No answer from ConfigManager when " +
                                    "asking about for spec of Remote " +
                                    "module " + module_name)
     if answer:
         rcode, value = parse_answer(answer)
         if rcode == 0:
             module_spec = isc.config.module_spec.ModuleSpec(value)
             if module_spec.get_module_name() != module_name:
                 raise ModuleCCSessionError("Module name mismatch: " +
                                            module_name + " and " +
                                            module_spec.get_module_name())
             self._add_remote_config_internal(module_spec,
                                              config_update_callback)
         else:
             raise ModuleCCSessionError("Error code " + str(rcode) +
                                        "when asking for module spec of " +
                                        module_name)
     else:
         raise ModuleCCSessionError("No answer when asking for module " +
                                    "spec of " + module_name)
     # Just to be consistent with the add_remote_config
     return module_name
Exemple #2
0
 def add_remote_config_by_name(self,
                               module_name,
                               config_update_callback=None):
     """
     This does the same as add_remote_config, but you provide the module name
     instead of the name of the spec file.
     """
     seq = self._session.group_sendmsg(
         create_command(COMMAND_GET_MODULE_SPEC,
                        {"module_name": module_name}), "ConfigManager")
     try:
         answer, env = self._session.group_recvmsg(False, seq)
     except isc.cc.SessionTimeout:
         raise ModuleCCSessionError("No answer from ConfigManager when " +
                                    "asking about for spec of Remote " +
                                    "module " + module_name)
     if answer:
         rcode, value = parse_answer(answer)
         if rcode == 0:
             module_spec = isc.config.module_spec.ModuleSpec(value)
             if module_spec.get_module_name() != module_name:
                 raise ModuleCCSessionError("Module name mismatch: " +
                                            module_name + " and " +
                                            module_spec.get_module_name())
             self._add_remote_config_internal(module_spec,
                                              config_update_callback)
         else:
             raise ModuleCCSessionError("Error code " + str(rcode) +
                                        "when asking for module spec of " +
                                        module_name)
     else:
         raise ModuleCCSessionError("No answer when asking for module " +
                                    "spec of " + module_name)
     # Just to be consistent with the add_remote_config
     return module_name
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
 def add_remote_config(self, spec_file_name, config_update_callback=None):
     """Gives access to the configuration of a different module.
        These remote module options can at this moment only be
        accessed through get_remote_config_value(). This function
        also subscribes to the channel of the remote module name
        to receive the relevant updates. It is not possible to
        specify your own handler for this right now, but you can
        specify a callback that is called after the change happened.
        start() must have been called on this CCSession
        prior to the call to this method.
        Returns the name of the module."""
     module_spec = isc.config.module_spec_from_file(spec_file_name)
     self._add_remote_config_internal(module_spec, config_update_callback)
     return module_spec.get_module_name()
Exemple #6
0
 def add_remote_config(self, spec_file_name, config_update_callback=None):
     """Gives access to the configuration of a different module.
        These remote module options can at this moment only be
        accessed through get_remote_config_value(). This function
        also subscribes to the channel of the remote module name
        to receive the relevant updates. It is not possible to
        specify your own handler for this right now, but you can
        specify a callback that is called after the change happened.
        start() must have been called on this CCSession
        prior to the call to this method.
        Returns the name of the module."""
     module_spec = isc.config.module_spec_from_file(spec_file_name)
     self._add_remote_config_internal(module_spec, config_update_callback)
     return module_spec.get_module_name()
Exemple #7
0
    def _add_remote_config_internal(self,
                                    module_spec,
                                    config_update_callback=None):
        """The guts of add_remote_config and add_remote_config_by_name"""
        module_cfg = ConfigData(module_spec)
        module_name = module_spec.get_module_name()

        self._session.group_subscribe(module_name)

        # Get the current config for that module now
        seq = self._session.group_sendmsg(
            create_command(COMMAND_GET_CONFIG, {"module_name": module_name}),
            "ConfigManager")

        try:
            answer, _ = self._session.group_recvmsg(False, seq)
        except isc.cc.SessionTimeout:
            raise ModuleCCSessionError("No answer from ConfigManager when "
                                       "asking about Remote module " +
                                       module_name)
        call_callback = False
        if answer:
            rcode, value = parse_answer(answer)
            if rcode == 0:
                if value != None:
                    if module_spec.validate_config(False, value):
                        module_cfg.set_local_config(value)
                        call_callback = True
                    else:
                        raise ModuleCCSessionError("Bad config data for " +
                                                   module_name + ": " +
                                                   str(value))
            else:
                raise ModuleCCSessionError("Failure requesting remote " +
                                           "configuration data for " +
                                           module_name)

        # all done, add it
        self._remote_module_configs[module_name] = module_cfg
        self._remote_module_callbacks[module_name] = config_update_callback
        if call_callback and config_update_callback is not None:
            config_update_callback(value, module_cfg)
Exemple #8
0
    def _add_remote_config_internal(self, module_spec,
                                    config_update_callback=None):
        """The guts of add_remote_config and add_remote_config_by_name"""
        module_cfg = ConfigData(module_spec)
        module_name = module_spec.get_module_name()

        self._session.group_subscribe(module_name)

        # Get the current config for that module now
        seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": module_name }), "ConfigManager")

        try:
            answer, _ = self._session.group_recvmsg(False, seq)
        except isc.cc.SessionTimeout:
            raise ModuleCCSessionError("No answer from ConfigManager when "
                                       "asking about Remote module " +
                                       module_name)
        call_callback = False
        if answer:
            rcode, value = parse_answer(answer)
            if rcode == 0:
                if value != None:
                    if module_spec.validate_config(False, value):
                        module_cfg.set_local_config(value)
                        call_callback = True
                    else:
                        raise ModuleCCSessionError("Bad config data for " +
                                                   module_name + ": " +
                                                   str(value))
            else:
                raise ModuleCCSessionError("Failure requesting remote " +
                                           "configuration data for " +
                                           module_name)

        # all done, add it
        self._remote_module_configs[module_name] = module_cfg
        self._remote_module_callbacks[module_name] = config_update_callback
        if call_callback and config_update_callback is not None:
            config_update_callback(value, module_cfg)