Commit 7529cf9c authored by Likun Zhang's avatar Likun Zhang
Browse files

1. Remove some unused path for BigTool.

2. Fix bug: can't parse the commands which don't have paramters correctly.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@213 e5f2f494-b856-4b98-b285-d166d9295462
parent a45fffd3
#! /bin/sh
PYTHON_EXEC=/usr/bin/python3
PYTHON_EXEC=python3
BIGTOOL_PATH=.
PYTHONPATH=../../lib/cc/python:../../lib/cc/python/ISC:../../lib/cc/python/ISC/CC:../../lib/cc/python/ISC/Util:../../lib/bigtool/
PYTHONPATH=../../lib/cc/python:../../lib/bigtool/
export PYTHONPATH
cd ${BIGTOOL_PATH}
......
from moduleinfo import *
from bigtool import *
import ISC
def _prepare_fake_data(bigtool):
add_cmd = CommandInfo(name = "add", desc = "add one zone")
remove_cmd = CommandInfo(name = 'remove', desc = 'remove one zone')
list_cmd = CommandInfo(name = 'list', desc = 'list all zones', need_inst_param = False)
list_cmd = CommandInfo(name = 'list', desc = 'list all zones',
need_inst_param = False)
zone_module = ModuleInfo(name = "zone",
inst_name = "zone_name",
inst_type = STRING_TYPE,
inst_desc = "the name of one zone",
desc = "manage all the zones")
zone_module.add_command(add_cmd)
zone_module.add_command(remove_cmd)
zone_module.add_command(list_cmd)
shutdown_cmd = CommandInfo(name = 'shutdown', desc = "stop bind10",
need_inst_param = False)
boss_module = ModuleInfo(name = "boss", desc = "boss of bind10")
boss_module.add_command(shutdown_cmd)
bigtool.add_module_info(zone_module)
bigtool.add_module_info(boss_module)
if __name__ == '__main__':
tool = BigTool()
_prepare_fake_data(tool)
tool.cmdloop()
try:
cc = ISC.CC.Session()
cc.group_subscribe("BigTool")
cc.group_subscribe("ConfigManager")
tool = BigTool(cc)
_prepare_fake_data(tool)
tool.cmdloop()
except ISC.CC.SessionError:
print("Failed to create cchannel session, "
"is the command channel daemon running?")
......@@ -27,19 +27,14 @@ CONST_COMMAND_NODE = "command"
class BigTool(Cmd):
"""simple bigtool example."""
def __init__(self):
def __init__(self, session = None):
Cmd.__init__(self)
self.prompt = '> '
self.ruler = '-'
self.modules = OrderedDict()
self.add_module_info(ModuleInfo("help", desc = "Get help for bigtool"))
try:
self.cc = ISC.CC.Session()
self.cc.group_subscribe("BigTool")
self.cc.group_subscribe("ConfigManager")
except ISC.CC.SessionError:
print("Failed to create cchannel session")
exit()
self.cc = session
def validate_cmd(self, cmd):
if not cmd.module in self.modules:
......@@ -226,15 +221,23 @@ class BigTool(Cmd):
def apply_cmd(self, cmd):
if not self.cc:
return
try:
msg ={"command": [cmd.module, cmd.command, list(cmd.params.values())[0]]}
print("begin to send the message...")
content = [cmd.module, cmd.command]
values = cmd.params.values()
if len(values) > 0:
content.append(list(values)[0])
msg = {"command":content}
print("begin to send the message...")
self.cc.group_sendmsg(msg, "ConfigManager")
print("waiting for configure manager reply...")
self.cc.group_sendmsg(msg, "ConfigManager")
print("waiting for configure manager reply...")
reply, env = self.cc.group_recvmsg(False)
print("received reply:", reply)
reply, env = self.cc.group_recvmsg(False)
print("received reply:", reply)
except ISC.CC.SessionError:
print("Error commucation with configure manager")
......
#! /bin/sh
PYTHON_EXEC=/usr/bin/python3
PYTHON_EXEC=python3
BIGTOOL_PATH=.
PYTHONPATH=../../lib/cc/python:../../lib/cc/python/ISC:../../lib/cc/python/ISC/CC:../../lib/cc/python/ISC/Util:../../lib/bigtool/
PYTHONPATH=../../lib/cc/python:../../lib/bigtool/
export PYTHONPATH
cd ${BIGTOOL_PATH}
......
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