Browse Source

[trac1010] add optional callback for remote config update

Jelte Jansen 14 years ago
parent
commit
707e700d48
2 changed files with 20 additions and 3 deletions
  1. 1 1
      src/bin/xfrout/xfrout.py.in
  2. 19 2
      src/lib/python/isc/config/ccsession.py

+ 1 - 1
src/bin/xfrout/xfrout.py.in

@@ -559,7 +559,7 @@ class XfroutServer:
         #self._log = None
         #self._log = None
         self._listen_sock_file = UNIX_SOCKET_FILE
         self._listen_sock_file = UNIX_SOCKET_FILE
         self._shutdown_event = threading.Event()
         self._shutdown_event = threading.Event()
-        self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION, self.config_handler, self.command_handler)
+        self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION, self.config_handler, self.command_handler, None, True)
         self._config_data = self._cc.get_full_config()
         self._config_data = self._cc.get_full_config()
         self._cc.start()
         self._cc.start()
         self._cc.add_remote_config(AUTH_SPECFILE_LOCATION);
         self._cc.add_remote_config(AUTH_SPECFILE_LOCATION);

+ 19 - 2
src/lib/python/isc/config/ccsession.py

@@ -39,6 +39,8 @@
 from isc.cc import Session
 from isc.cc import Session
 from isc.config.config_data import ConfigData, MultiConfigData, BIND10_CONFIG_DATA_VERSION
 from isc.config.config_data import ConfigData, MultiConfigData, BIND10_CONFIG_DATA_VERSION
 import isc
 import isc
+from isc.util.file import path_search
+import bind10_config
 
 
 class ModuleCCSessionError(Exception): pass
 class ModuleCCSessionError(Exception): pass
 
 
@@ -116,6 +118,9 @@ def create_command(command_name, params = None):
     msg = { 'command': cmd }
     msg = { 'command': cmd }
     return msg
     return msg
 
 
+def default_logconfig_handler(new_config, config_data):
+    pass
+
 class ModuleCCSession(ConfigData):
 class ModuleCCSession(ConfigData):
     """This class maintains a connection to the command channel, as
     """This class maintains a connection to the command channel, as
        well as configuration options for modules. The module provides
        well as configuration options for modules. The module provides
@@ -126,7 +131,7 @@ class ModuleCCSession(ConfigData):
        callbacks are called when 'check_command' is called on the
        callbacks are called when 'check_command' is called on the
        ModuleCCSession"""
        ModuleCCSession"""
        
        
-    def __init__(self, spec_file_name, config_handler, command_handler, cc_session = None):
+    def __init__(self, spec_file_name, config_handler, command_handler, cc_session = None, handle_logging_config = False):
         """Initialize a ModuleCCSession. This does *NOT* send the
         """Initialize a ModuleCCSession. This does *NOT* send the
            specification and request the configuration yet. Use start()
            specification and request the configuration yet. Use start()
            for that once the ModuleCCSession has been initialized.
            for that once the ModuleCCSession has been initialized.
@@ -149,6 +154,11 @@ class ModuleCCSession(ConfigData):
         self._session.group_subscribe(self._module_name, "*")
         self._session.group_subscribe(self._module_name, "*")
 
 
         self._remote_module_configs = {}
         self._remote_module_configs = {}
+        self._remote_module_callbacks = {}
+
+        if handle_logging_config:
+            self.add_remote_config(path_search('logging.spec', bind10_config.PLUGIN_PATHS),
+                                   default_logconfig_handler)
 
 
     def __del__(self):
     def __del__(self):
         # If the CC Session obejct has been closed, it returns
         # If the CC Session obejct has been closed, it returns
@@ -218,6 +228,9 @@ class ModuleCCSession(ConfigData):
                             newc = self._remote_module_configs[module_name].get_local_config()
                             newc = self._remote_module_configs[module_name].get_local_config()
                             isc.cc.data.merge(newc, new_config)
                             isc.cc.data.merge(newc, new_config)
                             self._remote_module_configs[module_name].set_local_config(newc)
                             self._remote_module_configs[module_name].set_local_config(newc)
+                            if self._remote_module_callbacks[module_name] != None:
+                                self._remote_module_callbacks[module_name](new_config,
+                                                                           self._remote_module_configs[module_name])
                         # For other modules, we're not supposed to answer
                         # For other modules, we're not supposed to answer
                         return
                         return
 
 
@@ -260,7 +273,7 @@ class ModuleCCSession(ConfigData):
            and return an answer created with create_answer()"""
            and return an answer created with create_answer()"""
         self._command_handler = command_handler
         self._command_handler = command_handler
 
 
-    def add_remote_config(self, spec_file_name):
+    def add_remote_config(self, spec_file_name, config_update_callback = None):
         """Gives access to the configuration of a different module.
         """Gives access to the configuration of a different module.
            These remote module options can at this moment only be
            These remote module options can at this moment only be
            accessed through get_remote_config_value(). This function
            accessed through get_remote_config_value(). This function
@@ -289,9 +302,12 @@ class ModuleCCSession(ConfigData):
             if rcode == 0:
             if rcode == 0:
                 if value != None and module_spec.validate_config(False, value):
                 if value != None and module_spec.validate_config(False, value):
                     module_cfg.set_local_config(value);
                     module_cfg.set_local_config(value);
+                    if config_update_callback is not None:
+                        config_update_callback(value, module_cfg)
 
 
         # all done, add it
         # all done, add it
         self._remote_module_configs[module_name] = module_cfg
         self._remote_module_configs[module_name] = module_cfg
+        self._remote_module_callbacks[module_name] = config_update_callback
         return module_name
         return module_name
         
         
     def remove_remote_config(self, module_name):
     def remove_remote_config(self, module_name):
@@ -299,6 +315,7 @@ class ModuleCCSession(ConfigData):
         if module_name in self._remote_module_configs:
         if module_name in self._remote_module_configs:
             self._session.group_unsubscribe(module_name)
             self._session.group_unsubscribe(module_name)
             del self._remote_module_configs[module_name]
             del self._remote_module_configs[module_name]
+            del self._remote_module_callbacks[module_name]
 
 
     def get_remote_config_value(self, module_name, identifier):
     def get_remote_config_value(self, module_name, identifier):
         """Returns the current setting for the given identifier at the
         """Returns the current setting for the given identifier at the