Author: eallen
Date: 2009-08-12 14:38:49 -0400 (Wed, 12 Aug 2009)
New Revision: 3569
Modified:
mgmt/trunk/cumin/python/cumin/model.py
Log:
Qmftasks return the string "OK" in the status_code instead of the number 0.
Added CuminNegotiator actions for getting/ setting config variables.
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2009-08-12 18:35:12 UTC (rev 3568)
+++ mgmt/trunk/cumin/python/cumin/model.py 2009-08-12 18:38:49 UTC (rev 3569)
@@ -155,6 +155,7 @@
self.form = None
self.aggregate = False
+ self.navigable = True
if self.cls:
if self.__class__ not in self.cls.tasks_by_class:
@@ -314,7 +315,7 @@
def completion(status_code, output_args):
invoc.last_change_time = datetime.now()
- if status_code == 0:
+ if status_code == 0 or status_code == "OK":
invoc.status = invoc.OK
else:
invoc.status = invoc.FAILED
@@ -2413,6 +2414,12 @@
action = GetStartedAction(self, "GetStarted")
action.navigable = False
+ action = self.GetConfigSet(self, "GetConfigSet")
+ action.navigable = False
+
+ action = self.GetRawConfig(self, "GetRawConfig")
+ action.navigable = False
+
def init(self):
super(CuminNegotiator, self).init()
@@ -2424,25 +2431,100 @@
def get_object_name(self, neg):
return neg.Name
+ class GetRawConfig(CuminAction):
+ def do_invoke(self, negotiator, config_name, timeout=5):
+ self.data = None
+ self.got_data = False
+ self.error = False
+
+ def completion(status, data):
+ self.data = data
+ self.got_data = True
+
+ def predicate():
+ return self.got_data or self.error
+
+ try:
+ negotiator.GetRawConfig(self.mint.model, completion, config_name, None)
+ except Exception, e:
+ self.error = True
+
+ wait(predicate, timeout=timeout)
+ return self.data
+
+ class GetConfigSet(CuminAction):
+ """ send a set or qmf requests at the same time and wait for
+ them all to complete or timeout """
+
+ def do_invoke(self, negotiator, groups, prepend="",
method="GetStats", timeout=5):
+ def predicate(calls):
+ done = 0
+ for call in calls:
+ if call.done():
+ done = done + 1
+ return done == len(calls)
+
+ calls = list()
+ for group in groups:
+ call = self.StatGetter()
+ calls.append(call)
+ call.invoke(self.mint.model, negotiator, group, prepend, method,
{'Value': 0})
+
+ wait(predicate, timeout=timeout, args=calls)
+
+ return [(call.group, call.data, (call.status, call.error, call.got_data))
+ for call in calls]
+
+ class StatGetter(object):
+ def invoke(self, model, negotiator, group, prepend, method, default):
+ self.data = default
+ self.group = group
+ self.got_data = False
+ self.error = False
+ self.status = None
+
+ def completion(status, data):
+ self.status = status
+ if (status == 0) or (status == "OK"):
+ self.data = data
+ self.got_data = True
+ else:
+ self.error = True
+
+ try:
+ if method == "GetStats":
+ negotiator.GetStats(model, completion, group, None)
+ elif method == "GetRawConfig":
+ negotiator.GetRawConfig(model, completion, prepend+group, None)
+ except Exception, e:
+ self.error = True
+
+ def done(self):
+ return self.got_data or self.error
+
class GetLimits(CuminAction):
def do_invoke(self, negotiator):
self.lim = dict()
self.got_data = False
+ self.error = False
def completion(status, data):
- self.lim = data["Limits"]
- self.got_data = True
+ try:
+ self.lim = data["Limits"]
+ self.got_data = True
+ except KeyError:
+ self.error = True
def predicate():
- return self.got_data
+ return self.got_data or self.error
try:
negotiator.GetLimits(self.mint.model, completion, None)
except Exception, e:
return self.lim
- # wait for up to 5 seconds for completion to be called
- wait(predicate, timeout=5)
+ # wait a couple of seconds for completion to be called
+ wait(predicate, timeout=2)
if not self.got_data:
self.lim["timeout"] = True
return self.lim