Author: justi9
Date: 2007-10-12 15:42:02 -0400 (Fri, 12 Oct 2007)
New Revision: 1027
Added:
mgmt/cumin/python/cumin/util.py
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/server.py
mgmt/cumin/python/cumin/server.strings
Log:
Makes the server browser view (with group dimensions) the default
server view. Adds a utility function for sorting objects by their
attributes.
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-12 18:13:33 UTC (rev 1026)
+++ mgmt/cumin/python/cumin/page.py 2007-10-12 19:42:02 UTC (rev 1027)
@@ -7,6 +7,7 @@
from server import *
from cluster import *
from widgets import *
+from util import *
strings = StringCatalog(__file__)
@@ -123,9 +124,6 @@
self.server = ServerFrame(app, "server")
self.add_child(self.server)
- self.sgroup = ServerGroupFrame(app, "sgroup")
- self.add_child(self.sgroup)
-
self.cluster = ClusterFrame(app, "cluster")
self.add_child(self.cluster)
@@ -143,10 +141,6 @@
self.server.set_server(session, server)
return self.show_mode(session, self.server)
- def show_server_group(self, session, sgroup):
- self.sgroup.set_server_group(session, sgroup)
- return self.show_mode(session, self.sgroup)
-
def show_cluster(self, session, cluster):
self.cluster.set_cluster(session, cluster)
return self.show_mode(session, self.cluster)
@@ -167,19 +161,9 @@
def render_title(self, session, model):
return "Red Hat Messaging"
- class ServerTab(TabSet):
- def __init__(self, app, name):
- super(MainView.ServerTab, self).__init__(app, name)
+ class ServerTab(ServerBrowser):
+ pass
- self.groups = ServerGroupTree(app, "groups")
- self.add_child(self.groups)
-
- self.servers = ServerBrowser(app, "servers")
- self.add_child(self.servers)
-
- def render_title(self, session, model):
- return "Servers (%i)" % len(model.get_servers())
-
class ClusterTab(Widget):
def __init__(self, app, name):
super(MainView.ClusterTab, self).__init__(app, name)
@@ -189,65 +173,3 @@
def render_title(self, session, model):
return self.clusters.render_title(session, model)
-
-class ServerBrowser(Widget):
- def __init__(self, app, name):
- super(ServerBrowser, self).__init__(app, name)
-
- self.param = ServerGroupParameter(app, "param")
- self.add_parameter(self.param)
-
- self.groups = self.BrowserGroups(app, "groups")
- self.add_child(self.groups)
-
- self.servers = self.BrowserServers(app, "servers")
- self.add_child(self.servers)
-
- def render_title(self, session, model):
- return "Servers (%i)" % len(model.get_servers())
-
- def render_show_all_link(self, session, model):
- class_ = self.param.get(session) is None and "selected"
-
- branch = session.branch()
- self.param.set(branch, None)
- return link(branch.marshal(), "Show All", class_)
-
- class BrowserGroups(ItemSet):
- def __init__(self, app, name):
- super(ServerBrowser.BrowserGroups, self).__init__(app, name)
-
- def get_items(self, session, model):
- return sorted(model.get_server_groups(), cmp, lambda x: x.name)
-
- def render_items(self, session, model):
- writer = Writer()
-
- last_type = None
- groups = self.get_items(session, model)
-
- if groups:
- for group in groups:
- if group.get_type() is not last_type:
- pass
-
- self.item_tmpl.render(session, group, writer)
-
- return writer.to_string()
-
- def render_item_content(self, session, group):
- branch = session.branch()
- self.parent.param.set(branch, group)
-
- selected = self.parent.param.get(session) is group
-
- return mlink(branch.marshal(), "ServerGroup", group.name,
selected)
-
- class BrowserServers(ServerSet):
- def get_items(self, session, model):
- group = self.parent.param.get(session)
-
- if group:
- return sorted(group.server_items(), cmp, lambda x: x.name)
- else:
- return sorted(model.get_servers(), cmp, lambda x: x.name)
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-10-12 18:13:33 UTC (rev 1026)
+++ mgmt/cumin/python/cumin/page.strings 2007-10-12 19:42:02 UTC (rev 1027)
@@ -390,33 +390,9 @@
{tabs}
</div>
-[ServerTab.html]
-<ul class="radiotabs tabs">{tabs}</ul>
-<div class="mode">{mode}</div>
-
[ClusterTab.html]
<ul class="actions">
<li><a href="">Add Cluster</a></li>
</ul>
{clusters}
-
-[ServerBrowser.css]
-.ServerBrowser.groups {
- float: left;
- width: 20%;
-}
-
-.ServerBrowser.servers {
- width: 80%;
-}
-
-[ServerBrowser.html]
-<div class="ServerBrowser groups">
- {show_all_link}
-
- <br/><br/>
-
- {groups}
-</div>
-<div class="ServerBrowser servers">{servers}</div>
Modified: mgmt/cumin/python/cumin/server.py
===================================================================
--- mgmt/cumin/python/cumin/server.py 2007-10-12 18:13:33 UTC (rev 1026)
+++ mgmt/cumin/python/cumin/server.py 2007-10-12 19:42:02 UTC (rev 1027)
@@ -3,6 +3,7 @@
from virtualhost import *
from widgets import *
+from util import *
strings = StringCatalog(__file__)
@@ -86,9 +87,6 @@
def __init__(self, app, name):
super(ServerView, self).__init__(app, name)
- self.groups = self.ServerServerGroups(app, "groups")
- self.add_child(self.groups)
-
self.tabs = TabSet(app, "tabs")
self.add_child(self.tabs)
@@ -115,10 +113,6 @@
return html
- class ServerServerGroups(ServerGroupSet):
- def get_items(self, session, server):
- return sorted(server.server_group_items(), cmp, lambda x: x.name)
-
class VirtualHostTab(VirtualHostSet):
def render_title(self, session, server):
return "Functional Hosts (%i)" % len(server.virtual_host_items())
@@ -138,30 +132,75 @@
def render_title(self, session, server):
return "Log Messages"
-class ServerGroupTree(ItemTree):
- def render_title(self, session, model):
- return "Groups (%i)" % len(model.get_server_groups())
+class ServerBrowser(Widget):
+ def __init__(self, app, name):
+ super(ServerBrowser, self).__init__(app, name)
+
+ self.param = ServerGroupParameter(app, "param")
+ self.add_parameter(self.param)
- def get_items(self, session, model):
- roots = list()
+ self.groups = self.BrowserGroups(app, "groups")
+ self.add_child(self.groups)
- for group in model.get_server_groups():
- if not group.parent_items():
- roots.append(group)
+ self.servers = self.BrowserServers(app, "servers")
+ self.add_child(self.servers)
- return roots
+ def render_title(self, session, model):
+ return "Servers (%i)" % len(model.get_servers())
- def get_child_items(self, session, group):
- return group.child_items()
+ def render_all_servers_link(self, session, model):
+ class_ = self.param.get(session) is None and "selected"
- def render_item_href(self, session, group):
branch = session.branch()
- self.page().show_server_group(branch, group).show_view(branch)
- return branch.marshal()
+ self.param.set(branch, None)
+ return link(branch.marshal(), "All Servers", class_)
- def render_item_name(self, session, group):
- return group.name
+ class BrowserGroups(Widget):
+ def __init__(self, app, name):
+ super(ServerBrowser.BrowserGroups, self).__init__(app, name)
+ self.type_tmpl = Template(self, "type_html")
+ self.group_tmpl = Template(self, "group_html")
+
+ def get_items(self, session, model):
+ return sorted(model.get_server_group_types(), cmp, lambda x: x.name)
+
+ def render_types(self, session, model):
+ writer = Writer()
+
+ for type in self.get_items(session, model):
+ self.type_tmpl.render(session, type, writer)
+
+ return writer.to_string()
+
+ def render_type_name(self, session, type):
+ return type.name
+
+ def render_groups(self, session, type):
+ writer = Writer()
+
+ for group in csorted(type.server_group_items()):
+ self.group_tmpl.render(session, group, writer)
+
+ return writer.to_string()
+
+ def render_group_link(self, session, group):
+ branch = session.branch()
+ self.parent.param.set(branch, group)
+
+ selected = self.parent.param.get(session) is group
+
+ return mlink(branch.marshal(), "ServerGroup", group.name,
selected)
+
+ class BrowserServers(ServerSet):
+ def get_items(self, session, model):
+ group = self.parent.param.get(session)
+
+ if group:
+ return sorted(group.server_items(), cmp, lambda x: x.name)
+ else:
+ return sorted(model.get_servers(), cmp, lambda x: x.name)
+
class ServerGroupParameter(Parameter):
def do_unmarshal(self, string):
return self.app.model.get_server_group(int(string))
@@ -186,9 +225,6 @@
def show_view(self, session):
self.show_mode(session, self.view)
- def render_title(self, session, group):
- return "Server Group '%s'" % group.name
-
class ServerGroupView(Widget):
def __init__(self, app, name):
super(ServerGroupView, self).__init__(app, name)
Modified: mgmt/cumin/python/cumin/server.strings
===================================================================
--- mgmt/cumin/python/cumin/server.strings 2007-10-12 18:13:33 UTC (rev 1026)
+++ mgmt/cumin/python/cumin/server.strings 2007-10-12 19:42:02 UTC (rev 1027)
@@ -28,7 +28,6 @@
<dl class="properties">
<dt>Name</dt><dd>{name}</dd>
<dt>Cluster</dt><dd>{cluster_link}</dd>
- <dt>Server Groups</dt><dd>{groups}</dd>
</dl>
<ul class="actions">
@@ -66,36 +65,53 @@
}
</pre>
-[ServerGroupTree.css]
-ul.ServerGroupTree, ul.ServerGroupTree ul {
- list-style: square;
- color: #ccc;
- padding: 0 0 0 2em;
+[ServerBrowser.css]
+.ServerBrowser.groups {
+ float: left;
+ width: 20%;
}
-ul.ServerGroupTree {
- padding: 0 0 0 1em;
+.ServerBrowser.groups a.selected {
+ font-weight: bold;
}
-[ServerGroupTree.html]
-<ul class="ServerGroupTree">{items}</ul>
+.ServerBrowser.groups ul {
+ margin: 0 0 1em 0;
+}
-[ServerGroupTree.item_html]
-<li><a href="{item_href}">{item_name}</a></li>
-<ul>{child_items}</ul>
+.ServerBrowser.groups h2 {
+ color: #afbf27;
+ font-weight: bold;
+}
-[ServerGroupView.html]
-<div class="oblock">
- <h1>{title}</h1>
+.ServerBrowser.servers {
+ width: 80%;
+}
- <dl class="properties">
- <dt>Parent Groups</dt><dd>{parent_groups}</dd>
- </dl>
-
+[ServerBrowser.html]
+<div class="ServerBrowser groups">
+ <ul><li>{all_servers_link}</li></ul>
+ {groups}
+</div>
+<div class="ServerBrowser servers">
<ul class="actions">
<li><a href="">Add Server</a></li>
- <li><a href="">Shutdown Servers in This
Group</a></li>
+ <li><a href="">Shutdown Servers</a></li>
</ul>
- {tabs}
+ {servers}
</div>
+
+[BrowserGroups.html]
+{types}
+
+<ul class="actions">
+ <li><a href="">Add Group</a>
+</ul>
+
+[BrowserGroups.type_html]
+<h2>{type_name}</h2>
+<ul>{groups}</ul>
+
+[BrowserGroups.group_html]
+<li>{group_link}</li>
Added: mgmt/cumin/python/cumin/util.py
===================================================================
--- mgmt/cumin/python/cumin/util.py (rev 0)
+++ mgmt/cumin/python/cumin/util.py 2007-10-12 19:42:02 UTC (rev 1027)
@@ -0,0 +1,2 @@
+def csorted(seq, attr="name"):
+ return sorted(seq, cmp, lambda x: getattr(x, attr))