Parcourir la source

Closes #430: Include circuits when rendering topology maps

Jeremy Stretch il y a 8 ans
Parent
commit
fc46f70153
1 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 8 1
      netbox/extras/models.py

+ 8 - 1
netbox/extras/models.py

@@ -318,6 +318,7 @@ class TopologyMap(models.Model):
 
     def render(self, img_format='png'):
 
+        from circuits.models import CircuitTermination
         from dcim.models import Device, InterfaceConnection
 
         # Construct the graph
@@ -352,7 +353,7 @@ class TopologyMap(models.Model):
             for query in device_set.split(';'):  # Split regexes on semicolons
                 device_superset = device_superset | Q(name__regex=query)
 
-        # Add all connections to the graph
+        # Add all interface connections to the graph
         devices = Device.objects.filter(*(device_superset,))
         connections = InterfaceConnection.objects.filter(
             interface_a__device__in=devices, interface_b__device__in=devices
@@ -360,6 +361,12 @@ class TopologyMap(models.Model):
         for c in connections:
             graph.edge(c.interface_a.device.name, c.interface_b.device.name)
 
+        # Add all circuits to the graph
+        for termination in CircuitTermination.objects.filter(term_side='A', interface__device__in=devices):
+            peer_termination = termination.get_peer_termination()
+            if peer_termination is not None and peer_termination.interface.device in devices:
+                graph.edge(termination.interface.device.name, peer_termination.interface.device.name, color='blue')
+
         return graph.pipe(format=img_format)