[svn] commit: r576 - in /branches/parkinglot/src: bin/bind10/bind10.py bin/bindctl/bindctl.py bin/cmd-ctrld/cmd-ctrld.py bin/parkinglot/main.cc lib/config/cpp/ccsession.cc lib/config/python/bind-cfgd.py lib/config/python/isc/config/CCSession.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jan 28 00:09:16 UTC 2010
Author: jelte
Date: Thu Jan 28 00:09:16 2010
New Revision: 576
Log:
more command handling for CCSession stuff
added CCSession to Boss module
removed hard-coded boss stuff from cmd-ctrld and bindctl
removed a few unnecessary subscriptions from default channels
Modified:
branches/parkinglot/src/bin/bind10/bind10.py
branches/parkinglot/src/bin/bindctl/bindctl.py
branches/parkinglot/src/bin/cmd-ctrld/cmd-ctrld.py
branches/parkinglot/src/bin/parkinglot/main.cc
branches/parkinglot/src/lib/config/cpp/ccsession.cc
branches/parkinglot/src/lib/config/python/bind-cfgd.py
branches/parkinglot/src/lib/config/python/isc/config/CCSession.py
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 28 00:09:16 2010
@@ -93,20 +93,28 @@
if self.verbose:
print("[XX] handling new config:")
print(new_config)
+ # TODO
def command_handler(self, command):
+ # a command is of the form [ "command", { "arg1": arg1, "arg2": arg2 } ]
if self.verbose:
print("[XX] Boss got command:")
print(command)
answer = None
- if "command" in command:
- cmd = command["command"]
+ if type(command) != list or len(command) == 0:
+ answer = { "result": [ 1, "bad command" ] }
+ else:
+ cmd = command[0]
if cmd == "shutdown":
- self.shutdown()
+ print("[XX] got shutdown command")
+ self.runnable = False
+ answer = { "result": [ 0 ] }
+ elif cmd == "print_message":
+ if len(command) > 1 and type(command[1]) == dict and "message" in command[1]:
+ print(command[1]["message"])
+ answer = { "result": [ 0 ] }
else:
- answer = { "result": [ 1, "unknown command: " + cmd ] }
- else:
- answer = { "result": [ 1, "bad command" ] }
+ answer = { "result": [ 1, "Unknown command" ] }
return answer
def startup(self):
@@ -140,7 +148,7 @@
self.cc_session = ISC.CC.Session(self.c_channel_port)
except ISC.CC.session.SessionError:
time.sleep(0.1)
- self.cc_session.group_subscribe("Boss", "boss")
+ #self.cc_session.group_subscribe("Boss", "boss")
# start the configuration manager
if self.verbose:
@@ -161,7 +169,7 @@
time.sleep(1)
if self.verbose:
print("[XX] starting ccsession")
- self.ccs = isc.config.CCSession("bob", "bob.spec", self.config_handler, self.command_handler)
+ self.ccs = isc.config.CCSession("Boss", "bob.spec", self.config_handler, self.command_handler)
if self.verbose:
print("[XX] ccsession started")
@@ -280,56 +288,60 @@
else:
sys.stdout.write("Unknown child pid %d exited.\n" % pid)
- def recv_and_process_cc_msg(self):
- """Receive and process the next message on the c-channel,
- if any."""
- msg, envelope = self.cc_session.group_recvmsg(False)
- print(msg)
- if msg is None:
- return
- if not ((type(msg) is dict) and (type(envelope) is dict)):
- if self.verbose:
- sys.stdout.write("Non-dictionary message\n")
- return
- if not "command" in msg:
- if self.verbose:
- if "msg" in envelope:
- del envelope['msg']
- sys.stdout.write("Unknown message received\n")
- sys.stdout.write(pprint.pformat(envelope) + "\n")
- sys.stdout.write(pprint.pformat(msg) + "\n")
- return
- cmd = msg['command']
- if not (type(cmd) is list):
- if self.verbose:
- sys.stdout.write("Non-list command\n")
- return
-
+ # 'old' command style, uncommented for now
+ # move the handling below move to command_handler please
+ #def recv_and_process_cc_msg(self):
+ #"""Receive and process the next message on the c-channel,
+ #if any."""
+ #self.ccs.checkCommand()
+ #msg, envelope = self.cc_session.group_recvmsg(False)
+ #print(msg)
+ #if msg is None:
+ # return
+ #if not ((type(msg) is dict) and (type(envelope) is dict)):
+ # if self.verbose:
+ # sys.stdout.write("Non-dictionary message\n")
+ # return
+ #if not "command" in msg:
+ # if self.verbose:
+ # if "msg" in envelope:
+ # del envelope['msg']
+ # sys.stdout.write("Unknown message received\n")
+ # sys.stdout.write(pprint.pformat(envelope) + "\n")
+ # sys.stdout.write(pprint.pformat(msg) + "\n")
+ # return
+
+ #cmd = msg['command']
+ #if not (type(cmd) is list):
+ # if self.verbose:
+ # sys.stdout.write("Non-list command\n")
+ # return
+ #
# done checking and extracting... time to execute the command
- if cmd[0] == "shutdown":
- if self.verbose:
- sys.stdout.write("shutdown command received\n")
- self.runnable = False
- # XXX: reply here?
- elif cmd[0] == "getProcessList":
- if self.verbose:
- sys.stdout.write("getProcessList command received\n")
- live_processes = [ ]
- for proc_info in processes:
- live_processes.append({ "name": proc_info.name,
- "args": proc_info.args,
- "pid": proc_info.pid, })
- dead_processes = [ ]
- for proc_info in dead_processes:
- dead_processes.append({ "name": proc_info.name,
- "args": proc_info.args, })
- cc.group_reply(envelope, { "response": cmd,
- "sent": msg["sent"],
- "live_processes": live_processes,
- "dead_processes": dead_processes, })
- else:
- if self.verbose:
- sys.stdout.write("Unknown command %s\n" % str(cmd))
+ #if cmd[0] == "shutdown":
+ # if self.verbose:
+ # sys.stdout.write("shutdown command received\n")
+ # self.runnable = False
+ # # XXX: reply here?
+ #elif cmd[0] == "getProcessList":
+ # if self.verbose:
+ # sys.stdout.write("getProcessList command received\n")
+ # live_processes = [ ]
+ # for proc_info in processes:
+ # live_processes.append({ "name": proc_info.name,
+ # "args": proc_info.args,
+ # "pid": proc_info.pid, })
+ # dead_processes = [ ]
+ # for proc_info in dead_processes:
+ # dead_processes.append({ "name": proc_info.name,
+ # "args": proc_info.args, })
+ # cc.group_reply(envelope, { "response": cmd,
+ # "sent": msg["sent"],
+ # "live_processes": live_processes,
+ # "dead_processes": dead_processes, })
+ #else:
+ # if self.verbose:
+ # sys.stdout.write("Unknown command %s\n" % str(cmd))
def restart_processes(self):
"""Restart any dead processes."""
@@ -427,7 +439,7 @@
# In our main loop, we check for dead processes or messages
# on the c-channel.
wakeup_fd = wakeup_pipe[0]
- cc_fd = boss_of_bind.cc_session._socket.fileno()
+ ccs_fd = boss_of_bind.ccs.getSocket().fileno()
while boss_of_bind.runnable:
# XXX: get time for next restart for timeout
@@ -435,7 +447,7 @@
# even if they are resumable, so we have to catch
# the exception
try:
- (rlist, wlist, xlist) = select.select([wakeup_fd, cc_fd], [], [])
+ (rlist, wlist, xlist) = select.select([wakeup_fd, ccs_fd], [], [])
except select.error as err:
if err.args[0] == errno.EINTR:
(rlist, wlist, xlist) = ([], [], [])
@@ -444,8 +456,8 @@
break
for fd in rlist + xlist:
- if fd == cc_fd:
- boss_of_bind.recv_and_process_cc_msg()
+ if fd == ccs_fd:
+ boss_of_bind.ccs.checkCommand()
elif fd == wakeup_fd:
os.read(wakeup_fd, 32)
Modified: branches/parkinglot/src/bin/bindctl/bindctl.py
==============================================================================
--- branches/parkinglot/src/bin/bindctl/bindctl.py (original)
+++ branches/parkinglot/src/bin/bindctl/bindctl.py Thu Jan 28 00:09:16 2010
@@ -49,22 +49,11 @@
module.add_command(cmd)
tool.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:
tool = BindCmdInterpreter("localhost:8080")
prepare_config_commands(tool)
- prepare_boss_command(tool)
tool.run()
except Exception as e:
print(e)
Modified: branches/parkinglot/src/bin/cmd-ctrld/cmd-ctrld.py
==============================================================================
--- branches/parkinglot/src/bin/cmd-ctrld/cmd-ctrld.py (original)
+++ branches/parkinglot/src/bin/cmd-ctrld/cmd-ctrld.py Thu Jan 28 00:09:16 2010
@@ -108,7 +108,7 @@
def __init__(self):
self.cc = ISC.CC.Session()
self.cc.group_subscribe('Cmd-Ctrld')
- self.cc.group_subscribe('Boss', 'Cmd-Ctrld')
+ #self.cc.group_subscribe('Boss', 'Cmd-Ctrld')
self.command_spec = self.get_cmd_specification()
self.config_spec = self.get_data_specification()
self.config_data = self.get_config_data()
@@ -149,11 +149,6 @@
msg = {'command' : content}
print('cmd-ctrld send command \'%s\' to %s' %(command_name, module_name))
try:
- # Do special for Boss shutdown. TODO, avoid specicialism
- if module_name == 'Boss' and command_name == 'shutdown':
- self.cc.group_sendmsg(msg, module_name, 'boss')
- return {}
-
self.cc.group_sendmsg(msg, module_name)
answer, env = self.cc.group_recvmsg(False)
if answer and 'result' in answer.keys() and type(answer['result']) == list:
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 28 00:09:16 2010
@@ -70,7 +70,7 @@
{
isc::data::ElementPtr answer = isc::data::Element::createFromString("{ \"result\": [0] }");
- cout << "[XX] Handle command: " << endl << command->str() << endl;
+ cout << "[XX] Parkinglot handle command: " << endl << command->str() << endl;
if (command->get(0)->stringValue() == "print_message")
{
cout << command->get(1)->get("message") << endl;
Modified: branches/parkinglot/src/lib/config/cpp/ccsession.cc
==============================================================================
--- branches/parkinglot/src/lib/config/cpp/ccsession.cc (original)
+++ branches/parkinglot/src/lib/config/cpp/ccsession.cc Thu Jan 28 00:09:16 2010
@@ -90,8 +90,8 @@
session_.establish();
session_.subscribe(module_name, "*");
- session_.subscribe("Boss", "*");
- session_.subscribe("statistics", "*");
+ //session_.subscribe("Boss", "*");
+ //session_.subscribe("statistics", "*");
read_data_definition(spec_file_name);
sleep(1);
// send the data specification
Modified: branches/parkinglot/src/lib/config/python/bind-cfgd.py
==============================================================================
--- branches/parkinglot/src/lib/config/python/bind-cfgd.py (original)
+++ branches/parkinglot/src/lib/config/python/bind-cfgd.py Thu Jan 28 00:09:16 2010
@@ -91,6 +91,9 @@
cmd = msg["command"]
try:
if cmd[0] == "get_commands":
+ print("[XX] bind-cfgd got get_commands");
+ print("[XX] sending:")
+ print(self.commands)
answer["result"] = [ 0, self.commands ]
elif cmd[0] == "get_data_spec":
if len(cmd) > 1 and cmd[1]['module_name'] != '':
@@ -163,6 +166,9 @@
raise ie
elif "data_specification" in msg:
# todo: validate? (no direct access to spec as
+ # todo: use DataDefinition class?
+ print("[XX] bind-cfgd got specification:")
+ print(msg["data_specification"])
spec = msg["data_specification"]
if "config_data" in spec:
self.set_config(spec["module_name"], spec["config_data"])
Modified: branches/parkinglot/src/lib/config/python/isc/config/CCSession.py
==============================================================================
--- branches/parkinglot/src/lib/config/python/isc/config/CCSession.py (original)
+++ branches/parkinglot/src/lib/config/python/isc/config/CCSession.py Thu Jan 28 00:09:16 2010
@@ -41,9 +41,16 @@
self.__sendSpec()
self.__getFullConfig()
- #do we need getSocket()?
-
- def checkCommand():
+ def getSocket(self):
+ """Returns the socket from the command channel session"""
+ return self._session._socket
+
+ def getSession(self):
+ """Returns the command-channel session that is used, so the
+ application can use it directly"""
+ return self._session
+
+ def checkCommand(self):
"""Check whether there is a command on the channel.
Call the command callback function if so"""
msg, env = self._session.group_recvmsg(False)
More information about the bind10-changes
mailing list