summaryrefslogtreecommitdiff
path: root/python/mgmt-cli/managementdata.py
diff options
context:
space:
mode:
authorCarl C. Trieloff <cctrieloff@apache.org>2007-12-14 20:22:30 +0000
committerCarl C. Trieloff <cctrieloff@apache.org>2007-12-14 20:22:30 +0000
commit4930af608c6763a41eed4985bb5460a7bf8eb6b9 (patch)
treeb62c6e1dde2db62aaf9553ecb79e1a6f5d35dc32 /python/mgmt-cli/managementdata.py
parent5c65e1c2269ae3257010a7a3cbbc4bb57fff2053 (diff)
downloadqpid-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
Diffstat (limited to 'python/mgmt-cli/managementdata.py')
-rw-r--r--python/mgmt-cli/managementdata.py71
1 files changed, 59 insertions, 12 deletions
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)