1
2
3
4
5
6
7
8
9
10
11
12
13
15 '''
16 This class is a wrapper for pydot functionality. It provides a means of
17 graphically representing nodes in a tree.
18 '''
20 if device:
21 raise NotImplemented
22 self.node = None
23 elif node:
24 self.node = node
25 self.parentName = parentName
26 self.format = 'png'
27
30 '''
31 This method processes the child nodes of the passed node, and then its
32 children. It returns a list of tuples where the tuples represent a
33 simple parent-child relationship.
34 '''
35 if not node:
36 node = self.node
37 if not parentName:
38 parentName = self.parentName
39 edges = []
40 if doNets and hasattr(node, 'nets'):
41 edges.extend([ (parentName, x.ip) for x in node.nets if x.ip != 'default'])
42 for childNode in node.children:
43 childName = '%s' % (childNode.pj.hostname)
44 if parentName:
45 edges.append((parentName, childName))
46 moreEdges = self.simpleProcessNodes(childNode, childName, doNets=doNets)
47 edges.extend(moreEdges)
48 return edges
49
51 '''
52 This method (will) processes nodes and builds the graphs node at a time
53 with actual pydot objects (as opposed to building a graph from a list
54 of edges). This allows for custom presentation changes based on node
55 attributes.
56 '''
57 raise NotImplemented
58
59
61 import os, os.path
62 from Utils import zenPath
63 config = zenPath('lib/graphviz/config')
64 if not os.path.exists(config) or os.path.getsize(config) == 0:
65 os.system(zenPath("bin/dot") + " -c")
66 import pydot
67 graph = pydot.graph_from_edges(edges, directed=directed)
68 graph.ranksep = '1.5'
69 graph.format = self.format
70 graph.bgcolor = '#EEEEEE'
71
72 graph.fillcolor = '#5A6F8F'
73 graph.fontcolor = '#FFFFFF'
74 graph.fontsize = '10.0'
75 graph.fontname = 'Helvetica'
76 graph.style = 'filled'
77 self.graph = graph
78
79 - def prepare(self, nodeProcessing='simple', edges=None):
88
89
90 - def write(self, fdOrPath, format='png'):
98
100 '''
101 This will render an image format suitable for display in a browser.
102 '''
103 self.withNetworks = withNetworks
104 self.prepare()
105 return self.graph.create(format=format)
106
107 '''
108 scp /tmp/graph_from_edges_dot.svg [email protected]:
109
110 * Give a device name
111 * Find device and get node
112 * input node
113 * output to given file or stdout
114 * turn on/off networks
115 * turn on/off devices
116 * look at nets[0].pingjobs -- should be the list of things to ping on that
117 * network
118
119 processNode should allow one to indicate whether or not networks, devices,
120 etc., should be displayed
121 '''
122