Browse Source

Change the code to support new module 'cmd-ctrld', Now,
1. bindctl(bigtool) will send the command to cmd-ctrl.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@493 e5f2f494-b856-4b98-b285-d166d9295462

Likun Zhang 15 years ago
parent
commit
e3e8cda089

+ 1 - 1
src/bin/Makefile.am

@@ -1 +1 @@
-SUBDIRS = bind10 bindctl msgq parkinglot host
+SUBDIRS = bind10 bindctl msgq parkinglot host cmd-ctrld

+ 1 - 1
src/bin/bind10/bind10.in

@@ -5,7 +5,7 @@ export PYTHON_EXEC
 
 BIND10_PATH=@abs_top_srcdir@/src/bin/bind10
 
-PATH=@abs_top_srcdir@/src/bin/msgq:@abs_top_srcdir@/src/bin/parkinglot:@abs_top_srcdir@/src/bin/bind-cfgd:$PATH
+PATH=@abs_top_srcdir@/src/bin/msgq:@abs_top_srcdir@/src/bin/parkinglot:@abs_top_srcdir@/src/bin/bind-cfgd:@abs_top_srcdir@/src/bin/cmd-ctrld:$PATH
 export PATH
 
 PYTHONPATH=@abs_top_srcdir@/src/lib/cc/python:${abs_top_src_dir}/lib/cc/python/ISC

+ 22 - 5
src/bin/bind10/bind10.py

@@ -141,19 +141,35 @@ class BoB:
         try:
             parkinglot = ProcessInfo("parkinglot", ["parkinglot", "-p", "5300"])
         except Exception as e:
-            c_channel.kill()
-            bind_cfgd.kill()
+            c_channel.process.kill()
+            bind_cfgd.process.kill()
             return "Unable to start parkinglot; " + str(e)
         self.processes[parkinglot.pid] = parkinglot
         if self.verbose:
             sys.stdout.write("Started parkinglot (PID %d)\n" % parkinglot.pid)
 
+        # start the cmd-ctrld
+        # XXX: we hardcode port 8080
+        if self.verbose:
+            sys.stdout.write("Starting cmd-ctrld on port 8080\n")
+        try:
+            cmd_ctrld = ProcessInfo("cmd-ctrld", 'cmd-ctrld')
+        except Exception as e:
+            c_channel.process.kill()
+            bind_cfgd.process.kill()
+            parkinglot.process.kill()
+            return "Unable to start cmd-ctrld; " + str(e)
+        self.processes[cmd_ctrld.pid] = cmd_ctrld
+        if self.verbose:
+            sys.stdout.write("Started cmd-ctrld (PID %d)\n" % cmd_ctrld.pid)
+
         self.runnable = True
         return None
 
     def stop_all_processes(self):
         """Stop all processes."""
-        cmd = { "command": "shutdown" }
+        cmd = { "command": ['shutdown']}
+        self.cc_session.group_sendmsg(cmd, 'Boss', 'Cmd-Ctrld')
         self.cc_session.group_sendmsg(cmd, "Boss", "ConfigManager")
         self.cc_session.group_sendmsg(cmd, "Boss", "ParkingLot")
 
@@ -237,10 +253,11 @@ class BoB:
         if msg is None:
             return
         msg_from = data.get('from', '')
+
         if (type(msg) is dict) and (type(data) is dict):
             if "command" in msg:
                 cmd = msg['command']
-                if (cmd[0] == "boss") and (cmd[1] == "shutdown"):
+                if cmd[0] == "shutdown":
                     if self.verbose:
                         sys.stdout.write("Shutdown command received\n")
                     self.runnable = False
@@ -385,7 +402,7 @@ if __name__ == "__main__":
                 raise
             if pid == 0: break
             boss_of_bind.reap(pid, exit_status)
-
+        
         boss_of_bind.restart_processes()
 
     # shutdown

+ 36 - 0
src/bin/bindctl/create_your_cert.pem

@@ -0,0 +1,36 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDpICWxJGKMvUhLFPbf5n8ZWogqjYcQqqoHqHVRHYjyiey6FZdt
+ZkY2s1gYh0G0NXtimlIgic+vEcFe7vdmyKntW7DYDaqAj0KrED7RKAj8324jNbSJ
+HtLP4evvJep3vsoNtTvNuceQJ46vukxyxgg3DuC9kVqPuD8CZ1Rq4ATyiwIDAQAB
+AoGBAOJlOtV+DUq6Y2Ou91VXRiU8GzKgAQP5iWgoe84Ljbxkn4XThBxVD2j94Fbp
+u7AjpDCMx6cbzpoo9w6XqaGizAmAehIfTE3eFYs74N/FM09Wg2OSDyxMY0jgyECU
+A4ukjlPwcGDbmgbmlY3i+FVHp+zCgtZEsMC1IAosMac1BoX5AkEA/lrXWaVtH8bo
+mut3GBaXvubZMdaUr0BUd5a9q+tt4dQcKG1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CPQqsQPtEoCPzfbiM1tIke0s/h6+8l6ne+yg21
+O825x5Anjq+6THLGCDcO4L2RWo+4PwJnVGrgBPKLAgMBAAGjgfIwge8wHQYDVR0O
+BBYEFJKM/O0ViGlwtb3JEci/DLTO/7DaMIG/BgNVHSMEgbcwgbSAFJKM/O0ViGlw
+tb3JEci/DLTO/7DaoYGQpIGNMIGKMQswCQYDVQQGEwJjbjEQMA4GA1UECBMHYmVp
+amluZzEQMA4GA1UEBxMHYmVpamluZzEOMAwGA1UEChMFY25uaWMxDjAMBgNVBAsT
+BWNubmljMRMwEQYDVQQDEwp6aGFuZ2xpa3VuMSIwIAYJKoZIhvcNAQkBFhN6aGFu
+Z2xpa3VuQGNubmljLmNuggkAvCeA0WKTs40wDAYDVR0TBAUwAwEB/zANBgkqhkiG
+9w0BAQUFAAOBgQBh5N6isMAQAFFD+pbfpppjQlO4vUNcEdzPdeuBFaf9CsX5ZdxV
+jmn1ZuGm6kRzqUPwPSxvCIAY0wuSu1g7YREPAZ3XBVwcg6262iGOA6n7E+nv5PLz
+EuZ1oUg+IfykUIoflKH6xZB4MyPL+EgkMT+i9BrngaXHXF8tEO30YppMiA==
+-----END CERTIFICATE-----

+ 4 - 0
src/bin/bindctl/message_format

@@ -0,0 +1,4 @@
+#define the message format between different modules
+'command' : [module_name, command_name, {param1 = value1, param2 = value2}]
+
+

+ 16 - 27
src/bin/bindctl/run_bindctl.py

@@ -1,22 +1,9 @@
 from moduleinfo  import *
 from bindctl import *
 import ISC
+import pprint
 
 
-def _prepare_fake_data(bindctl):
-    shutdown_param = ParamInfo(name = "module_name", desc = "the name of module")
-    shutdown_cmd = CommandInfo(name = 'shutdown', desc = "stop bind10",
-                               need_inst_param = False)
-    shutdown_cmd.add_param(shutdown_param)
-    boss_module = ModuleInfo(name = "boss", desc = "boss of bind10")
-    boss_module.add_command(shutdown_cmd)               
-
-    bindctl.add_module_info(boss_module)
-
-def prepare_commands(bindctl, command_spec):
-    for module_name in command_spec.keys():
-        bindctl.prepare_module_commands(module_name, command_spec[module_name])
-
 def prepare_config_commands(bindctl):
     module = ModuleInfo(name = "config", desc = "Configuration commands")
     cmd = CommandInfo(name = "show", desc = "Show configuration", need_inst_param = False)
@@ -63,22 +50,24 @@ def prepare_config_commands(bindctl):
 
     bindctl.add_module_info(module)
     
+def prepare_boss_command(tool):
+    # Prepare the command 'shutdown' for Boss, this is one 'hardcode' exception.
+    shutdown_cmd = CommandInfo(name = 'shutdown', desc = "stop one module",
+                               need_inst_param = False)
+    boss_module = ModuleInfo(name = "Boss", desc = "boss of bind10")
+    boss_module.add_command(shutdown_cmd)               
+    tool.add_module_info(boss_module)
+
+
 
 if __name__ == '__main__':
     try:
-        cc = ISC.CC.Session()
-        cc.group_subscribe("BindCtl", "*")
-        cc.group_subscribe("Boss", "*")
-
-        tool = BindCtl(cc)
-        cc.group_sendmsg({ "command": ["get_commands"] }, "ConfigManager")
-        command_spec, env =  cc.group_recvmsg(False)
-        prepare_commands(tool, command_spec["result"][1])
+        tool = BindCtl("localhost:8080")
         prepare_config_commands(tool)
-        _prepare_fake_data(tool)   
-        tool.cmdloop()
-    except ISC.CC.SessionError:
-        print("Failed to create cchannel session, "
-              "is the command channel daemon running?")
+        prepare_boss_command(tool)
+        tool.run()
+    except Exception as e:
+        print(e)
+        print("Failed to connect with cmd-ctrld module, is it running?")
 
 

+ 1 - 1
src/bin/parkinglot/ccsession.cc

@@ -100,7 +100,7 @@ CommandSession::CommandSession(std::string module_name,
     
     // get any stored configuration from the manager
     if (config_handler_) {
-        ElementPtr cmd = Element::createFromString("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }");
+        ElementPtr cmd = Element::createFromString("{ \"command\": [\"get_config\", {\"module_name\":\"" + module_name + "\"} ] }");
         session_.group_sendmsg(cmd, "ConfigManager");
         session_.group_recvmsg(env, answer, false);
         cout << "[XX] got config: " << endl << answer->str() << endl;

+ 4 - 3
src/bin/parkinglot/main.cc

@@ -99,11 +99,12 @@ my_command_handler(isc::data::ElementPtr command)
     isc::data::ElementPtr answer = isc::data::Element::createFromString("{ \"result\": [0] }");
 
     cout << "[XX] Handle command: " << endl << command->str() << endl;
-    if (command->get(1)->stringValue() == "print_message") {
-        cout << command->get(2)->stringValue() << endl;
+    if (command->get(0)->stringValue() == "print_message") 
+    {
+        cout << command->get(1)->get("message") << endl;
         /* let's add that message to our answer as well */
         cout << "[XX] answer was: " << answer->str() << endl;
-        answer->get("result")->add(command->get(2));
+        answer->get("result")->add(command->get(1));
         cout << "[XX] answer now: " << answer->str() << endl;
     }