scripts/bcfg2/bcfg2-graph.py
2013-02-08 01:47:16 +01:00

51 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import xml.dom.minidom
tmp_file = '/tmp/graph.gv'
out = file(tmp_file,'w')
from sh import neato
from sh import date
groups = xml.dom.minidom.parse(file('/var/lib/bcfg2/Metadata/groups.xml','r')).documentElement
print("""digraph G {
edge [len=4.50, ratio=fill]
""", file=out)
def childGroups(parent):
return [ x for x in parent.childNodes if \
x.nodeType == x.ELEMENT_NODE and x.tagName == u'Group']
# Les clients
print("""
subgraph cluster_1 {
node [style=filled];
""", file=out)
for elem in childGroups(groups):
if elem.hasAttribute('profile'):
print('"%s";' % elem.getAttribute('name'), file=out)
print("""
label = "process #2";
color=blue
}
""", file=out)
# Le reste
for elem in childGroups(groups):
print('"%s" -> {%s};' % \
( elem.getAttribute('name'),
" ".join( [ '"%s"' % x.getAttribute('name')
for x in childGroups(elem) ]),
), file=out)
print("""
label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s";
}""" % str(date())[0:-1], file=out)
out.close()
neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/bcfg2/groups.svg")