mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Catch exceptions on graph generation
This commit is contained in:
parent
0c8e9e5825
commit
d83d0b66b0
@ -84,14 +84,19 @@ class TopologyMapView(APIView):
|
|||||||
|
|
||||||
# Add all connections to the graph
|
# Add all connections to the graph
|
||||||
devices = Device.objects.filter(*(device_superset,))
|
devices = Device.objects.filter(*(device_superset,))
|
||||||
connections = InterfaceConnection.objects.filter(interface_a__device__in=devices, interface_b__device__in=devices)
|
connections = InterfaceConnection.objects.filter(interface_a__device__in=devices,
|
||||||
|
interface_b__device__in=devices)
|
||||||
for c in connections:
|
for c in connections:
|
||||||
edge = pydot.Edge(c.interface_a.device.name, c.interface_b.device.name)
|
edge = pydot.Edge(c.interface_a.device.name, c.interface_b.device.name)
|
||||||
graph.add_edge(edge)
|
graph.add_edge(edge)
|
||||||
|
|
||||||
# Write the image to disk and return
|
# Write the image to disk and return
|
||||||
topo_file = tempfile.NamedTemporaryFile()
|
topo_file = tempfile.NamedTemporaryFile()
|
||||||
|
try:
|
||||||
graph.write(topo_file.name, format='png')
|
graph.write(topo_file.name, format='png')
|
||||||
|
except:
|
||||||
|
return HttpResponse("There was an error generating the requested graph. Ensure that the GraphViz "
|
||||||
|
"executables have been installed correctly.")
|
||||||
response = HttpResponse(FileWrapper(topo_file), content_type='image/png')
|
response = HttpResponse(FileWrapper(topo_file), content_type='image/png')
|
||||||
topo_file.close()
|
topo_file.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user