Browse Source

compile-time location for parkinglot.spec file
somewhat parse the commands structure in bigtool as they are sent by the config manager


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@318 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen 15 years ago
parent
commit
7e2512b059

+ 1 - 0
configure.ac

@@ -64,6 +64,7 @@ AC_CONFIG_FILES([Makefile
                ])
 AC_OUTPUT([src/bin/bind-cfgd/bind-cfgd
            src/bin/bind10/bind10
+           src/bin/parkinglot/config.h
           ], [
            chmod +x src/bin/bind-cfgd/bind-cfgd
            chmod +x src/bin/bind10/bind10

+ 24 - 1
src/bin/bigtool/run_bigtool.py

@@ -27,8 +27,28 @@ def _prepare_fake_data(bigtool):
 
     bigtool.add_module_info(zone_module)
     bigtool.add_module_info(boss_module)
-    
 
+def prepare_data_module(bigtool, module_name, module_commands):
+    module = ModuleInfo(name = module_name,
+                        desc = "same here")
+    for command in module_commands:
+        cmd = CommandInfo(name = command["command_name"],
+                          desc = "todo2",
+                          need_inst_param = False)
+        for arg in command["command_args"]:
+            param = ParamInfo(name = arg["item_name"],
+                              type = arg["item_type"],
+                              optional = bool(arg["item_optional"]))
+            if ("item_default" in arg):
+                param.default = arg["item_default"]
+            cmd.add_param(param)
+        module.add_command(cmd)
+    bigtool.add_module_info(module)
+
+def prepare_data(bigtool, command_spec):
+    for module_name in command_spec.keys():
+        prepare_data_module(bigtool, module_name, command_spec[module_name])
+    
 if __name__ == '__main__':
     try:
         cc = ISC.CC.Session()
@@ -37,6 +57,9 @@ if __name__ == '__main__':
         cc.group_subscribe("Boss", "*", "meonly")
 
         tool = BigTool(cc)
+        cc.group_sendmsg({ "command": ["get_commands"] }, "ConfigManager")
+        command_spec, env =  cc.group_recvmsg(False)
+        prepare_data(tool, command_spec["result"])
         _prepare_fake_data(tool)   
         tool.cmdloop()
     except ISC.CC.SessionError:

+ 3 - 2
src/bin/parkinglot/ccsession.cc

@@ -38,6 +38,7 @@
 
 #include "common.h"
 #include "ccsession.h"
+#include "config.h"
 
 using namespace std;
 
@@ -52,9 +53,9 @@ CommandSession::read_data_definition(const std::string& filename) {
     std::ifstream file;
 
     // this file should be declared in a @something@ directive
-    file.open("parkinglot.spec");
+    file.open(PARKINGLOT_SPECFILE_LOCATION);
     if (!file) {
-        cout << "error opening parkinglot.spec" << endl;
+        cout << "error opening " << PARKINGLOT_SPECFILE_LOCATION << endl;
         exit(1);
     }
 

+ 1 - 0
src/bin/parkinglot/config.h.in

@@ -0,0 +1 @@
+#define PARKINGLOT_SPECFILE_LOCATION "@abs_top_srcdir@/src/bin/parkinglot/parkinglot.spec"

+ 46 - 0
src/bin/parkinglot/parkinglot.spec

@@ -0,0 +1,46 @@
+{
+  "data_specification": {
+    "module_name": "ParkingLot",
+    "config_data": [
+      {
+        "item_name": "port",
+        "item_type": "integer",
+        "item_optional": false,
+        "item_default": 5300
+      },
+      {
+        "item_name": "zones",
+        "item_type": "list",
+        "item_optional": false,
+        "item_default": [ ],
+        "list_item_spec": {
+          "item_name": "zone_name",
+          "item_type": "string",
+          "item_optional": false,
+          "item_default": ""
+        }
+      }
+    ],
+    "commands": [
+      {
+        "command_name": "zone_add",
+        "command_args": [ {
+          "item_name": "zone_name",
+          "item_type": "string",
+          "item_optional": False,
+          "item_default": ""
+        } ]
+      },
+      {
+        "command_name": "zone_delete",
+        "command_args": [ {
+          "item_name": "zone_name",
+          "item_type": "string",
+          "item_optional": False,
+          "item_default": ""
+        } ]
+      }
+    ]
+  }
+}
+

+ 1 - 1
src/lib/bind-cfgd/python/bind-cfgd.py

@@ -85,7 +85,7 @@ class ConfigManager:
             try:
                 if cmd[0] == "get_commands":
                     answer["result"] = self.commands
-                if cmd[0] == "zone" and cmd[1] == "add":
+                elif cmd[0] == "zone" and cmd[1] == "add":
                     self.add_zone(cmd[2])
                     answer["result"] = [ 0 ]
                 elif cmd[0] == "zone" and cmd[1] == "remove":