[svn] commit: r1626 - in /branches/trac90/src: bin/bindctl/bindcmd.py bin/cmdctl/cmdctl.py.in lib/python/isc/config/ccsession.py lib/python/isc/config/cfgmgr.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 22 13:44:38 UTC 2010
Author: jelte
Date: Mon Mar 22 13:44:38 2010
New Revision: 1626
Log:
b10-cmdctl now stores module specifications completely (instead of commands and config specifications separately)
bindctl uses this info to get module descriptions too
Modified:
branches/trac90/src/bin/bindctl/bindcmd.py
branches/trac90/src/bin/cmdctl/cmdctl.py.in
branches/trac90/src/lib/python/isc/config/ccsession.py
branches/trac90/src/lib/python/isc/config/cfgmgr.py
Modified: branches/trac90/src/bin/bindctl/bindcmd.py
==============================================================================
--- branches/trac90/src/bin/bindctl/bindcmd.py (original)
+++ branches/trac90/src/bin/bindctl/bindcmd.py Mon Mar 22 13:44:38 2010
@@ -180,13 +180,9 @@
def _update_commands(self):
- '''Get the commands of all modules. '''
- cmd_spec = self.send_GET('/command_spec')
- if not cmd_spec:
- return
-
- for module_name in cmd_spec.keys():
- self._prepare_module_commands(module_name, cmd_spec[module_name])
+ '''Update the commands of all modules. '''
+ for module_name in self.config_data.get_config_item_list():
+ self._prepare_module_commands(self.config_data.get_module_spec(module_name))
def send_GET(self, url, body = None):
'''Send GET request to cmdctl, session id is send with the name
@@ -222,11 +218,11 @@
self.prompt = self.location + self.prompt_end
return stop
- def _prepare_module_commands(self, module_name, module_commands):
+ def _prepare_module_commands(self, module_spec):
'''Prepare the module commands'''
- module = ModuleInfo(name = module_name,
- desc = "same here")
- for command in module_commands:
+ module = ModuleInfo(name = module_spec.get_module_name(),
+ desc = module_spec.get_module_description())
+ for command in module_spec.get_commands_spec():
cmd = CommandInfo(name = command["command_name"],
desc = command["command_description"])
for arg in command["command_args"]:
Modified: branches/trac90/src/bin/cmdctl/cmdctl.py.in
==============================================================================
--- branches/trac90/src/bin/cmdctl/cmdctl.py.in (original)
+++ branches/trac90/src/bin/cmdctl/cmdctl.py.in Mon Mar 22 13:44:38 2010
@@ -219,8 +219,7 @@
self._verbose = verbose
self.cc = isc.cc.Session()
self.cc.group_subscribe('Cmd-Ctrld')
- self.command_spec = self.get_cmd_specification()
- self.config_spec = self.get_data_specification()
+ self.module_spec = self.get_module_specification()
self.config_data = self.get_config_data()
def _parse_command_result(self, rcode, reply):
@@ -229,10 +228,6 @@
return {}
return reply
- def get_cmd_specification(self):
- rcode, reply = self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_COMMANDS_SPEC)
- return self._parse_command_result(rcode, reply)
-
def get_config_data(self):
'''Get config data for all modules from configmanager '''
rcode, reply = self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_CONFIG)
@@ -244,7 +239,7 @@
if module_name == 'ConfigManager' and command_name == isc.config.ccsession.COMMAND_SET_CONFIG:
self.config_data = self.get_config_data()
- def get_data_specification(self):
+ def get_module_specification(self):
rcode, reply = self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_MODULE_SPEC)
return self._parse_command_result(rcode, reply)
@@ -253,10 +248,8 @@
(message, env) = self.cc.group_recvmsg(True)
command, arg = isc.config.ccsession.parse_command(message)
while command:
- if command == isc.config.ccsession.COMMAND_COMMANDS_UPDATE:
- self.command_spec[arg[0]] = arg[1]
- elif command == isc.config.ccsession.COMMAND_SPECIFICATION_UPDATE:
- self.config_spec[arg[0]] = arg[1]
+ if command == isc.config.ccsession.COMMAND_MODULE_SPECIFICATION_UPDATE:
+ self.module_spec[arg[0]] = arg[1]
elif command == "shutdown":
return False
(message, env) = self.cc.group_recvmsg(True)
@@ -278,11 +271,12 @@
if module_name == 'ConfigManager':
return self.send_command(module_name, command_name, params)
- if module_name not in self.command_spec.keys():
+ if module_name not in self.module_spec.keys():
return 1, {'error' : 'unknown module'}
cmd_valid = False
- commands = self.command_spec[module_name]
+ # todo: make validate_command() in ModuleSpec class
+ commands = self.module_spec[module_name]["commands"]
for cmd in commands:
if cmd['command_name'] == command_name:
cmd_valid = True
@@ -383,12 +377,10 @@
'''Currently only support the following three url GET request '''
rcode, reply = http.client.NO_CONTENT, []
if not module:
- if id == 'command_spec':
- rcode, reply = http.client.OK, self.cmdctrl.command_spec
- elif id == 'config_data':
+ if id == 'config_data':
rcode, reply = http.client.OK, self.cmdctrl.config_data
- elif id == 'config_spec':
- rcode, reply = http.client.OK, self.cmdctrl.config_spec
+ elif id == 'module_spec':
+ rcode, reply = http.client.OK, self.cmdctrl.module_spec
return rcode, reply
Modified: branches/trac90/src/lib/python/isc/config/ccsession.py
==============================================================================
--- branches/trac90/src/lib/python/isc/config/ccsession.py (original)
+++ branches/trac90/src/lib/python/isc/config/ccsession.py Mon Mar 22 13:44:38 2010
@@ -81,8 +81,7 @@
# 'fixed' commands
"""Fixed names for command and configuration messages"""
COMMAND_CONFIG_UPDATE = "config_update"
-COMMAND_COMMANDS_UPDATE = "commands_update"
-COMMAND_SPECIFICATION_UPDATE = "specification_update"
+COMMAND_MODULE_SPECIFICATION_UPDATE = "module_specification_update"
COMMAND_GET_COMMANDS_SPEC = "get_commands_spec"
COMMAND_GET_CONFIG = "get_config"
@@ -313,16 +312,9 @@
# this step should be unnecessary but is the current way cmdctl returns stuff
# so changes are needed there to make this clean (we need a command to simply get the
# full specs for everything, including commands etc, not separate gets for that)
- specs = self._conn.send_GET('/config_spec')
- commands = self._conn.send_GET('/commands')
+ specs = self._conn.send_GET('/module_spec')
for module in specs.keys():
- cur_spec = { 'module_name': module }
- if module in specs and specs[module]:
- cur_spec['config_data'] = specs[module]
- if module in commands and commands[module]:
- cur_spec['commands'] = commands[module]
-
- self.set_specification(isc.config.ModuleSpec(cur_spec))
+ self.set_specification(isc.config.ModuleSpec(specs[module]))
def request_current_config(self):
"""Requests the current configuration from the configuration
Modified: branches/trac90/src/lib/python/isc/config/cfgmgr.py
==============================================================================
--- branches/trac90/src/lib/python/isc/config/cfgmgr.py (original)
+++ branches/trac90/src/lib/python/isc/config/cfgmgr.py Mon Mar 22 13:44:38 2010
@@ -148,11 +148,23 @@
if module_name in self.module_specs:
del self.module_specs[module_name]
- def get_module_spec(self, module_name):
+ def get_module_spec(self, module_name = None):
"""Returns the full ModuleSpec for the module with the given
- module_name"""
- if module_name in self.module_specs:
- return self.module_specs[module_name]
+ module_name. If no module name is given, a dict will
+ be returned with 'name': module_spec values. If the
+ module name is given, but does not exist, an empty dict
+ is returned"""
+ if module_name:
+ if module_name in self.module_specs:
+ return self.module_specs[module_name]
+ else:
+ # TODO: log error?
+ return {}
+ else:
+ result = {}
+ for module in self.module_specs:
+ result[module] = self.module_specs[module].get_full_spec()
+ return result
def get_config_spec(self, name = None):
"""Returns a dict containing 'module_name': config_spec for
@@ -201,13 +213,13 @@
if type(cmd) == dict:
if 'module_name' in cmd and cmd['module_name'] != '':
module_name = cmd['module_name']
- answer = isc.config.ccsession.create_answer(0, self.get_config_spec(module_name))
+ answer = isc.config.ccsession.create_answer(0, self.get_module_spec(module_name))
else:
answer = isc.config.ccsession.create_answer(1, "Bad module_name in get_module_spec command")
else:
answer = isc.config.ccsession.create_answer(1, "Bad get_module_spec command, argument not a dict")
else:
- answer = isc.config.ccsession.create_answer(0, self.get_config_spec())
+ answer = isc.config.ccsession.create_answer(0, self.get_module_spec())
return answer
def _handle_get_config(self, cmd):
@@ -303,14 +315,10 @@
# We should make one general 'spec update for module' that
# passes both specification and commands at once
- spec_update = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_SPECIFICATION_UPDATE,
- [ spec.get_module_name(), spec.get_config_spec() ])
+ spec_update = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_MODULE_SPECIFICATION_UPDATE,
+ [ spec.get_module_name(), spec.get_full_spec() ])
self.cc.group_sendmsg(spec_update, "Cmd-Ctrld")
- cmds_update = isc.config.ccsession.create_command(isc.config.ccsession.COMMAND_COMMANDS_UPDATE,
- [ spec.get_module_name(), spec.get_commands_spec() ])
- self.cc.group_sendmsg(cmds_update, "Cmd-Ctrld")
- answer = isc.config.ccsession.create_answer(0)
- return answer
+ return isc.config.ccsession.create_answer(0)
def handle_msg(self, msg):
"""Handle a command from the cc channel to the configuration manager"""
More information about the bind10-changes
mailing list