Author: justi9
Date: 2007-10-10 12:02:30 -0400 (Wed, 10 Oct 2007)
New Revision: 997
Modified:
mgmt/cumin/python/cumin/demo.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/cumin/page.strings
mgmt/cumin/python/cumin/widgets.py
Log:
Adds a server group type object for describing groups in different
dimensions. Adds a preliminary version of server browser-style
interface that uses types and groups. Extends mlink a little for use
in selection lists.
Modified: mgmt/cumin/python/cumin/demo.py
===================================================================
--- mgmt/cumin/python/cumin/demo.py 2007-10-10 14:38:09 UTC (rev 996)
+++ mgmt/cumin/python/cumin/demo.py 2007-10-10 16:02:30 UTC (rev 997)
@@ -14,23 +14,24 @@
def load(self):
# XXX need some locking in here
+ sgtypes = dict()
sgroups = dict()
for name in ("Geography", "Department"):
- sgroup = ServerGroup(self.model)
- sgroup.name = name
- sgroups[name] = sgroup
+ sgtype = ServerGroupType(self.model)
+ sgtype.name = name
+ sgtypes[name] = sgtype
for name in ("West Coast", "East Coast"):
sgroup = ServerGroup(self.model)
sgroup.name = name
- sgroups["Geography"].add_child(sgroup)
+ sgroup.set_type(sgtypes["Geography"])
sgroups[name] = sgroup
for name in ("Marketing", "Sales"):
sgroup = ServerGroup(self.model)
sgroup.name = name
- sgroups["Department"].add_child(sgroup)
+ sgroup.set_type(sgtypes["Department"])
sgroups[name] = sgroup
# vhost templates
@@ -71,6 +72,11 @@
else:
sgroups["West Coast"].add_server(server)
+ if server_count % 4 < 2:
+ sgroups["Marketing"].add_server(server)
+ else:
+ sgroups["Sales"].add_server(server)
+
vhost = VirtualHost(self.model)
vhost.name = "default"
vhost.set_server(server)
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-10-10 14:38:09 UTC (rev 996)
+++ mgmt/cumin/python/cumin/model.py 2007-10-10 16:02:30 UTC (rev 997)
@@ -8,6 +8,7 @@
self.cluster = ModelClass(self, "cluster")
self.server = ModelClass(self, "server")
self.server_group = ModelClass(self, "server_group")
+ self.server_group_type = ModelClass(self, "server_group_type")
self.virtual_host = ModelClass(self, "virtual_host")
self.virtual_host_group = ModelClass(self, "virtual_host_group")
self.queue = ModelClass(self, "queue")
@@ -31,6 +32,10 @@
assoc.add_endpoint(self.server, "server_group", "0..n")
assoc.add_endpoint(self.server_group, "server", "0..n")
+ assoc = ModelAssociation(self, "server_groups_to_server_group_type")
+ assoc.add_endpoint(self.server_group_type, "server_group",
"0..n")
+ assoc.add_endpoint(self.server_group, "type", "0..1")
+
assoc = ModelAssociation(self, "server_groups_to_server_groups")
assoc.add_endpoint(self.server_group, "parent", "0..n")
assoc.add_endpoint(self.server_group, "child", "0..n")
@@ -89,6 +94,12 @@
def get_server_groups(self):
return self.get_index(self.server_group).values()
+
+ def get_server_group_type(self, id):
+ return self.get_index(self.server_group_type).get(id)
+
+ def get_server_group_types(self):
+ return self.get_index(self.server_group_type).values()
def get_virtual_host(self, id):
return self.get_index(self.virtual_host).get(id)
@@ -145,6 +156,12 @@
self.name = None
+class ServerGroupType(ModelObject):
+ def __init__(self, model):
+ super(ServerGroupType, self).__init__(model, model.server_group_type)
+
+ self.name = None
+
class VirtualHost(ModelObject):
def __init__(self, model):
super(VirtualHost, self).__init__(model, model.virtual_host)
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-10 14:38:09 UTC (rev 996)
+++ mgmt/cumin/python/cumin/page.py 2007-10-10 16:02:30 UTC (rev 997)
@@ -172,7 +172,7 @@
self.groups = ServerGroupTree(app, "groups")
self.add_child(self.groups)
- self.servers = ServerSet(app, "servers")
+ self.servers = ServerBrowser(app, "servers")
self.add_child(self.servers)
def render_title(self, session, model):
@@ -201,3 +201,58 @@
def render_title(self, session, model):
return "Templates (%i)" % \
len(model.get_virtual_host_templates())
+
+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())
+
+ 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-10 14:38:09 UTC (rev 996)
+++ mgmt/cumin/python/cumin/page.strings 2007-10-10 16:02:30 UTC (rev 997)
@@ -26,10 +26,20 @@
color: #06c;
}
+a.selected {
+ color: black;
+}
+
ul {
list-style: none;
+ padding: 0;
+ margin: 0;
}
+ul > ul {
+ padding: 1em;
+}
+
span.none {
font-style: italic;
color: #999;
@@ -399,3 +409,19 @@
<td>10 queues, 5 exchanges</td>
<td><a class="action"
href="">Remove</a></td>
</tr>
+
+[ServerBrowser.css]
+.ServerBrowser.groups {
+ float: left;
+ width: 20%;
+}
+
+.ServerBrowser.servers {
+ width: 80%;
+}
+
+[ServerBrowser.html]
+<div class="ServerBrowser groups">
+{groups}
+</div>
+<div class="ServerBrowser servers">{servers}</div>
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-10-10 14:38:09 UTC (rev 996)
+++ mgmt/cumin/python/cumin/widgets.py 2007-10-10 16:02:30 UTC (rev 997)
@@ -7,8 +7,9 @@
def link(href, name):
return "<a href=\"%s\">%s</a>" % (href, name)
-def mlink(href, variety, name):
- return "<a href=\"%s\">%s</a>" % (href, name)
+def mlink(href, variety, name, selected=False):
+ return "<a %s href=\"%s\">%s</a>" % \
+ (selected and "class=\"selected\"" or "", href,
name)
def none():
return "<span class=\"none\">None</span>"