Commit 8541de1b authored by Jelte Jansen's avatar Jelte Jansen
Browse files

documentation and cleanup of CCSession.py


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@566 e5f2f494-b856-4b98-b285-d166d9295462
parent 97a6c167
...@@ -30,18 +30,16 @@ class CCSession: ...@@ -30,18 +30,16 @@ class CCSession:
config_handler, command_handler): config_handler, command_handler):
self._module_name = module_name self._module_name = module_name
#self._spec_file_name = spec_file_name #self._spec_file_name = spec_file_name
self._config_handler = config_handler self.setConfigHandler(config_handler)
self._command_handler = command_handler self.setCommandHandler(command_handler)
self._data_definition = isc.config.DataDefinition(spec_file_name) self._data_definition = isc.config.DataDefinition(spec_file_name)
self._session = Session() self._session = Session()
self._session.group_subscribe(module_name, "*") self._session.group_subscribe(module_name, "*")
self._session.group_sendmsg(self._data_definition.getDefinition(), "ConfigManager")
answer, env = self._session.group_recvmsg(False) self.__sendSpec()
self._session.group_sendmsg({ "command": [ "get_config", { "module_name": module_name } ] }, "ConfigManager") self.__getFullConfig()
answer, env = self._session.group_recvmsg(False)
if self._config_handler:
self._config_handler(answer["result"])
print(answer)
#do we need getSocket()? #do we need getSocket()?
...@@ -60,5 +58,30 @@ class CCSession: ...@@ -60,5 +58,30 @@ class CCSession:
self._session.group_reply(env, answer) self._session.group_reply(env, answer)
def setConfigHandler(self, config_handler):
"""Set the config handler for this module. The handler is a
function that takes the full configuration and handles it.
It should return either { "result": [ 0 ] } or
{ "result": [ <error_number>, "error message" ] }"""
self._config_handler = config_handler
# should we run this right now since we've changed the handler?
def setCommandHandler(self, command_handler):
"""Set the command handler for this module. The handler is a
function that takes a command as defined in the .spec file
and return either { "result": [ 0, (result) ] } or
{ "result": [ <error_number>. "error message" ] }"""
self._command_handler = command_handler
def __sendSpec(self):
"""Sends the data specification to the configuration manager"""
self._session.group_sendmsg(self._data_definition.getDefinition(), "ConfigManager")
answer, env = self._session.group_recvmsg(False)
def __getFullConfig(self):
"""Asks the configuration manager for the current configuration, and call the config handler if set"""
self._session.group_sendmsg({ "command": [ "get_config", { "module_name": self._module_name } ] }, "ConfigManager")
answer, env = self._session.group_recvmsg(False)
if self._config_handler:
self._config_handler(answer["result"])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment