[svn] commit: r343 - in /branches/jelte-datadef/src: bin/bigtool/run_bigtool.py lib/bigtool/bigtool.py lib/bind-cfgd/python/bind-cfgd.py lib/cc/python/ISC/CC/data.py

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Dec 3 11:12:17 UTC 2009


Author: jelte
Date: Thu Dec  3 11:12:17 2009
New Revision: 343

Log:
added a data.py class with a few classes and function usable by configuration handlers. bigtool now has a fixed config 'module' which takes configuration commands. The completion function completes configuration identifiers, though i haven't been able to get rid of the space yet, which would not always be ideal

config commands are kind of based on the message i sent last week to -dev; set,unset,add (to list), remove (from list), revert, and commit

changed configuration is stored, but not sent to and used by parkinglot etc. yet

Added:
    branches/jelte-datadef/src/lib/cc/python/ISC/CC/data.py
Modified:
    branches/jelte-datadef/src/bin/bigtool/run_bigtool.py
    branches/jelte-datadef/src/lib/bigtool/bigtool.py
    branches/jelte-datadef/src/lib/bind-cfgd/python/bind-cfgd.py

Modified: branches/jelte-datadef/src/bin/bigtool/run_bigtool.py
==============================================================================
--- branches/jelte-datadef/src/bin/bigtool/run_bigtool.py (original)
+++ branches/jelte-datadef/src/bin/bigtool/run_bigtool.py Thu Dec  3 11:12:17 2009
@@ -28,7 +28,7 @@
     bigtool.add_module_info(zone_module)
     bigtool.add_module_info(boss_module)
 
-def prepare_data_module(bigtool, module_name, module_commands):
+def prepare_module_commands(bigtool, module_name, module_commands):
     module = ModuleInfo(name = module_name,
                         desc = "same here")
     for command in module_commands:
@@ -45,10 +45,52 @@
         module.add_command(cmd)
     bigtool.add_module_info(module)
 
-def prepare_data(bigtool, command_spec):
+def prepare_commands(bigtool, command_spec):
     for module_name in command_spec.keys():
-        prepare_data_module(bigtool, module_name, command_spec[module_name])
+        prepare_module_commands(bigtool, module_name, command_spec[module_name])
+
+def prepare_config_commands(bigtool):
+    module = ModuleInfo(name = "config", desc = "Configuration commands")
+    cmd = CommandInfo(name = "show", desc = "Show configuration", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type = "string", optional=True)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "add", desc = "Add entry to configuration list", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type = "string", optional=True)
+    cmd.add_param(param)
+    param = ParamInfo(name = "value", type = "string", optional=True)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "remove", desc = "Remove entry from configuration list", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type = "string", optional=True)
+    cmd.add_param(param)
+    param = ParamInfo(name = "value", type = "string", optional=True)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "set", desc = "Set a configuration value", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type = "string", optional=True)
+    cmd.add_param(param)
+    param = ParamInfo(name = "value", type = "string", optional=True)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "unset", desc = "Unset a configuration value", need_inst_param = False)
+    param = ParamInfo(name = "identifier", type = "string", optional=True)
+    cmd.add_param(param)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "revert", desc = "Revert all local changes", need_inst_param = False)
+    module.add_command(cmd)
+
+    cmd = CommandInfo(name = "commit", desc = "Commit all local changes", need_inst_param = False)
+    module.add_command(cmd)
+
+    bigtool.add_module_info(module)
     
+
 if __name__ == '__main__':
     try:
         cc = ISC.CC.Session()
@@ -59,7 +101,8 @@
         tool = BigTool(cc)
         cc.group_sendmsg({ "command": ["get_commands"] }, "ConfigManager")
         command_spec, env =  cc.group_recvmsg(False)
-        prepare_data(tool, command_spec["result"])
+        prepare_commands(tool, command_spec["result"])
+        prepare_config_commands(tool)
         _prepare_fake_data(tool)   
         tool.cmdloop()
     except ISC.CC.SessionError:

Modified: branches/jelte-datadef/src/lib/bigtool/bigtool.py
==============================================================================
--- branches/jelte-datadef/src/lib/bigtool/bigtool.py (original)
+++ branches/jelte-datadef/src/lib/bigtool/bigtool.py Thu Dec  3 11:12:17 2009
@@ -7,6 +7,7 @@
 from command import BigToolCmd
 from xml.dom import minidom
 import ISC
+import ISC.CC.data
 
 try:
     from collections import OrderedDict
@@ -34,7 +35,7 @@
         self.modules = OrderedDict()
         self.add_module_info(ModuleInfo("help", desc = "Get help for bigtool"))
         self.cc = session
-
+        self.config_data = ISC.CC.data.UIConfigData("", session)
 
     def validate_cmd(self, cmd):
         if not cmd.module in self.modules:
@@ -85,13 +86,15 @@
             for name in manda_params:
                 if not name in params and not param_nr in params:
                     raise CmdMissParamSyntaxError(cmd.module, cmd.command, name)
-                              
+                
                 param_nr += 1
 
     def _handle_cmd(self, cmd):
         #to do, consist xml package and send to bind10
         if cmd.command == "help" or ("help" in cmd.params.keys()):
             self._handle_help(cmd)
+        elif cmd.module == "config":
+            self.apply_config_cmd(cmd)
         else:
             self.apply_cmd(cmd)
 
@@ -141,6 +144,11 @@
                 else:                       
                     hints = self._get_param_startswith(cmd.module, cmd.command,
                                                        text)
+                    if cmd.module == "config":
+                        # grm text has been stripped of slashes...
+                        my_text = cur_line.rpartition(" ")[2]
+                        list = self.config_data.config.get_item_list(my_text.rpartition("/")[0])
+                        hints.extend([val for val in list if val.startswith(text)])
             except CmdModuleNameFormatError:
                 if not text:
                     hints = list(self.modules.keys())
@@ -160,9 +168,9 @@
 
             except BigToolException:
                 hints = []
-            
+
             self.hint = hints
-            self._append_space_to_hint()
+            #self._append_space_to_hint()
 
         if state < len(self.hint):
             return self.hint[state]
@@ -240,6 +248,43 @@
             self.modules[cmd.module].command_help(cmd.command)
 
 
+    def apply_config_cmd(self, cmd):
+        identifier = ""
+        try:
+            if 'identifier' in cmd.params:
+                identifier = cmd.params['identifier']
+            if cmd.command == "show":
+                values = self.config_data.get_value_maps(identifier)
+                for value_map in values:
+                    line = value_map['name']
+                    if value_map['type'] in [ 'module', 'map', 'list' ]:
+                        line += "/"
+                    else:
+                        line += ":\t" + str(value_map['value'])
+                    line += "\t" + value_map['type']
+                    line += "\t"
+                    if value_map['default']:
+                        line += "(default)"
+                    if value_map['modified']:
+                        line += "(modified)"
+                    print(line)
+            elif cmd.command == "add":
+                self.config_data.add(identifier, cmd.params['value'])
+            elif cmd.command == "remove":
+                self.config_data.remove(identifier, cmd.params['value'])
+            elif cmd.command == "set":
+                self.config_data.set(identifier, cmd.params['value'])
+            elif cmd.command == "unset":
+                self.config_data.unset(identifier)
+            elif cmd.command == "revert":
+                self.config_data.revert()
+            elif cmd.command == "commit":
+                self.config_data.commit(self.cc)
+        except ISC.CC.data.DataTypeError as dte:
+            print("Error: " + str(dte))
+        except ISC.CC.data.DataNotFoundError as dnfe:
+            print("Error: " + identifier + " not found")
+
     def apply_cmd(self, cmd):
         if not self.cc:
             return

Modified: branches/jelte-datadef/src/lib/bind-cfgd/python/bind-cfgd.py
==============================================================================
--- branches/jelte-datadef/src/lib/bind-cfgd/python/bind-cfgd.py (original)
+++ branches/jelte-datadef/src/lib/bind-cfgd/python/bind-cfgd.py Thu Dec  3 11:12:17 2009
@@ -1,10 +1,12 @@
 import ISC
 import pickle
 import signal
-    
+from ISC.CC import data
+
 class ConfigData:
     def __init__(self):
         self.zones = {}
+        self.data = {}
 
     def add_zone(self, zone_name, zone_file):
         self.zones[zone_name] = zone_file
@@ -85,6 +87,47 @@
             try:
                 if cmd[0] == "get_commands":
                     answer["result"] = self.commands
+                elif cmd[0] == "get_data_spec":
+                    if len(cmd) > 1 and cmd[1] != "":
+                        try:
+                            answer["result"] = [0, self.data_definitions[cmd[1]]]
+                        except KeyError as ke:
+                            answer["result"] = [1, "No specification for module " + cmd[1]]
+                    else:
+                        answer["result"] = [0, self.data_definitions]
+                elif cmd[0] == "get_config":
+                    # we may not have any configuration here
+                    conf_part = None
+                    if len(cmd) > 1:
+                        try:
+                            conf_part = data.find(self.config.data, cmd[1])
+                        except data.DataNotFoundError as dnfe:
+                            pass
+                    else:
+                        conf_part = self.config.data
+                    answer["result"] = [ 0, conf_part ]
+                elif cmd[0] == "set_config":
+                    print("[XX] cmd len: " + str(len(cmd)))
+                    print("[XX] cmd 0: " + str(cmd[0]))
+                    print("[XX] cmd 1: " + str(cmd[1]))
+                    print("[XX] cmd 2: " + str(cmd[2]))
+                    if len(cmd) == 3:
+                        # todo: use api (and check types?)
+                        if cmd[1] != "":
+                            conf_part = data.find_no_exc(self.config.data, cmd[1])
+                            if not conf_part:
+                                conf_part = data.set(self.config.data, cmd[1], "")
+                        else:
+                            conf_part = self.config.data
+                        conf_part.update(cmd[2])
+                        # send out changed info
+                        answer["result"] = [ 0 ]
+                    elif len(cmd) == 2:
+                        self.config.data.update(cmd[1])
+                        # send out changed info
+                        answer["result"] = [ 0 ]
+                    else:
+                        answer["result"] = [ 1, "Wrong number of arguments" ]
                 elif cmd[0] == "zone" and cmd[1] == "add":
                     self.add_zone(cmd[2])
                     answer["result"] = [ 0 ]
@@ -101,7 +144,7 @@
                     answer["result"] = [ 1, "Unknown command: " + str(cmd) ]
             except IndexError as ie:
                 print("missing argument")
-                answer["result"] = [ 1, "Missing argument in command" ]
+                answer["result"] = [ 1, "Missing argument in command: " + str(ie) ]
         elif "data_specification" in msg:
             # todo: validate? (no direct access to spec as
             spec = msg["data_specification"]




More information about the bind10-changes mailing list