summaryrefslogtreecommitdiffstats
path: root/overview.py
blob: 18703f7ba250fd9d7e4cd9e85f2fd264d6cd3ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/usr/bin/env python
# vim: set fileencoding=UTF-8:
# Copyright 2013 Red Hat, Inc.
# Author: Jan Pokorný <jpokorny at redhat dot com>
# Distributed under GPLv2+;  generated content under CC-BY-SA 3.0
# (to view a copy, visit http://creativecommons.org/licenses/by-sa/3.0/)
"""Model of cman-based cluster capturing deployment, communication, etc.

By default, output is a PDF file named as per this script modulo extension.
Generally, you can specify arbitrary format/extension supported by graphviz
as a first parameter and you'll get what you ask for, including original
'.dot' file for further utilization.

If you generate mere dot file (./overview.py dot), you can view it
conveniently using XDot: http://code.google.com/p/jrfonseca/wiki/XDot
"""
# TODO: integrate ^^^? http://code.google.com/p/jrfonseca/wiki/XDot#Embedding

from pydot import Dot, Edge, Node, Subgraph
from sys import argv
from os.path import extsep, splitext


FONT = 'Inconsolata'
FONTDEF = map(lambda switch: '-' + switch + 'fontname=' + FONT, "GNE")
OUTPUT = splitext(__file__)[0]


#
# Subgraph inheritance
#


class GraphNode(Subgraph):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('style', 'bold')
        super(GraphNode, self).__init__(*args, **kwargs)


class GraphSubnode(Subgraph):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('fillcolor', 'azure')
        kwargs.setdefault('style', 'filled')
        super(GraphSubnode, self).__init__(*args, **kwargs)


#
# Node inheritance
#


class Program(Node):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('shape', 'box')
        super(Program, self).__init__(*args, **kwargs)


class Agent(Program):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('fillcolor', 'lavenderblush')
        kwargs.setdefault('style', 'filled')
        super(Agent, self).__init__(*args, **kwargs)


class Executable(Program):
    pass


class Daemon(Executable):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('fillcolor', 'cornsilk')
        kwargs.setdefault('style', 'filled')
        super(Daemon, self).__init__(*args, **kwargs)


class Artefact(Node):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('shape', 'box3d')
        kwargs.setdefault('fillcolor', 'wheat')
        kwargs.setdefault('style', 'filled')
        super(Artefact, self).__init__(*args, **kwargs)


#
# Edge inheritance
#


class DBUS(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('style', 'dotted')
        super(DBUS, self).__init__(*args, **kwargs)


class OddjobExec(DBUS):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label', 'oddjob exec')
        super(OddjobExec, self).__init__(*args, **kwargs)


class HTTPS(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('style', 'bold')
        super(HTTPS, self).__init__(*args, **kwargs)


class LuciHTTPS(HTTPS):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label', 'port 8084')
        super(LuciHTTPS, self).__init__(*args, **kwargs)


class ApplicationSpecificProtocol(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('style', 'dashed')
        super(ApplicationSpecificProtocol, self).__init__(*args, **kwargs)


class RICCIRPC(ApplicationSpecificProtocol):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label', 'port 11111')
        super(RICCIRPC, self).__init__(*args, **kwargs)


class SNMP(ApplicationSpecificProtocol):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label', 'port 161')
        super(SNMP, self).__init__(*args, **kwargs)


class CIM(ApplicationSpecificProtocol):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label', 'port 898[89]')
        super(CIM, self).__init__(*args, **kwargs)


class Consume(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('color', 'darkgreen')
        kwargs.setdefault('fontcolor', 'darkgreen')
        super(Consume, self).__init__(*args, **kwargs)


class ConsumeReversed(Consume):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('dir', 'back')
        super(ConsumeReversed, self).__init__(*reversed(args), **kwargs)


class Produce(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('color', 'orangered')
        kwargs.setdefault('fontcolor', 'orangered')
        super(Produce, self).__init__(*args, **kwargs)


class Delegate(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('color', 'navy')
        kwargs.setdefault('fontcolor', 'navy')
        kwargs.setdefault('dir', 'both')
        super(Delegate, self).__init__(*args, **kwargs)


# peer-to-peer
class Exchange(Edge):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('color', 'saddlebrown')
        kwargs.setdefault('fontcolor', 'saddlebrown')
        kwargs.setdefault('dir', 'both')
        super(Exchange, self).__init__(*args, **kwargs)


# mixing

class DelegateOddjobExec(Delegate, OddjobExec):
    pass


class DelegateRICCIRPC(Delegate, RICCIRPC):
    pass


class DelegateLuciHTTPS(Delegate, LuciHTTPS):
    pass


class DelegateSNMP(Delegate, SNMP):
    pass


class DelegateCIM(Delegate, CIM):
    pass


#
# Here we go
#


# management client

node_mgmt = Subgraph('cluster-climgmt', label='management client')

node_mgmt.add_node(Program('luci'))
node_mgmt.add_node(Program('ccs'))


# other monitoring

node_mon = Subgraph('cluster-monitor', label='other monitoring')

node_mon.add_node(Program('snmpwalk'))
node_mon.add_node(Program('wbemcli'))


# node b - management

node_b_conga = GraphSubnode('cluster-node_b-conga', label='management')

node_b_conga.add_node(Agent('node_b-libClusterMonitorSnmp.so', label='libClusterMonitorSnmp.so'))
node_b_conga.add_node(Agent('node_b-libRedHatClusterProvider.so', label='libRedHatClusterProvider.so'))
node_b_conga.add_node(Artefact('node_b-clumond.sock', label='/var/run/clumond.sock'))
node_b_conga.add_node(Daemon('node_b-ricci', label='ricci'))
node_b_conga.add_node(Daemon('node_b-modclusterd', label='modclusterd'))
node_b_conga.add_node(Program('node_b-modcluster', label='modcluster'))

node_b_conga.add_edge(Consume('node_b-libClusterMonitorSnmp.so', 'node_b-clumond.sock'))
node_b_conga.add_edge(Consume('node_b-libRedHatClusterProvider.so', 'node_b-clumond.sock'))
node_b_conga.add_edge(Consume('node_b-modcluster', 'node_b-clumond.sock'))
node_b_conga.add_edge(Produce('node_b-modclusterd', 'node_b-clumond.sock'))


# node b - core

node_b_core = GraphSubnode('cluster-node_b-core', label='core')

node_b_core.add_node(Node('node_b-libccsconfdb', label='libccsconfdb'))
node_b_core.add_node(Daemon('node_b-rgmanager', label='rgmanager'))
node_b_core.add_node(Program('node_b-clustat', label='clustat'))
node_b_core.add_node(Artefact('node_b-rgmanager.sk', label='/var/run/cluster/rgmanager.sk'))

node_b_core.add_edge(Consume('node_b-clustat', 'node_b-rgmanager.sk'))
node_b_core.add_edge(Consume('node_b-rgmanager', 'node_b-libccsconfdb'))
node_b_core.add_edge(Produce('node_b-rgmanager', 'node_b-rgmanager.sk'))


# node b - general

node_b = GraphNode('cluster-node_b', label='NODE B')
node_b.add_subgraph(node_b_conga)
node_b.add_subgraph(node_b_core)

node_b.add_node(Artefact('node_b-cluster.conf', label='/etc/cluster/cluster.conf'))
node_b.add_node(Daemon('node_b-snmpd', label='snmpd'))
node_b.add_node(Daemon('node_b-cimserver', label='cimserver'))

node_b.add_edge(Consume('node_b-modcluster', 'node_b-cluster.conf', label='version?'))
node_b.add_edge(Consume('node_b-modclusterd', 'node_b-cluster.conf', label='version?'))
node_b.add_edge(Consume('node_b-libccsconfdb', 'node_b-cluster.conf', label='version?'))
node_b.add_edge(Consume('node_b-ricci', 'node_b-cluster.conf', label='clustername\nclusteralias'))
node_b.add_edge(Consume('node_b-snmpd', 'node_b-libClusterMonitorSnmp.so'))
node_b.add_edge(Consume('node_b-cimserver', 'node_b-libRedHatClusterProvider.so'))
node_b.add_edge(DelegateOddjobExec('node_b-ricci', 'node_b-modcluster'))


# node a - management

node_a_conga = GraphSubnode('cluster-node_a-conga', label='management (incomplete)')

node_a_conga.add_node(Daemon('node_a-ricci', label='ricci'))
node_a_conga.add_node(Daemon('node_a-modclusterd', label='modclusterd'))


# node a - general

node_a = GraphNode('cluster-node_a', label='NODE A')
node_a.add_subgraph(node_a_conga)


# node c - management

node_c_conga = GraphSubnode('cluster-node_c-conga', label='management (incomplete)')

node_c_conga.add_node(Daemon('node_c-ricci', label='ricci'))
node_c_conga.add_node(Daemon('node_c-modclusterd', label='modclusterd'))


# node c - general

node_c = GraphNode('cluster-node_c', label='NODE C')
node_c.add_subgraph(node_c_conga)


# nodes

nodes = Subgraph('cluster-nodes', style='invis')
nodes.add_subgraph(node_b)
nodes.add_subgraph(node_c)
nodes.add_subgraph(node_a)


# global environment

graph = Dot('Cluster.conf-related tools', graph_type='digraph', overlap='scalexy', compound='true', splines='yes')  # , ranksep='1.2'
graph.add_subgraph(node_mgmt)
graph.add_subgraph(node_mon)
#graph.add_subgraph(node_a)
#graph.add_subgraph(node_b)
graph.add_subgraph(nodes)

graph.add_node(Program('firefox'))

graph.add_edge(DelegateRICCIRPC('luci', 'node_a-ricci', ltail='cluster-climgmt', constraint='false'))
graph.add_edge(DelegateRICCIRPC('luci', 'node_b-ricci', ltail='cluster-climgmt'))
graph.add_edge(DelegateRICCIRPC('luci', 'node_c-ricci', ltail='cluster-climgmt', constraint='false'))
graph.add_edge(DelegateLuciHTTPS('firefox', 'luci'))

graph.add_edge(DelegateSNMP('snmpwalk', 'node_b-snmpd'))
graph.add_edge(DelegateCIM('wbemcli', 'node_b-cimserver'))

graph.add_edge(Exchange('node_a-modclusterd', 'node_b-modclusterd', label='port 16851 (either direction)', constraint='false'))
graph.add_edge(Exchange('node_a-modclusterd', 'node_c-modclusterd', label='port 16851 (either direction)', constraint='false'))
graph.add_edge(Exchange('node_b-modclusterd', 'node_c-modclusterd', label='port 16851 (either direction)', constraint='false'))


###


if __name__ == '__main__':
    ext = argv[1] if len(argv) > 1 else 'pdf'
    fmt = {'dot': 'raw'}.get(ext, ext)
    graph.write(OUTPUT + extsep + ext, format=fmt, prog=['dot'] + FONTDEF)