Author: eallen
Date: 2010-07-06 14:16:21 -0400 (Tue, 06 Jul 2010)
New Revision: 4079
Modified:
mgmt/newdata/cumin/python/cumin/grid/limit.py
mgmt/newdata/cumin/python/cumin/grid/limit.strings
mgmt/newdata/cumin/python/cumin/grid/pool.py
Log:
Added Limits tab to Pool view.
Added Limits list to Limits view
Added SetLimit task
Modified: mgmt/newdata/cumin/python/cumin/grid/limit.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/limit.py 2010-07-06 18:13:12 UTC (rev 4078)
+++ mgmt/newdata/cumin/python/cumin/grid/limit.py 2010-07-06 18:16:21 UTC (rev 4079)
@@ -17,20 +17,35 @@
log = logging.getLogger("cumin.limit")
class LimitDataSet(object):
- def __init__(self, app, negotiator):
+ def __init__(self, app, collector):
self.app = app
- self.negotiator = negotiator
+ self.collector = collector
+ def get_negotiator(self, session):
+ collector = self.collector.get(session)
+ cls = self.app.model.com_redhat_grid.Negotiator
+
+ # TODO: why is there more than 1 negotiator?
+ negs = cls.get_selection(session.cursor, Pool=collector.Pool)
+ youngest = negs[0]
+ for neg in negs:
+ if neg._qmf_update_time > youngest._qmf_update_time:
+ youngest = neg
+ negotiator = youngest
+
+ return negotiator
+
def get_items(self, session):
- negotiator = self.negotiator.get(session)
+ negotiator = self.get_negotiator(session)
if not negotiator:
return
limits = self.app.model.get_negotiator_limits(negotiator)
- if limits is None:
+ if limits is None or len(limits) == 0:
return ()
+ #limits = {'a':{'CURRENT': 1, 'MAX': 2}}
keys = limits.keys()
keys.sort()
@@ -41,10 +56,10 @@
for x in keys]
class LimitSet(CuminItemTable):
- def __init__(self, app, name, negotiator):
+ def __init__(self, app, name, collector):
super(LimitSet, self).__init__(app, name)
- self.data = LimitDataSet(app, negotiator)
+ self.data = LimitDataSet(app, collector)
self.defer_enabled = True
@@ -60,32 +75,22 @@
col.align = "right"
self.add_column(col)
- self.limit_count = self.LimitCount(app, "limit_count")
- self.add_child(self.limit_count)
-
def do_get_items(self, session):
return self.data.get_items(session)
def render_title(self, session):
- return self.limit_count.render(session)
+ return "Limits"
- class LimitCount(Widget):
- def __init__(self, app, name):
- super(LimitSet.LimitCount, self).__init__(app, name)
-
- self.defer_enabled = True
- self.update_enabled = True
-
- def render_count(self, session):
- return len(self.parent.get_items(session))
-
class NameColumn(ItemTableColumn):
def render_title(self, session):
return "Name"
def render_content(self, session, data):
limit = data["name"]
- href = self.frame.limit.get_href(session, limit)
+ negotiator = self.parent.data.get_negotiator(session)
+ self.frame.limit.id.set(session, negotiator._id)
+ self.frame.limit.set_limit.form.limit_name.set(session, limit)
+ href = self.frame.limit.set_limit.get_href(session)
return fmt_link(href, limit)
class CurrentColumn(ItemTableColumn):
@@ -100,16 +105,76 @@
def get_default(self, session):
return dict()
-class LimitFrame(CuminFrame):
- def __init__(self, app, name, negotiator):
- super(LimitFrame, self).__init__(app, name)
+class LimitFrame(ObjectFrame):
+ def __init__(self, app, name):
+ cls = app.model.com_redhat_grid.Negotiator
- self.object = Parameter(app, "name")
- self.add_parameter(self.object)
+ super(LimitFrame, self).__init__(app, name, cls)
- self.view = LimitView(app, "view", negotiator, self.object)
- self.add_mode(self.view)
+ self.set_limit = NegotiatorLimitTask(app, self)
+class NegotiatorLimitTask(ObjectTask):
+ def __init__(self, app, frame):
+ super(NegotiatorLimitTask, self).__init__(app, frame)
+
+ self.form = NegotiatorLimitForm(app, self.name, self)
+
+ def get_title(self, session):
+ return "Set Limit"
+
+ def do_enter(self, session, osession):
+ self.form.limit_name.set(session, self.form.limit_name.get(osession))
+
+ def do_invoke(self, invoc, negotiator, limit_name, limit_max):
+ action = QmfCall(self.app)
+ results = action.execute(negotiator, "SetLimit", limit_name,
limit_max)
+
+ if results.error:
+ raise results.error
+
+ invoc.status_code = results.status
+ invoc.end()
+
+class NegotiatorLimitForm(ObjectTaskForm):
+ def __init__(self, app, name, task):
+ super(NegotiatorLimitForm, self).__init__(app, name, task)
+
+ self.limit_name = self.LimitName(app, "name")
+ self.add_field(self.limit_name)
+
+ self.limit_max = self.LimitMax(app, "max")
+ self.limit_max.required = True
+ self.add_field(self.limit_max)
+
+ def process_submit(self, session):
+ self.validate(session)
+
+ if not self.errors.get(session):
+ limit_name = self.limit_name.get(session)
+ limit_max = self.limit_max.get(session)
+ negotiator = self.object.get(session)
+
+ self.task.invoke(session, negotiator, limit_name, limit_max)
+ self.task.exit_with_redirect(session)
+
+ class LimitName(StringField):
+ def __init__(self, app, name):
+ super(NegotiatorLimitForm.LimitName, self).__init__(app, name)
+
+ self.input = self.DisabledInput(app, "input")
+ self.replace_child(self.input)
+
+ def render_title(self, session):
+ return "Limit name"
+
+ class DisabledInput(StringInput):
+ # used to override html and css
+ pass
+
+ class LimitMax(IntegerField):
+ def render_title(self, session):
+ return "Max Allowance"
+
class NegotiatorLimitSetForm(CuminForm):
def __init__(self, app, name, task):
super(LimitEdit, self).__init__(app, name)
@@ -151,7 +216,7 @@
self.task.exit_with_redirect(session)
class LimitView(CuminView):
- def __init__(self, app, name, negotiator, limit):
+ def __init__(self, app, name, limit):
super(LimitView, self).__init__(app, name, None)
self.tabs = TabbedModeSet(app, "tabs")
Modified: mgmt/newdata/cumin/python/cumin/grid/limit.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/limit.strings 2010-07-06 18:13:12 UTC (rev 4078)
+++ mgmt/newdata/cumin/python/cumin/grid/limit.strings 2010-07-06 18:16:21 UTC (rev 4079)
@@ -4,3 +4,29 @@
[LimitCount.deferred_html]
<span id="{id}">Limits <span
class="count">(?)</span></span>
+[DisabledInput.css]
+input.disabled {
+ border: 0px;
+ background-color: white;
+ color: black;
+ cursor:default;
+}
+
+[DisabledInput.html]
+<input class="disabled" type="text" name="{name}"
id="{name}" value="{value}" tabindex="{tab_index}"
size="{size}"/>
+<script type="text/javascript">
+//<![CDATA[
+// Using input attribute disabled="disabled' has the unfortunate side effect of
not sending the input value
+// when the form is submitted. So we just leave it enabled and filter out keyboard input
with javascript.
+window.addEvent("domready",
+ function () {
+ $("{name}").addEvent("keypress",
+ function (e) {
+ if (!(e.key in {tab:1, left:1, right:1}))
+ if (! (e.key == 'c' && e.control) )
+ new Event(e).stop();
+ } )
+ }
+);
+//]]>
+</script>
Modified: mgmt/newdata/cumin/python/cumin/grid/pool.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/pool.py 2010-07-06 18:13:12 UTC (rev 4078)
+++ mgmt/newdata/cumin/python/cumin/grid/pool.py 2010-07-06 18:16:21 UTC (rev 4079)
@@ -72,8 +72,8 @@
#self.collector = CollectorFrame(app, "coll")
#elf.add_mode(self.collector)
- #self.limit = LimitFrame(app, "limit", negotiator)
- #self.add_mode(self.limit)
+ self.limit = LimitFrame(app, "limit")
+ self.add_mode(self.limit)
overview = PoolOverview(app, "overview", self.object)
self.view.add_tab(overview)
@@ -92,8 +92,8 @@
negotiators = NegotiatorSelector(app, "negotiators", self.object)
self.view.add_tab(negotiators)
- #self.limits = LimitSet(app, "limits", negotiator)
- #self.view.add_tab(self.limits)
+ self.limits = LimitSet(app, "limits", self.object)
+ self.view.add_tab(self.limits)
self.submission_add = SubmissionAdd(app, self)