Commit b49e1991 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

move prepare_module_commands to bigtool class

bigtool now listens to 'specification_update' and 'commands_update' commands for data_spec and module commands of modules that were not running yet at the time bigtool was started. no command for removal yet


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@352 e5f2f494-b856-4b98-b285-d166d9295462
parent f0d10833
......@@ -13,26 +13,9 @@ def _prepare_fake_data(bigtool):
bigtool.add_module_info(boss_module)
def prepare_module_commands(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 = command["command_description"],
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_commands(bigtool, command_spec):
for module_name in command_spec.keys():
prepare_module_commands(bigtool, module_name, command_spec[module_name])
bigtool.prepare_module_commands(module_name, command_spec[module_name])
def prepare_config_commands(bigtool):
module = ModuleInfo(name = "config", desc = "Configuration commands")
......@@ -84,7 +67,7 @@ def prepare_config_commands(bigtool):
if __name__ == '__main__':
try:
cc = ISC.CC.Session()
cc.group_subscribe("BigTool", "*", "meonly")
cc.group_subscribe("BigTool", "*")
cc.group_subscribe("ConfigManager", "*", "meonly")
cc.group_subscribe("Boss", "*", "meonly")
......
......@@ -2,8 +2,7 @@ import sys
import readline
from cmd import Cmd
from exception import *
from moduleinfo import ModuleInfo
from moduleinfo import ParamInfo
from moduleinfo import *
from command import BigToolCmd
from xml.dom import minidom
import ISC
......@@ -130,6 +129,8 @@ class BigTool(Cmd):
def onecmd(self, line):
# check if there's anything on the cc first
self.check_cc_messages()
if line == 'EOF' or line.lower() == "quit":
return True
......@@ -218,8 +219,35 @@ class BigTool(Cmd):
return []
def prepare_module_commands(self, module_name, module_commands):
module = ModuleInfo(name = module_name,
desc = "same here")
for command in module_commands:
cmd = CommandInfo(name = command["command_name"],
desc = command["command_description"],
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)
self.add_module_info(module)
def check_cc_messages(self):
(message, env) = self.cc.group_recvmsg(True)
while message:
if 'commands_update' in message:
self.prepare_module_commands(message['commands_update'][0], message['commands_update'][1])
elif 'specification_update' in message:
self.config_data.config.specification[message['specification_update'][0]] = message['specification_update'][1]
(message, env) = self.cc.group_recvmsg(True)
def _parse_cmd(self, line):
# check if there's anything on the cc first
self.check_cc_messages()
try:
cmd = BigToolCmd(line)
self.validate_cmd(cmd)
......
......@@ -74,17 +74,6 @@ class ConfigManager:
def remove_commands(self, module_name):
del self.commands[module_name]
def add_zone(self, zone_name):
self.config.add_zone(zone_name, "todo")
self.write_config()
print("sending update zone add")
self.cc.group_sendmsg({"zone_added": zone_name }, "ParkingLot")
def remove_zone(self, zone_name):
self.config.remove_zone(zone_name)
print("sending update zone del")
self.cc.group_sendmsg({"zone_deleted": zone_name }, "ParkingLot")
def read_config(self):
print("Reading config")
self.config = ConfigManagerData.read_from_file()
......@@ -164,8 +153,11 @@ class ConfigManager:
spec = msg["data_specification"]
if "config_data" in spec:
self.set_config(spec["module_name"], spec["config_data"])
self.cc.group_sendmsg({ "specification_update": [ spec["module_name"], spec["config_data"] ] }, "BigTool")
print("[XX] sent spec_update")
if "commands" in spec:
self.set_commands(spec["module_name"], spec["commands"])
self.cc.group_sendmsg({ "commands_update": [ spec["module_name"], spec["commands"] ] }, "BigTool")
answer["result"] = [ 0 ]
else:
print("unknown message: " + str(msg))
......
......@@ -163,7 +163,7 @@ class ConfigData:
class UIConfigData():
def __init__(self, name, cc):
self.module_name = name
data_spec = self.get_data_specification(cc)
data_spec = sel f.get_data_specification(cc)
self.config = ConfigData(data_spec)
self.get_config_data(cc)
self.config_changes = {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment