[svn] commit: r493 - in /branches/parkinglot/src/bin: Makefile.am bind10/bind10.in bind10/bind10.py bindctl/create_your_cert.pem bindctl/message_format bindctl/run_bindctl.py parkinglot/ccsession.cc parkinglot/main.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jan 21 08:56:27 UTC 2010
Author: zhanglikun
Date: Thu Jan 21 08:56:27 2010
New Revision: 493
Log:
Change the code to support new module 'cmd-ctrld', Now,
1. bindctl(bigtool) will send the command to cmd-ctrl.
Added:
branches/parkinglot/src/bin/bindctl/create_your_cert.pem
branches/parkinglot/src/bin/bindctl/message_format
Modified:
branches/parkinglot/src/bin/Makefile.am
branches/parkinglot/src/bin/bind10/bind10.in
branches/parkinglot/src/bin/bind10/bind10.py
branches/parkinglot/src/bin/bindctl/run_bindctl.py
branches/parkinglot/src/bin/parkinglot/ccsession.cc
branches/parkinglot/src/bin/parkinglot/main.cc
Modified: branches/parkinglot/src/bin/Makefile.am
==============================================================================
--- branches/parkinglot/src/bin/Makefile.am (original)
+++ branches/parkinglot/src/bin/Makefile.am Thu Jan 21 08:56:27 2010
@@ -1,1 +1,1 @@
-SUBDIRS = bind10 bindctl msgq parkinglot host
+SUBDIRS = bind10 bindctl msgq parkinglot host cmd-ctrld
Modified: branches/parkinglot/src/bin/bind10/bind10.in
==============================================================================
--- branches/parkinglot/src/bin/bind10/bind10.in (original)
+++ branches/parkinglot/src/bin/bind10/bind10.in Thu Jan 21 08:56:27 2010
@@ -5,7 +5,7 @@
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
Modified: branches/parkinglot/src/bin/bind10/bind10.py
==============================================================================
--- branches/parkinglot/src/bin/bind10/bind10.py (original)
+++ branches/parkinglot/src/bin/bind10/bind10.py Thu Jan 21 08:56:27 2010
@@ -141,19 +141,35 @@
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 @@
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 @@
raise
if pid == 0: break
boss_of_bind.reap(pid, exit_status)
-
+
boss_of_bind.restart_processes()
# shutdown
Modified: branches/parkinglot/src/bin/bindctl/run_bindctl.py
==============================================================================
--- branches/parkinglot/src/bin/bindctl/run_bindctl.py (original)
+++ branches/parkinglot/src/bin/bindctl/run_bindctl.py Thu Jan 21 08:56:27 2010
@@ -1,21 +1,8 @@
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")
@@ -63,22 +50,24 @@
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?")
Modified: branches/parkinglot/src/bin/parkinglot/ccsession.cc
==============================================================================
--- branches/parkinglot/src/bin/parkinglot/ccsession.cc (original)
+++ branches/parkinglot/src/bin/parkinglot/ccsession.cc Thu Jan 21 08:56:27 2010
@@ -100,7 +100,7 @@
// 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;
Modified: branches/parkinglot/src/bin/parkinglot/main.cc
==============================================================================
--- branches/parkinglot/src/bin/parkinglot/main.cc (original)
+++ branches/parkinglot/src/bin/parkinglot/main.cc Thu Jan 21 08:56:27 2010
@@ -99,11 +99,12 @@
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;
}
More information about the bind10-changes
mailing list