Browse Source

function to create and 'parse' ccsession commands, and a list of fixed (non-module) command names

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@948 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
e84b2e3e89
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/lib/config/python/isc/config/ccsession.py

+ 31 - 0
src/lib/config/python/isc/config/ccsession.py

@@ -74,6 +74,37 @@ def create_answer(rcode, arg = None):
     else:
         return { 'result': [ rcode ] }
 
+# 'fixed' commands
+"""Fixed names for command and configuration messages"""
+COMMAND_COMMANDS_UPDATE = "commands_update"
+COMMAND_SPECIFICATION_UPDATE = "specification_update"
+
+COMMAND_GET_COMMANDS_SPEC = "get_commands_spec"
+COMMAND_GET_CONFIG = "get_config"
+COMMAND_SET_CONFIG = "set_config"
+COMMAND_GET_MODULE_SPEC = "get_module_spec"
+
+def parse_command(msg):
+    """Parses what may be a command message. If it looks like one,
+       the function returns (command, value) where command is a
+       string. If it is not, this function returns None, None"""
+    if type(msg) == dict and len(msg.items()) == 1:
+        cmd, value = msg.popitem()
+        if type(cmd) == str:
+            return cmd, value
+    return None, None
+
+def create_command(command_name, params = None):
+    """Creates a module command message with the given command name (as
+       specified in the module's specification, and an optional params
+       object"""
+    # TODO: validate_command with spec
+    cmd = [ command_name ]
+    if params:
+        cmd.append(params)
+    msg = { 'command': cmd }
+    return msg
+
 class ModuleCCSession(ConfigData):
     """This class maintains a connection to the command channel, as
        well as configuration options for modules. The module provides