network_drawer 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54206d3c0db05645a83f274b6900a4166abcb162
4
- data.tar.gz: 249d6d136532330d9b7cd4f1fdd92d31a4e8fc73
3
+ metadata.gz: 55149d158ff78d750aafb07313075edf0d391d71
4
+ data.tar.gz: 8fbd393d42398a4720b42748dd60487c4e7c5134
5
5
  SHA512:
6
- metadata.gz: b9d48a3419d26a17037316c07730ba32042dacfe008e17e388ab3834470c30bbb5203b2f374d0d6f26f9c741339a8b70d527b72ac8fb9e86a714e67bccdf6c86
7
- data.tar.gz: a10a95559f0415afaadd4a979c34814513b81af29b26e79fc39ac438cad7a5f1ade9545ba49633568dbf453e85b584117ed57dc0d61337e1450d223c836888c0
6
+ metadata.gz: 64f3e725c69bc36abd67ee79a80621a2f6e5521fb368c2024d392f6482a6170f816ca6b4ec2c9a5d9c514ec6f3f01de2753f26e3aff13bb68d9ef98675ecc1c1
7
+ data.tar.gz: 2125777d7dc29d5524626fb7e74ab87b7315c06af793033a30e6b6fde052cfbbeeba669e73d96dbc0448857a22cc5c312e3394201dd0b97ef9a339e564f1d818
data/README.md CHANGED
@@ -70,67 +70,97 @@ You can describe diagram with JSON.
70
70
 
71
71
  You can describe diagram as follows:
72
72
 
73
-
74
- ```json
75
- {
76
- "layers": {
77
- "Web": {
78
- "nodes": [
79
- {
80
- "WebLB": {
81
- "ports": ["80/tcp", "443/tcp"],
82
- "type": "LB",
83
- "url": "https://github.com/otahi/network_drawer/"
84
- }
85
- },
86
- { "Web001": { "ports": ["80/tcp"] } },
87
- { "Web002": { "ports": ["80/tcp"] } }
88
- ]
89
- },
90
- "App": {
91
- "nodes": [
92
- { "AppLB": { "ports": ["80/tcp", "25/tcp"], "type": "LB" } },
93
- { "App001": { "ports": ["80/tcp", "25/tcp"] } },
94
- { "App002": { "ports": ["80/tcp", "25/tcp"] } }
95
- ]
96
- }
97
- },
98
- "nodes": [
99
- { "Browser": {}, "type": "Client" },
100
- { "Mail Server": {}, "type": "Client" }
101
- ],
102
- "connections": [
103
- { "from": "Browser", "to": "WebLB:80/tcp", "type": "HTTP" },
104
- { "from": "Browser", "to": "WebLB:443/tcp" },
105
- { "from": "Mail Server", "to": "AppLB:25/tcp" , "type": "SMTP" },
106
- { "from": "WebLB", "to": "Web001:80/tcp", "type": "HTTP" },
107
- { "from": "WebLB", "to": "Web002:80/tcp", "type": "HTTP" },
108
- { "from": "Web001", "to": "AppLB:80/tcp", "type": "HTTP" },
109
- { "from": "Web002", "to": "AppLB:80/tcp", "type": "HTTP" },
110
- { "from": "AppLB", "to": "App001:25/tcp", "type": "SMTP" },
111
- { "from": "AppLB", "to": "App001:80/tcp", "type": "HTTP" },
112
- { "from": "AppLB", "to": "App002:25/tcp", "type": "SMTP" },
113
- { "from": "AppLB", "to": "App002:80/tcp", "type": "HTTP" }
114
- ]
115
- }
116
-
73
+ [simple.yml](examples/simple.yml)
74
+ ```yaml
75
+ layers:
76
+ - Web:
77
+ nodes:
78
+ - WebLB:
79
+ ports:
80
+ - 80/tcp
81
+ - 443/tcp
82
+ type: LB
83
+ url: https://github.com/otahi/network_drawer/
84
+ - Web001:
85
+ ports:
86
+ - 80/tcp
87
+ - Web002:
88
+ ports:
89
+ - 80/tcp
90
+ - App:
91
+ nodes:
92
+ - AppLB:
93
+ ports:
94
+ - 80/tcp
95
+ - 25/tcp
96
+ type: LB
97
+ - App001:
98
+ ports:
99
+ - 80/tcp
100
+ - 25/tcp
101
+ - App002:
102
+ ports:
103
+ - 80/tcp
104
+ - 25/tcp
105
+ nodes:
106
+ - Browser:
107
+ type: Client
108
+ - Mail Server:
109
+ type: Client
110
+ connections:
111
+ - from: Browser
112
+ to: WebLB:80/tcp
113
+ type: HTTP
114
+ - from: Browser
115
+ to: WebLB:443/tcp
116
+ - from: Mail Server
117
+ to: AppLB:25/tcp
118
+ type: SMTP
119
+ - from: WebLB
120
+ to: Web001:80/tcp
121
+ type: HTTP
122
+ - from: WebLB
123
+ to: Web002:80/tcp
124
+ type: HTTP
125
+ - from: Web001
126
+ to: AppLB:80/tcp
127
+ type: HTTP
128
+ - from: Web002
129
+ to: AppLB:80/tcp
130
+ type: HTTP
131
+ - from: AppLB
132
+ to: App001:25/tcp
133
+ type: SMTP
134
+ - from: AppLB
135
+ to: App001:80/tcp
136
+ type: HTTP
137
+ - from: AppLB
138
+ to: App002:25/tcp
139
+ type: SMTP
140
+ - from: AppLB
141
+ to: App002:80/tcp
142
+ type: HTTP
117
143
  ```
118
144
 
119
145
  ### Style
120
146
 
121
147
  You can specify your style for nodes or edges with [Graphviz attributes](http://www.graphviz.org/content/attrs).
122
148
 
123
- ```json
124
- {
125
- "types": {
126
- "LB": { "style": "rounded,filled,dotted", "fillcolor": "azure" },
127
- "HTTP": { "color": "blue" },
128
- "SMTP": { "color": "green" }
129
- }
130
- }
149
+ [simple_style.yml](examples/simple_style.yml)
150
+ ```yaml
151
+ types:
152
+ WEB:
153
+ style: rounded,filled,dotted
154
+ fillcolor: azure
155
+ LB:
156
+ style: rounded,filled,dotted
157
+ fillcolor: azure
158
+ HTTP:
159
+ color: blue
160
+ SMTP:
161
+ color: green
131
162
  ```
132
163
 
133
-
134
164
  ## Contributing
135
165
 
136
166
  1. Fork it ( https://github.com/otahi/network_drawer/fork )
data/Rakefile CHANGED
@@ -10,8 +10,8 @@ task :update do
10
10
 
11
11
  %w(png svg).each do |f|
12
12
  command = 'bundle exec bin/network_drawer '
13
- command << 'draw examples/simple.json '
14
- command << "-s examples/simple_style.json -f #{f}"
13
+ command << 'draw examples/simple.yml '
14
+ command << "-s examples/simple_style.yml -f #{f}"
15
15
 
16
16
  system(env, command)
17
17
  end
data/examples/simple.json CHANGED
@@ -12,24 +12,6 @@
12
12
  },
13
13
  { "Web001": { "ports": ["80/tcp"] } },
14
14
  { "Web002": { "ports": ["80/tcp"] } }
15
- ],
16
- "layers": [
17
- {
18
- "Image": {
19
- "nodes": [
20
- {
21
- "ImageWeb001": {
22
- "ports": ["80/tcp"]
23
- }
24
- },
25
- {
26
- "ImageWeb002": {
27
- "ports": ["80/tcp"]
28
- }
29
- }
30
- ]
31
- }
32
- }
33
15
  ]
34
16
  }
35
17
  },
data/examples/simple.png CHANGED
Binary file
data/examples/simple.svg CHANGED
@@ -4,61 +4,35 @@
4
4
  <!-- Generated by graphviz version 2.34.0 (20140129.0153)
5
5
  -->
6
6
  <!-- Title: simple Pages: 1 -->
7
- <svg width="533pt" height="492pt"
8
- viewBox="0.00 0.00 533.00 492.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
- <g id="0" class="graph" transform="scale(1 1) rotate(0) translate(4 488)">
7
+ <svg width="336pt" height="460pt"
8
+ viewBox="0.00 0.00 336.00 460.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="0" class="graph" transform="scale(1 1) rotate(0) translate(4 456)">
10
10
  <title>simple</title>
11
- <polygon fill="white" stroke="white" points="-4,4 -4,-488 529,-488 529,4 -4,4"/>
11
+ <polygon fill="white" stroke="white" points="-4,4 -4,-456 332,-456 332,4 -4,4"/>
12
12
  <g id="1" class="cluster"><title>cluster_Web</title>
13
- <polygon fill="none" stroke="black" points="104,-212 104,-440 517,-440 517,-212 104,-212"/>
14
- <text text-anchor="middle" x="310.5" y="-422" font-family="Helvetica,sans-Serif" font-size="14.00">Web</text>
13
+ <polygon fill="none" stroke="black" points="105,-212 105,-408 295,-408 295,-212 105,-212"/>
14
+ <text text-anchor="middle" x="200" y="-390" font-family="Helvetica,sans-Serif" font-size="14.00">Web</text>
15
15
  </g>
16
- <g id="2" class="cluster"><title>cluster_Image</title>
17
- <polygon fill="none" stroke="black" points="240,-308 240,-408 509,-408 509,-308 240,-308"/>
18
- <text text-anchor="middle" x="374.5" y="-390" font-family="Helvetica,sans-Serif" font-size="14.00">Image</text>
19
- </g>
20
- <g id="3" class="cluster"><title>cluster_App</title>
21
- <polygon fill="none" stroke="black" points="46,-8 46,-204 303,-204 303,-8 46,-8"/>
22
- <text text-anchor="middle" x="174.5" y="-186" font-family="Helvetica,sans-Serif" font-size="14.00">App</text>
16
+ <g id="2" class="cluster"><title>cluster_App</title>
17
+ <polygon fill="none" stroke="black" points="63,-8 63,-204 320,-204 320,-8 63,-8"/>
18
+ <text text-anchor="middle" x="191.5" y="-186" font-family="Helvetica,sans-Serif" font-size="14.00">App</text>
23
19
  </g>
24
20
  <!-- 0 -->
25
21
  <g id="0" class="node"><title>0</title>
26
- <g id="a_0"><a xlink:title="ImageWeb001">
27
- <polygon fill="none" stroke="black" points="500.25,-375.5 383.75,-375.5 383.75,-316.5 500.25,-316.5 500.25,-375.5"/>
28
- <polygon fill="none" stroke="black" points="394,-346 394,-369 491,-369 491,-346 394,-346"/>
29
- <text text-anchor="start" x="423.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
30
- <polygon fill="none" stroke="black" points="394,-322 394,-344 491,-344 491,-322 394,-322"/>
31
- <text text-anchor="start" x="397.096" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">ImageWeb001</text>
22
+ <g id="a_0"><a xlink:href="https://github.com/otahi/network_drawer/" xlink:title="WebLB">
23
+ <path fill="azure" stroke="black" stroke-dasharray="1,5" d="M247,-375.5C247,-375.5 153,-375.5 153,-375.5 147,-375.5 141,-369.5 141,-363.5 141,-363.5 141,-328.5 141,-328.5 141,-322.5 147,-316.5 153,-316.5 153,-316.5 247,-316.5 247,-316.5 253,-316.5 259,-322.5 259,-328.5 259,-328.5 259,-363.5 259,-363.5 259,-369.5 253,-375.5 247,-375.5"/>
24
+ <polygon fill="none" stroke="black" points="151,-346 151,-369 196,-369 196,-346 151,-346"/>
25
+ <text text-anchor="start" x="154.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
26
+ <polygon fill="none" stroke="black" points="198,-346 198,-369 249,-369 249,-346 198,-346"/>
27
+ <text text-anchor="start" x="200.538" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">443/tcp</text>
28
+ <polygon fill="none" stroke="black" points="151,-322 151,-344 249,-344 249,-322 151,-322"/>
29
+ <text text-anchor="start" x="177.168" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">WebLB</text>
32
30
  </a>
33
31
  </g>
34
32
  </g>
35
33
  <!-- 1 -->
36
34
  <g id="1" class="node"><title>1</title>
37
- <g id="a_1"><a xlink:title="ImageWeb002">
38
- <polygon fill="none" stroke="black" points="365.25,-375.5 248.75,-375.5 248.75,-316.5 365.25,-316.5 365.25,-375.5"/>
39
- <polygon fill="none" stroke="black" points="259,-346 259,-369 356,-369 356,-346 259,-346"/>
40
- <text text-anchor="start" x="288.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
41
- <polygon fill="none" stroke="black" points="259,-322 259,-344 356,-344 356,-322 259,-322"/>
42
- <text text-anchor="start" x="262.096" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">ImageWeb002</text>
43
- </a>
44
- </g>
45
- </g>
46
- <!-- 2 -->
47
- <g id="2" class="node"><title>2</title>
48
- <g id="a_2"><a xlink:href="https://github.com/otahi/network_drawer/" xlink:title="WebLB">
49
- <path fill="azure" stroke="black" stroke-dasharray="1,5" d="M218,-375.5C218,-375.5 124,-375.5 124,-375.5 118,-375.5 112,-369.5 112,-363.5 112,-363.5 112,-328.5 112,-328.5 112,-322.5 118,-316.5 124,-316.5 124,-316.5 218,-316.5 218,-316.5 224,-316.5 230,-322.5 230,-328.5 230,-328.5 230,-363.5 230,-363.5 230,-369.5 224,-375.5 218,-375.5"/>
50
- <polygon fill="none" stroke="black" points="122,-346 122,-369 167,-369 167,-346 122,-346"/>
51
- <text text-anchor="start" x="125.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
52
- <polygon fill="none" stroke="black" points="169,-346 169,-369 220,-369 220,-346 169,-346"/>
53
- <text text-anchor="start" x="171.538" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">443/tcp</text>
54
- <polygon fill="none" stroke="black" points="122,-322 122,-344 220,-344 220,-322 122,-322"/>
55
- <text text-anchor="start" x="148.168" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">WebLB</text>
56
- </a>
57
- </g>
58
- </g>
59
- <!-- 3 -->
60
- <g id="3" class="node"><title>3</title>
61
- <g id="a_3"><a xlink:title="Web001">
35
+ <g id="a_1"><a xlink:title="Web001">
62
36
  <polygon fill="none" stroke="black" points="191,-279.5 113,-279.5 113,-220.5 191,-220.5 191,-279.5"/>
63
37
  <polygon fill="none" stroke="black" points="123,-250 123,-273 181,-273 181,-250 123,-250"/>
64
38
  <text text-anchor="start" x="132.931" y="-255.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
@@ -67,14 +41,14 @@
67
41
  </a>
68
42
  </g>
69
43
  </g>
70
- <!-- 2&#45;&gt;3 -->
71
- <g id="3" class="edge"><title>2&#45;&gt;3:p80tcp</title>
72
- <path fill="none" stroke="blue" d="M159.728,-316.444C156.596,-306.662 153.73,-295.356 152.558,-284.18"/>
73
- <polygon fill="blue" stroke="blue" points="156.042,-283.793 152,-274 149.053,-284.177 156.042,-283.793"/>
44
+ <!-- 0&#45;&gt;1 -->
45
+ <g id="3" class="edge"><title>0&#45;&gt;1:p80tcp</title>
46
+ <path fill="none" stroke="blue" d="M199.141,-316.436C198.045,-299.18 195.572,-278.608 190.026,-268.401"/>
47
+ <polygon fill="blue" stroke="blue" points="192,-265.499 182,-262 187.636,-270.972 192,-265.499"/>
74
48
  </g>
75
- <!-- 4 -->
76
- <g id="4" class="node"><title>4</title>
77
- <g id="a_4"><a xlink:title="Web002">
49
+ <!-- 2 -->
50
+ <g id="2" class="node"><title>2</title>
51
+ <g id="a_2"><a xlink:title="Web002">
78
52
  <polygon fill="none" stroke="black" points="287,-279.5 209,-279.5 209,-220.5 287,-220.5 287,-279.5"/>
79
53
  <polygon fill="none" stroke="black" points="219,-250 219,-273 277,-273 277,-250 219,-250"/>
80
54
  <text text-anchor="start" x="228.931" y="-255.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
@@ -83,14 +57,14 @@
83
57
  </a>
84
58
  </g>
85
59
  </g>
86
- <!-- 2&#45;&gt;4 -->
87
- <g id="4" class="edge"><title>2&#45;&gt;4:p80tcp</title>
88
- <path fill="none" stroke="blue" d="M184.178,-316.436C192.374,-299.367 202.768,-279.054 210.398,-268.737"/>
89
- <polygon fill="blue" stroke="blue" points="212.837,-271.252 218,-262 208.195,-266.013 212.837,-271.252"/>
60
+ <!-- 0&#45;&gt;2 -->
61
+ <g id="4" class="edge"><title>0&#45;&gt;2:p80tcp</title>
62
+ <path fill="none" stroke="blue" d="M200.859,-316.436C201.955,-299.18 204.428,-278.608 209.974,-268.401"/>
63
+ <polygon fill="blue" stroke="blue" points="212.364,-270.972 218,-262 208,-265.499 212.364,-270.972"/>
90
64
  </g>
91
- <!-- 5 -->
92
- <g id="5" class="node"><title>5</title>
93
- <g id="a_5"><a xlink:title="AppLB">
65
+ <!-- 3 -->
66
+ <g id="3" class="node"><title>3</title>
67
+ <g id="a_3"><a xlink:title="AppLB">
94
68
  <path fill="azure" stroke="black" stroke-dasharray="1,5" d="M218.25,-171.5C218.25,-171.5 131.75,-171.5 131.75,-171.5 125.75,-171.5 119.75,-165.5 119.75,-159.5 119.75,-159.5 119.75,-124.5 119.75,-124.5 119.75,-118.5 125.75,-112.5 131.75,-112.5 131.75,-112.5 218.25,-112.5 218.25,-112.5 224.25,-112.5 230.25,-118.5 230.25,-124.5 230.25,-124.5 230.25,-159.5 230.25,-159.5 230.25,-165.5 224.25,-171.5 218.25,-171.5"/>
95
69
  <polygon fill="none" stroke="black" points="130,-142 130,-165 175,-165 175,-142 130,-142"/>
96
70
  <text text-anchor="start" x="133.431" y="-147.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
@@ -101,92 +75,92 @@
101
75
  </a>
102
76
  </g>
103
77
  </g>
104
- <!-- 3&#45;&gt;5 -->
105
- <g id="5" class="edge"><title>3&#45;&gt;5:p80tcp</title>
78
+ <!-- 1&#45;&gt;3 -->
79
+ <g id="5" class="edge"><title>1&#45;&gt;3:p80tcp</title>
106
80
  <path fill="none" stroke="blue" d="M152,-220.191C152,-207.217 152,-191.442 152,-176.321"/>
107
81
  <polygon fill="blue" stroke="blue" points="155.5,-176 152,-166 148.5,-176 155.5,-176"/>
108
82
  </g>
109
- <!-- 4&#45;&gt;5 -->
110
- <g id="6" class="edge"><title>4&#45;&gt;5:p80tcp</title>
83
+ <!-- 2&#45;&gt;3 -->
84
+ <g id="6" class="edge"><title>2&#45;&gt;3:p80tcp</title>
111
85
  <path fill="none" stroke="blue" d="M212.526,-220.441C192.443,-204.036 169.215,-184.601 158.292,-173.792"/>
112
86
  <polygon fill="blue" stroke="blue" points="161.006,-171.581 152,-166 155.559,-175.979 161.006,-171.581"/>
113
87
  </g>
114
- <!-- 6 -->
115
- <g id="6" class="node"><title>6</title>
116
- <g id="a_6"><a xlink:title="App001">
117
- <polygon fill="none" stroke="black" points="165.25,-75.5 54.75,-75.5 54.75,-16.5 165.25,-16.5 165.25,-75.5"/>
118
- <polygon fill="none" stroke="black" points="65,-46 65,-69 110,-69 110,-46 65,-46"/>
119
- <text text-anchor="start" x="68.4312" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
120
- <polygon fill="none" stroke="black" points="112,-46 112,-69 156,-69 156,-46 112,-46"/>
121
- <text text-anchor="start" x="114.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
122
- <polygon fill="none" stroke="black" points="65,-22 65,-44 156,-44 156,-22 65,-22"/>
123
- <text text-anchor="start" x="86.3657" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App001</text>
88
+ <!-- 4 -->
89
+ <g id="4" class="node"><title>4</title>
90
+ <g id="a_4"><a xlink:title="App001">
91
+ <polygon fill="none" stroke="black" points="182.25,-75.5 71.75,-75.5 71.75,-16.5 182.25,-16.5 182.25,-75.5"/>
92
+ <polygon fill="none" stroke="black" points="82,-46 82,-69 127,-69 127,-46 82,-46"/>
93
+ <text text-anchor="start" x="85.4312" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
94
+ <polygon fill="none" stroke="black" points="129,-46 129,-69 173,-69 173,-46 129,-46"/>
95
+ <text text-anchor="start" x="131.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
96
+ <polygon fill="none" stroke="black" points="82,-22 82,-44 173,-44 173,-22 82,-22"/>
97
+ <text text-anchor="start" x="103.366" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App001</text>
124
98
  </a>
125
99
  </g>
126
100
  </g>
127
- <!-- 5&#45;&gt;6 -->
128
- <g id="7" class="edge"><title>5&#45;&gt;6:p25tcp</title>
129
- <path fill="none" stroke="green" d="M149.5,-112.32C143.052,-102.894 137.306,-91.8436 135.033,-80.2736"/>
130
- <polygon fill="green" stroke="green" points="138.483,-79.5995 134,-70 131.518,-80.3001 138.483,-79.5995"/>
101
+ <!-- 3&#45;&gt;4 -->
102
+ <g id="7" class="edge"><title>3&#45;&gt;4:p25tcp</title>
103
+ <path fill="none" stroke="green" d="M160.623,-112.37C156.71,-102.677 153.148,-91.4558 151.693,-80.2467"/>
104
+ <polygon fill="green" stroke="green" points="155.167,-79.7409 151,-70 148.183,-80.2135 155.167,-79.7409"/>
131
105
  </g>
132
- <!-- 5&#45;&gt;6 -->
133
- <g id="8" class="edge"><title>5&#45;&gt;6:p80tcp</title>
134
- <path fill="none" stroke="blue" d="M119.268,-117.548C104.806,-108.2 92.1675,-95.862 88.2503,-80.1911"/>
135
- <polygon fill="blue" stroke="blue" points="91.6918,-79.4993 87,-70 84.7439,-80.3518 91.6918,-79.4993"/>
106
+ <!-- 3&#45;&gt;4 -->
107
+ <g id="8" class="edge"><title>3&#45;&gt;4:p80tcp</title>
108
+ <path fill="none" stroke="blue" d="M126.856,-112.424C116.765,-103.478 108.243,-92.5876 105.197,-79.976"/>
109
+ <polygon fill="blue" stroke="blue" points="108.667,-79.5118 104,-70 101.716,-80.3458 108.667,-79.5118"/>
136
110
  </g>
137
- <!-- 7 -->
138
- <g id="7" class="node"><title>7</title>
139
- <g id="a_7"><a xlink:title="App002">
140
- <polygon fill="none" stroke="black" points="294.25,-75.5 183.75,-75.5 183.75,-16.5 294.25,-16.5 294.25,-75.5"/>
141
- <polygon fill="none" stroke="black" points="194,-46 194,-69 239,-69 239,-46 194,-46"/>
142
- <text text-anchor="start" x="197.431" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
143
- <polygon fill="none" stroke="black" points="241,-46 241,-69 285,-69 285,-46 241,-46"/>
144
- <text text-anchor="start" x="243.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
145
- <polygon fill="none" stroke="black" points="194,-22 194,-44 285,-44 285,-22 194,-22"/>
146
- <text text-anchor="start" x="215.366" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App002</text>
111
+ <!-- 5 -->
112
+ <g id="5" class="node"><title>5</title>
113
+ <g id="a_5"><a xlink:title="App002">
114
+ <polygon fill="none" stroke="black" points="311.25,-75.5 200.75,-75.5 200.75,-16.5 311.25,-16.5 311.25,-75.5"/>
115
+ <polygon fill="none" stroke="black" points="211,-46 211,-69 256,-69 256,-46 211,-46"/>
116
+ <text text-anchor="start" x="214.431" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
117
+ <polygon fill="none" stroke="black" points="258,-46 258,-69 302,-69 302,-46 258,-46"/>
118
+ <text text-anchor="start" x="260.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
119
+ <polygon fill="none" stroke="black" points="211,-22 211,-44 302,-44 302,-22 211,-22"/>
120
+ <text text-anchor="start" x="232.366" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App002</text>
147
121
  </a>
148
122
  </g>
149
123
  </g>
150
- <!-- 5&#45;&gt;7 -->
151
- <g id="9" class="edge"><title>5&#45;&gt;7:p25tcp</title>
152
- <path fill="none" stroke="green" d="M230.732,-117.548C245.194,-108.2 257.833,-95.862 261.75,-80.1911"/>
153
- <polygon fill="green" stroke="green" points="265.256,-80.3518 263,-70 258.308,-79.4993 265.256,-80.3518"/>
124
+ <!-- 3&#45;&gt;5 -->
125
+ <g id="9" class="edge"><title>3&#45;&gt;5:p25tcp</title>
126
+ <path fill="none" stroke="green" d="M230.267,-125.47C252.302,-116.05 273.686,-101.572 278.832,-80.0328"/>
127
+ <polygon fill="green" stroke="green" points="282.32,-80.3376 280,-70 275.367,-79.5283 282.32,-80.3376"/>
154
128
  </g>
155
- <!-- 5&#45;&gt;7 -->
156
- <g id="10" class="edge"><title>5&#45;&gt;7:p80tcp</title>
157
- <path fill="none" stroke="blue" d="M200.5,-112.32C206.948,-102.894 212.694,-91.8436 214.967,-80.2736"/>
158
- <polygon fill="blue" stroke="blue" points="218.482,-80.3001 216,-70 211.517,-79.5995 218.482,-80.3001"/>
129
+ <!-- 3&#45;&gt;5 -->
130
+ <g id="10" class="edge"><title>3&#45;&gt;5:p80tcp</title>
131
+ <path fill="none" stroke="blue" d="M181.385,-112.436C186.051,-94.4294 192.996,-72.8124 201.291,-63.1294"/>
132
+ <polygon fill="blue" stroke="blue" points="203.16,-66.0907 210,-58 199.607,-60.059 203.16,-66.0907"/>
159
133
  </g>
160
- <!-- 8 -->
161
- <g id="8" class="node"><title>8</title>
162
- <g id="a_8"><a xlink:title="Browser">
163
- <polygon fill="none" stroke="black" points="208,-484 132,-484 132,-448 208,-448 208,-484"/>
164
- <text text-anchor="start" x="144.328" y="-459.9" font-family="Helvetica,sans-Serif" font-size="14.00">Browser</text>
134
+ <!-- 6 -->
135
+ <g id="6" class="node"><title>6</title>
136
+ <g id="a_6"><a xlink:title="Browser">
137
+ <polygon fill="none" stroke="black" points="237,-452 161,-452 161,-416 237,-416 237,-452"/>
138
+ <text text-anchor="start" x="173.328" y="-427.9" font-family="Helvetica,sans-Serif" font-size="14.00">Browser</text>
165
139
  </a>
166
140
  </g>
167
141
  </g>
168
- <!-- 8&#45;&gt;2 -->
169
- <g id="0" class="edge"><title>8&#45;&gt;2:p80tcp</title>
170
- <path fill="none" stroke="blue" d="M162.34,-447.876C155.599,-431.413 146.54,-405.394 144.445,-380.295"/>
171
- <polygon fill="blue" stroke="blue" points="147.929,-379.839 144,-370 140.935,-380.142 147.929,-379.839"/>
142
+ <!-- 6&#45;&gt;0 -->
143
+ <g id="0" class="edge"><title>6&#45;&gt;0:p80tcp</title>
144
+ <path fill="none" stroke="blue" d="M187.672,-415.857C182.088,-406.095 176.087,-393.216 173.879,-380.063"/>
145
+ <polygon fill="blue" stroke="blue" points="177.357,-379.657 173,-370 170.384,-380.267 177.357,-379.657"/>
172
146
  </g>
173
- <!-- 8&#45;&gt;2 -->
174
- <g id="1" class="edge"><title>8&#45;&gt;2:p443tcp</title>
175
- <path fill="none" stroke="black" d="M177.366,-447.848C183.847,-431.362 192.557,-405.325 194.572,-380.272"/>
176
- <polygon fill="black" stroke="black" points="198.081,-380.137 195,-370 191.087,-379.846 198.081,-380.137"/>
147
+ <!-- 6&#45;&gt;0 -->
148
+ <g id="1" class="edge"><title>6&#45;&gt;0:p443tcp</title>
149
+ <path fill="none" stroke="black" d="M209.893,-415.8C215.261,-406.018 221.032,-393.129 223.155,-380.02"/>
150
+ <polygon fill="black" stroke="black" points="226.647,-380.259 224,-370 219.672,-379.67 226.647,-380.259"/>
177
151
  </g>
178
- <!-- 9 -->
179
- <g id="9" class="node"><title>9</title>
180
- <g id="a_9"><a xlink:title="Mail Server">
152
+ <!-- 7 -->
153
+ <g id="7" class="node"><title>7</title>
154
+ <g id="a_7"><a xlink:title="Mail Server">
181
155
  <polygon fill="none" stroke="black" points="94.25,-268 -0.25,-268 -0.25,-232 94.25,-232 94.25,-268"/>
182
156
  <text text-anchor="start" x="12.1035" y="-243.9" font-family="Helvetica,sans-Serif" font-size="14.00">Mail Server</text>
183
157
  </a>
184
158
  </g>
185
159
  </g>
186
- <!-- 9&#45;&gt;5 -->
187
- <g id="2" class="edge"><title>9&#45;&gt;5:p25tcp</title>
188
- <path fill="none" stroke="green" d="M69.6461,-231.889C78.8316,-225.297 89.6903,-217.933 100,-212 138.766,-189.69 190.193,-210.654 197.991,-176.054"/>
189
- <polygon fill="green" stroke="green" points="201.484,-176.299 199,-166 194.519,-175.601 201.484,-176.299"/>
160
+ <!-- 7&#45;&gt;3 -->
161
+ <g id="2" class="edge"><title>7&#45;&gt;3:p25tcp</title>
162
+ <path fill="none" stroke="green" d="M70.1237,-231.94C79.4894,-225.355 90.5446,-217.983 101,-212 139.498,-189.969 190.301,-210.355 198.004,-175.979"/>
163
+ <polygon fill="green" stroke="green" points="201.489,-176.298 199,-166 194.524,-175.603 201.489,-176.298"/>
190
164
  </g>
191
165
  </g>
192
166
  </svg>
data/examples/simple.yml CHANGED
@@ -13,15 +13,6 @@ layers:
13
13
  - Web002:
14
14
  ports:
15
15
  - 80/tcp
16
- layers:
17
- - Image:
18
- nodes:
19
- - ImageWeb001:
20
- ports:
21
- - 80/tcp
22
- - ImageWeb002:
23
- ports:
24
- - 80/tcp
25
16
  - App:
26
17
  nodes:
27
18
  - AppLB:
@@ -0,0 +1,11 @@
1
+ types:
2
+ WEB:
3
+ style: rounded,filled,dotted
4
+ fillcolor: azure
5
+ LB:
6
+ style: rounded,filled,dotted
7
+ fillcolor: azure
8
+ HTTP:
9
+ color: blue
10
+ SMTP:
11
+ color: green
@@ -5,6 +5,7 @@ module NetworkDrawer
5
5
  class Diagram
6
6
  TOP_LAYER = :networkdrawertop
7
7
  DEFAULT_OPTIONS = {}
8
+ ELELMENT_KEYS = [:layers, :nodes, :connections]
8
9
 
9
10
  def self.draw(source, dest_file, options = {})
10
11
  diagram = new(source, dest_file, options)
@@ -12,7 +13,7 @@ module NetworkDrawer
12
13
  end
13
14
 
14
15
  def initialize(source, dest_file, options = {})
15
- @source = source
16
+ @source = source ? source : {}
16
17
  @dest_file = dest_file
17
18
  @options = DEFAULT_OPTIONS.merge(options)
18
19
  @title = @options[:title] ? @options[:title] :
@@ -30,6 +31,7 @@ module NetworkDrawer
30
31
  draw_elements
31
32
 
32
33
  @gv.global(layout: @options[:layout] ? @options[:layout] : :dot)
34
+ @gv.global(@source.dup.delete_if { |k, _| ELELMENT_KEYS.include?(k) })
33
35
  @gv.save @dest_file, @options[:format]
34
36
  end
35
37
 
@@ -72,7 +74,7 @@ module NetworkDrawer
72
74
  return nil unless n.is_a?(Hash)
73
75
  node = Element::Node.new(n.values.first, @style[:types])
74
76
  node.name = n.keys.first
75
- @nodes[node.name] = node.id
77
+ @nodes[node.name] = { id: node.id }
76
78
  nodes << node
77
79
  end
78
80
  nodes
@@ -92,8 +94,11 @@ module NetworkDrawer
92
94
  connection = Element::Connection.new({}, @style[:types])
93
95
  c.each_pair { |k, v| connection[k.to_sym] = v }
94
96
 
95
- from = from_port ? "#{@nodes[from_name]}:p#{from_port}" : @nodes[from_name]
96
- to = to_port ? "#{@nodes[to_name]}:p#{to_port}" : @nodes[to_name]
97
+ from_name = @nodes[from_name][:id] if @nodes[from_name]
98
+ to_name = @nodes[to_name][:id] if @nodes[to_name]
99
+
100
+ from = from_port ? "#{from_name}:p#{from_port}" : from_name
101
+ to = to_port ? "#{to_name}:p#{to_port}" : to_name
97
102
 
98
103
  connection.from = from
99
104
  connection.to = to
@@ -104,7 +109,7 @@ module NetworkDrawer
104
109
 
105
110
  def node_exist?(name)
106
111
  return false unless name
107
- if @nodes[name]
112
+ if @nodes[name] && @nodes[name][:id]
108
113
  true
109
114
  else
110
115
  puts "No #{name} exists"
@@ -114,7 +119,7 @@ module NetworkDrawer
114
119
 
115
120
  def node_id(name)
116
121
  return nil unless node_exist?(name)
117
- @nodes[name.to_sym]
122
+ @nodes[name.to_sym][:id]
118
123
  end
119
124
  end
120
125
  end
@@ -22,17 +22,77 @@ module NetworkDrawer
22
22
  private
23
23
 
24
24
  def build_label
25
- if self.ports && self.ports.size > 0
26
- label = "<tr border='1'>"
27
- self.ports.each_with_index do |p, j|
25
+ label = ''
26
+
27
+ label << port_label
28
+ if [num_ports, num_modules].max > 0
29
+ label << "<tr border='1'><td border='1'"
30
+ label << " colspan=\"#{num_columns}\">#{self.name}</td></tr>"
31
+ else
32
+ label << "<tr border='0'><td border='0'>#{self.name}</td></tr>"
33
+ end
34
+ label << module_label
35
+
36
+ "<table border='0'>#{label}</table>"
37
+ end
38
+
39
+ def port_label
40
+ label = ''
41
+ if num_ports > 0
42
+ label << "<tr border='1'>"
43
+ self.ports.each_with_index do |p, i|
28
44
  label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
45
+ label << row_separator(i, num_ports)
29
46
  end
30
47
  label << '</tr>'
31
- label << "<tr border='1'><td border='1' colspan=\"#{self.ports.size}\">#{self.name}</td></tr>"
48
+ end
49
+ label
50
+ end
51
+
52
+ def module_label
53
+ label = ''
54
+ if num_modules > 0
55
+ label << "<tr border='1'>"
56
+ self.modules.each_with_index do |p, i|
57
+ label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
58
+ label << row_separator(i, num_modules)
59
+ end
60
+ label << '</tr>'
61
+ end
62
+ label
63
+ end
64
+
65
+ def row_separator(index, size)
66
+ return '' unless self.max_column && self.max_column.respond_to?(:to_i)
67
+ if ((index + 1) % self.max_column == 0) && index + 1 < size
68
+ "</tr><tr border='1'>"
32
69
  else
33
- label = "<tr border='1'><td>#{self.name}</td></tr>"
70
+ ''
71
+ end
72
+ end
73
+
74
+ def num_columns
75
+ number = [num_ports, num_modules, 1].max
76
+ if self.max_column && self.max_column.respond_to?(:to_i)
77
+ number = [self.max_column, number].min
78
+ end
79
+ number
80
+ end
81
+
82
+ def num_ports
83
+ if self.ports && self.ports.respond_to?(:size)
84
+ self.ports.size
85
+ else
86
+ 0
87
+ end
88
+ end
89
+
90
+ def num_modules
91
+ if self.modules && self.modules.respond_to?(:size)
92
+ self.modules.size
93
+ else
94
+ 0
34
95
  end
35
- "<table border='0'>#{label}</table>"
36
96
  end
37
97
  end
38
98
  end
@@ -1,3 +1,3 @@
1
1
  module NetworkDrawer
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_drawer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ota
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gviz
@@ -113,6 +113,7 @@ files:
113
113
  - examples/simple.svg
114
114
  - examples/simple.yml
115
115
  - examples/simple_style.json
116
+ - examples/simple_style.yml
116
117
  - lib/network_drawer.rb
117
118
  - lib/network_drawer/cli.rb
118
119
  - lib/network_drawer/diagram.rb