diff options
author | Carl C. Trieloff <cctrieloff@apache.org> | 2007-12-14 20:22:30 +0000 |
---|---|---|
committer | Carl C. Trieloff <cctrieloff@apache.org> | 2007-12-14 20:22:30 +0000 |
commit | 4930af608c6763a41eed4985bb5460a7bf8eb6b9 (patch) | |
tree | b62c6e1dde2db62aaf9553ecb79e1a6f5d35dc32 | |
parent | 5c65e1c2269ae3257010a7a3cbbc4bb57fff2053 (diff) | |
download | qpid-python-4930af608c6763a41eed4985bb5460a7bf8eb6b9.tar.gz |
patch from tross
QPID-706
Added implementation for the "Call" command to invoke methods on management objects.
Fixed a bug in qpid/management.py caused by replies to methods with no arguments.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@604286 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | python/mgmt-cli/main.py | 3 | ||||
-rw-r--r-- | python/mgmt-cli/managementdata.py | 71 | ||||
-rw-r--r-- | python/qpid/management.py | 12 |
3 files changed, 68 insertions, 18 deletions
diff --git a/python/mgmt-cli/main.py b/python/mgmt-cli/main.py index 2990e25437..4d7c03d1f2 100755 --- a/python/mgmt-cli/main.py +++ b/python/mgmt-cli/main.py @@ -48,11 +48,12 @@ class Mcli (Cmd): print " list - Print summary of existing objects by class" print " list <className> - Print list of objects of the specified class" print " list <className> all - Print contents of all objects of specified class" + print " list <className> active - Print contents of all non-deleted objects of specified class" print " list <className> <list-of-IDs> - Print contents of one or more objects" print " list is space-separated, ranges may be specified (i.e. 1004-1010)" print " call <ID> <methodName> [<args>] - Invoke a method on an object" print " schema - Print summary of object classes seen on the target" - print " schema [className] - Print details of an object class" + print " schema <className> - Print details of an object class" print " set time-format short - Select short timestamp format (default)" print " set time-format long - Select long timestamp format" print " quit or ^D - Exit the program" diff --git a/python/mgmt-cli/managementdata.py b/python/mgmt-cli/managementdata.py index b770677825..2adb962b54 100644 --- a/python/mgmt-cli/managementdata.py +++ b/python/mgmt-cli/managementdata.py @@ -90,9 +90,16 @@ class ManagementData: finally: self.lock.release () - def methodReply (self, broker, methodId, status, sText, args): + def methodReply (self, broker, sequence, status, sText, args): """ Callback for method-reply messages """ - pass + self.lock.acquire () + try: + line = "Call Result: " + self.methodsPending[sequence] + \ + " " + str (status) + " (" + sText + ")" + print line, args + del self.methodsPending[sequence] + finally: + self.lock.release () def schemaHandler (self, context, className, configs, insts, methods, events): """ Callback for schema updates """ @@ -106,11 +113,13 @@ class ManagementData: self.broker.instrumentationListener (1, self.dataHandler) self.broker.methodListener (None, self.methodReply) self.broker.schemaListener (None, self.schemaHandler) - self.lock = Lock () - self.tables = {} - self.schema = {} - self.baseId = 0 - self.disp = disp + self.lock = Lock () + self.tables = {} + self.schema = {} + self.baseId = 0 + self.disp = disp + self.methodSeq = 1 + self.methodsPending = {} self.broker.start () def close (self): @@ -186,6 +195,11 @@ class ManagementData: for id in self.tables[className]: list.append (id - self.baseId) + elif tokens[0] == "active": + for id in self.tables[className]: + if self.tables[className][id][0][2] == 0: + list.append (id - self.baseId) + else: for token in tokens: if token.find ("-") != -1: @@ -362,10 +376,8 @@ class ManagementData: titles = ("Element", "Type", "Unit", "Access", "Notes", "Description") self.disp.table ("Schema for class '%s':" % className, titles, rows) - for method in self.schema[className][2]: - mname = method[0] - mdesc = method[1] - args = method[2] + for mname in self.schema[className][2]: + (mdesc, args) = self.schema[className][2][mname] caption = "\nMethod '%s' %s" % (mname, self.notNone (mdesc)) rows = [] for arg in args: @@ -398,6 +410,33 @@ class ManagementData: return className return None + def callMethod (self, userOid, methodName, args): + self.lock.acquire () + methodOk = True + try: + className = self.getClassForId (userOid + self.baseId) + if className == None: + raise ValueError () + + schemaMethod = self.schema[className][2][methodName] + if len (args) != len (schemaMethod[1]): + print "Wrong number of method args: Need %d, Got %d" % (len (schemaMethod[1]), len (args)) + raise ValueError () + + namedArgs = {} + for idx in range (len (args)): + namedArgs[schemaMethod[1][idx][0]] = args[idx] + + self.methodSeq = self.methodSeq + 1 + self.methodsPending[self.methodSeq] = methodName + except: + methodOk = False + print "Error in call syntax" + self.lock.release () + if methodOk: + self.broker.method (self.methodSeq, userOid + self.baseId, className, + methodName, namedArgs) + def do_list (self, data): tokens = data.split () if len (tokens) == 0: @@ -414,4 +453,12 @@ class ManagementData: self.schemaTable (data) def do_call (self, data): - print "Not yet implemented" + tokens = data.split () + if len (tokens) < 2: + print "Not enough arguments supplied" + return + + userOid = long (tokens[0]) + methodName = tokens[1] + args = tokens[2:] + self.callMethod (userOid, methodName, args) diff --git a/python/qpid/management.py b/python/qpid/management.py index 8373ecceb7..1c8b3cd840 100644 --- a/python/qpid/management.py +++ b/python/qpid/management.py @@ -108,7 +108,7 @@ class ManagementMetadata: configs = [] insts = [] - methods = [] + methods = {} events = [] configs.append (("id", 4, "", "", 1, 1, None, None, None, None, None)) @@ -195,7 +195,7 @@ class ManagementMetadata: arg = (name, type, dir, unit, desc, min, max, maxlen, default) args.append (arg) - methods.append ((mname, mdesc, args)) + methods[mname] = (mdesc, args) self.schema[(className,'C')] = configs @@ -297,18 +297,19 @@ class ManagedBroker: return (userSequence, className, methodName) = data + args = {} if status == 0: ms = self.metadata.schema[(className,'M')] arglist = None - for (mname, mdesc, margs) in ms: + for mname in ms: + (mdesc, margs) = ms[mname] if mname == methodName: arglist = margs if arglist == None: msg.complete () return - args = {} for arg in arglist: if arg[2].find("O") != -1: args[arg[0]] = self.metadata.decodeValue (codec, arg[1]) @@ -379,7 +380,8 @@ class ManagedBroker: ms = self.metadata.schema[(className,'M')] arglist = None - for (mname, mdesc, margs) in ms: + for mname in ms: + (mdesc, margs) = ms[mname] if mname == methodName: arglist = margs if arglist == None: |