Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
re6stnet
Commits
191b0781
Commit
191b0781
authored
Jun 28, 2024
by
Tom Niget
Committed by
Julien Muchembled
Sep 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
demo: handle errors in SVG generation and fix empty prefix handling
parent
89ac5ebc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
14 deletions
+25
-14
demo/demo
demo/demo
+25
-14
No files found.
demo/demo
View file @
191b0781
...
...
@@ -412,6 +412,7 @@ def node_by_ll(addr):
_ll[a] = n, t
return _ll[addr]
def route_svg(ipv4, z=4):
graph = {}
for n in nodes:
...
...
@@ -420,8 +421,8 @@ def route_svg(ipv4, z=4):
if (r.prefix and r.prefix.startswith('10.42.') if ipv4 else
r.prefix is None or r.prefix.startswith('2001:db8:')):
try:
g[node_by_ll(r.nexthop)].append(
node_by_ll(r.prefix)[0] if r.prefix else default
)
if r.prefix:
g[node_by_ll(r.nexthop)].append(node_by_ll(r.prefix)[0]
)
except KeyError:
pass
gv = ["digraph { splines = true; edge[color=grey, labelangle=0];"]
...
...
@@ -436,9 +437,9 @@ def route_svg(ipv4, z=4):
j = abs(nodes.index(p[0]) - i)
l.append((min(j, N - j), p, r))
for j, (_, (p2, t), r) in enumerate(sorted(l, key=lambda x: x[0])):
l = []
l
2
= []
arrowhead = 'none'
for r2 in sorted(r2.short for r2 in r):
for r2 in sorted(r2.short
or ''
for r2 in r):
if r2:
if r2 == p2.short:
r2 = '
<font
color=
"grey"
>
%s
</font>
' % r2
...
...
@@ -483,11 +484,14 @@ if args.port:
if page
<
2:
body =
route_svg(page)
else:
body =
registry.Popen(('python3',
'
-c
',
r
"""
if
1:
out
,
err =
(
registry.Popen(('python3',
'
-c
',
r
"""
if
1:
import
math
,
json
from
re6st
.
registry
import
RegistryClient
g =
json.loads(RegistryClient(
'
http:
//
localhost
/').
topology
())
topo =
RegistryClient('http://localhost/').topology()
g =
json.loads(topo)
if
not
g:
print
('
digraph
{
"
empty
topology
"
[shape=
"none"
]
}')
exit
()
r =
set(g.pop('',
()))
a =
set()
for
v
in
g
.
values
()
:
...
...
@@ -506,13 +510,20 @@ if args.port:
for
v
in
v:
print
('"%
s
"
-
>
"%s";' % (n, title(v)))
print('}')
"""), stdout=subprocess.PIPE, cwd="..").communicate()[0].decode("utf-8")
if body:
body = subprocess.Popen(('neato', '-Tsvg'),
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
).communicate(body.encode("utf-8"))[0].decode("utf-8")
if not body:
self.send_error(500)
"""), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd="..")
.communicate())
if err:
self.send_error(500, explain='SVG generation failed: '
+ err.decode(errors='replace'))
return
graph_body = out.decode("utf-8")
try:
body = subprocess.run(
('neato', '-Tsvg'), check=True, text=True,
capture_output=True,
input=graph_body).stdout
except subprocess.CalledProcessError as e:
self.send_error(500, explain='neato failed: ' + e.stderr)
return
if ext == 'svg':
mt = 'image/svg+xml'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment