summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAndrew Brestick <brestick@mcs.anl.gov>2008-08-01 14:44:20 +0000
committerAndrew Brestick <brestick@mcs.anl.gov>2008-08-01 14:44:20 +0000
commit4597031f28922b680fb67e522790aae01d8a9984 (patch)
treed1ca4b6bfa5fa0489c1d172ea76fa8500e8c507f /src/lib
parente9e94e78bb52ca2ec36e3f3402dbde3f8289cdf3 (diff)
downloadbcfg2-4597031f28922b680fb67e522790aae01d8a9984.tar.gz
bcfg2-4597031f28922b680fb67e522790aae01d8a9984.tar.bz2
bcfg2-4597031f28922b680fb67e522790aae01d8a9984.zip
support for alternate metadata plugins in viz admin mode
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4846 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Admin/Viz.py68
-rw-r--r--src/lib/Server/Plugin.py4
-rw-r--r--src/lib/Server/Plugins/BB.py67
-rw-r--r--src/lib/Server/Plugins/Metadata.py64
4 files changed, 130 insertions, 73 deletions
diff --git a/src/lib/Server/Admin/Viz.py b/src/lib/Server/Admin/Viz.py
index d2eeb3370..138cc4aaf 100644
--- a/src/lib/Server/Admin/Viz.py
+++ b/src/lib/Server/Admin/Viz.py
@@ -48,7 +48,6 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
def Visualize(self, repopath, raw=False, hosts=False,
bundles=False, key=False, output=False):
'''Build visualization of groups file'''
- groups = self.metadata.get_groups()
if raw:
cmd = "dd bs=4M"
if output:
@@ -58,73 +57,13 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
if output:
cmd += " -o %s" % output
dotpipe = popen2.Popen4(cmd)
- categories = {'default':'grey83'}
- instances = {}
- egroups = groups.findall("Group") + groups.findall('.//Groups/Group')
- for group in egroups:
- if not categories.has_key(group.get('category')):
- categories[group.get('category')] = self.colors.pop()
- group.set('color', categories[group.get('category')])
- if None in categories:
- del categories[None]
-
try:
dotpipe.tochild.write("digraph groups {\n")
except:
print "write to dot process failed. Is graphviz installed?"
raise SystemExit(1)
dotpipe.tochild.write('\trankdir="LR";\n')
-
- if hosts:
- clients = self.metadata.clients
- for client, profile in clients.iteritems():
- if instances.has_key(profile):
- instances[profile].append(client)
- else:
- instances[profile] = [client]
- for profile, clist in instances.iteritems():
- clist.sort()
- dotpipe.tochild.write(
- '''\t"%s-instances" [ label="%s", shape="record" ];\n''' \
- % (profile, '|'.join(clist)))
- dotpipe.tochild.write('''\t"%s-instances" -> "group-%s";\n''' \
- % (profile, profile))
-
- if bundles:
- bundles = []
- [bundles.append(bund.get('name')) \
- for bund in groups.findall('.//Bundle')
- if bund.get('name') not in bundles]
- bundles.sort()
- for bundle in bundles:
- dotpipe.tochild.write(
- '''\t"bundle-%s" [ label="%s", shape="septagon"];\n''' \
- % (bundle, bundle))
- gseen = []
- for group in egroups:
- if group.get('profile', 'false') == 'true':
- style = "filled, bold"
- else:
- style = "filled"
- gseen.append(group.get('name'))
- dotpipe.tochild.write(
- '\t"group-%s" [label="%s", style="%s", fillcolor=%s];\n' %
- (group.get('name'), group.get('name'), style, group.get('color')))
- if bundles:
- for bundle in group.findall('Bundle'):
- dotpipe.tochild.write('\t"group-%s" -> "bundle-%s";\n' %
- (group.get('name'), bundle.get('name')))
-
- gfmt = '\t"group-%s" [label="%s", style="filled", fillcolor="grey83"];\n'
- for group in egroups:
- for parent in group.findall('Group'):
- if parent.get('name') not in gseen:
- dotpipe.tochild.write(gfmt % (parent.get('name'),
- parent.get('name')))
- gseen.append(parent.get("name"))
- dotpipe.tochild.write('\t"group-%s" -> "group-%s" ;\n' %
- (group.get('name'), parent.get('name')))
-
+ dotpipe.tochild.write(self.metadata.viz(hosts, bundles, key, self.colors))
if key:
dotpipe.tochild.write("\tsubgraph cluster_key {\n")
dotpipe.tochild.write('''\tstyle="filled";\n''')
@@ -133,11 +72,6 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
dotpipe.tochild.write('''\tGroup [shape="ellipse"];\n''')
dotpipe.tochild.write('''\tProfile [style="bold", shape="ellipse"];\n''')
dotpipe.tochild.write('''\tHblock [label="Host1|Host2|Host3", shape="record"];\n''')
- for category in categories:
- dotpipe.tochild.write(
- '''\t"''' + category + '''" [label="''' + category + \
- '''", shape="record", style="filled", fillcolor=''' + \
- categories[category] + '''];\n''')
dotpipe.tochild.write('''\tlabel="Key";\n''')
dotpipe.tochild.write("\t}\n")
dotpipe.tochild.write("}\n")
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 114e0b039..4fa4e2cbe 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -85,8 +85,8 @@ class MetadataPlugin(Plugin):
def remove_client(self, client_name):
'''remove client'''
pass
- def get_groups(self):
- '''get groups xml tree'''
+ def viz(self, hosts, bundles, key, colors):
+ '''create viz str for viz admin mode'''
pass
class ProbingPlugin(Plugin):
diff --git a/src/lib/Server/Plugins/BB.py b/src/lib/Server/Plugins/BB.py
index 50badb7a3..858ab8102 100644
--- a/src/lib/Server/Plugins/BB.py
+++ b/src/lib/Server/Plugins/BB.py
@@ -46,11 +46,70 @@ class BB(Bcfg2.Server.Plugin.GeneratorPlugin,
self.dhcpd_loaded = False
self.need_update = False
- def get_groups(self):
- '''get groups xml tree'''
+ def viz(self, hosts, bundles, key, colors):
+ '''admin mode viz support'''
groups_tree = lxml.etree.parse(self.data + "/groups.xml")
- root = groups_tree.getroot()
- return root
+ groups = groups_tree.getroot()
+ categories = {'default':'grey83'}
+ instances = {}
+ viz_str = ""
+ egroups = groups.findall("Group") + groups.findall('.//Groups/Group')
+ for group in egroups:
+ if not categories.has_key(group.get('category')):
+ categories[group.get('category')] = colors.pop()
+ group.set('color', categories[group.get('category')])
+ if None in categories:
+ del categories[None]
+ if hosts:
+ clients = self.clients
+ for client, profile in clients.iteritems():
+ if instances.has_key(profile):
+ instances[profile].append(client)
+ else:
+ instances[profile] = [client]
+ for profile, clist in instances.iteritems():
+ clist.sort()
+ viz_str += '''\t"%s-instances" [ label="%s", shape="record" ];\n''' \
+ % (profile, '|'.join(clist))
+ viz_str += '''\t"%s-instances" -> "group-%s";\n''' \
+ % (profile, profile)
+ if bundles:
+ bundles = []
+ [bundles.append(bund.get('name')) \
+ for bund in groups.findall('.//Bundle') \
+ if bund.get('name') not in bundles]
+
+ bundles.sort()
+ for bundle in bundles:
+ viz_str += '''\t"bundle-%s" [ label="%s", shape="septagon"];\n''' \
+ % (bundle, bundle)
+ gseen = []
+ for group in egroups:
+ if group.get('profile', 'false') == 'true':
+ style = "filled, bold"
+ else:
+ style = "filled"
+ gseen.append(group.get('name'))
+ viz_str += '\t"group-%s" [label="%s", style="%s", fillcolor=%s];\n' % \
+ (group.get('name'), group.get('name'), style, group.get('color'))
+ if bundles:
+ for bundle in group.findall('Bundle'):
+ viz_str += '\t"group-%s" -> "bundle-%s";\n' % \
+ (group.get('name'), bundle.get('name'))
+ gfmt = '\t"group-%s" [label="%s", style="filled", fillcolor="grey83"];\n'
+ for group in egroups:
+ for parent in group.findall('Group'):
+ if parent.get('name') not in gseen:
+ viz_str += gfmt % (parent.get('name'), parent.get('name'))
+ gseen.append(parent.get("name"))
+ viz_str += '\t"group-%s" -> "group-%s" ;\n' % \
+ (group.get('name'), parent.get('name'))
+ if key:
+ for category in categories:
+ viz_str += '''\t"''' + category + '''" [label="''' + category + \
+ '''", shape="record", style="filled", fillcolor=''' + \
+ categories[category] + '''];\n'''
+ return viz_str
def remove_client(self, client_name):
'''Remove client from bb.xml'''
diff --git a/src/lib/Server/Plugins/Metadata.py b/src/lib/Server/Plugins/Metadata.py
index d28d75530..813ca99eb 100644
--- a/src/lib/Server/Plugins/Metadata.py
+++ b/src/lib/Server/Plugins/Metadata.py
@@ -561,3 +561,67 @@ class Metadata(Bcfg2.Server.Plugin.MetadataPlugin,
'''Return a list of clients that are members of a given profile'''
return [client for client in self.clients \
if self.clients[client] == profile]
+
+ def viz(self, hosts, bundles, key, colors):
+ '''admin mode viz support'''
+ groups_tree = lxml.etree.parse(self.data + "/groups.xml")
+ groups = groups_tree.getroot()
+ categories = {'default':'grey83'}
+ instances = {}
+ viz_str = ""
+ egroups = groups.findall("Group") + groups.findall('.//Groups/Group')
+ for group in egroups:
+ if not categories.has_key(group.get('category')):
+ categories[group.get('category')] = colors.pop()
+ group.set('color', categories[group.get('category')])
+ if None in categories:
+ del categories[None]
+ if hosts:
+ clients = self.clients
+ for client, profile in clients.iteritems():
+ if instances.has_key(profile):
+ instances[profile].append(client)
+ else:
+ instances[profile] = [client]
+ for profile, clist in instances.iteritems():
+ clist.sort()
+ viz_str += '''\t"%s-instances" [ label="%s", shape="record" ];\n''' \
+ % (profile, '|'.join(clist))
+ viz_str += '''\t"%s-instances" -> "group-%s";\n''' \
+ % (profile, profile)
+ if bundles:
+ bundles = []
+ [bundles.append(bund.get('name')) \
+ for bund in groups.findall('.//Bundle') \
+ if bund.get('name') not in bundles]
+ bundles.sort()
+ for bundle in bundles:
+ viz_str += '''\t"bundle-%s" [ label="%s", shape="septagon"];\n''' \
+ % (bundle, bundle)
+ gseen = []
+ for group in egroups:
+ if group.get('profile', 'false') == 'true':
+ style = "filled, bold"
+ else:
+ style = "filled"
+ gseen.append(group.get('name'))
+ viz_str += '\t"group-%s" [label="%s", style="%s", fillcolor=%s];\n' % \
+ (group.get('name'), group.get('name'), style, group.get('color'))
+ if bundles:
+ for bundle in group.findall('Bundle'):
+ viz_str += '\t"group-%s" -> "bundle-%s";\n' % \
+ (group.get('name'), bundle.get('name'))
+ gfmt = '\t"group-%s" [label="%s", style="filled", fillcolor="grey83"];\n'
+ for group in egroups:
+ for parent in group.findall('Group'):
+ if parent.get('name') not in gseen:
+ viz_str += gfmt % (parent.get('name'), parent.get('name'))
+ gseen.append(parent.get("name"))
+ viz_str += '\t"group-%s" -> "group-%s" ;\n' % \
+ (group.get('name'), parent.get('name'))
+ if key:
+ for category in categories:
+ viz_str += '''\t"''' + category + '''" [label="''' + category + \
+ '''", shape="record", style="filled", fillcolor=''' + \
+ categories[category] + '''];\n'''
+ return viz_str