From ba07bcfbba2a0c710fa424651be9e29690ec6bfd Mon Sep 17 00:00:00 2001 From: Sander Steffann Date: Wed, 12 Jun 2019 19:59:57 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20graph=20now=20that=20CircuitTermination.i?= =?UTF-8?q?nterface=20doesn't=20exist=20anymore=20Note:=20it=20shouldn't?= =?UTF-8?q?=20have=20existed=20because=20of=20`related=5Fname=3D'+'`=20in?= =?UTF-8?q?=20the=20first=20place,=20but=20it=20did=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0071_auto_20190612_1730.py | 19 ++++++++++++++ netbox/dcim/models.py | 1 - netbox/extras/models.py | 25 +++++++------------ 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 netbox/dcim/migrations/0071_auto_20190612_1730.py diff --git a/netbox/dcim/migrations/0071_auto_20190612_1730.py b/netbox/dcim/migrations/0071_auto_20190612_1730.py new file mode 100644 index 000000000..cbcc406ae --- /dev/null +++ b/netbox/dcim/migrations/0071_auto_20190612_1730.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.2 on 2019-06-12 17:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0070_auto_20190612_1801'), + ] + + operations = [ + migrations.AlterField( + model_name='interface', + name='_connected_circuittermination', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='circuits.CircuitTermination'), + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 19306c7de..7541726b2 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -1949,7 +1949,6 @@ class Interface(CableTermination, ComponentModel): _connected_circuittermination = models.ForeignKey( to='circuits.CircuitTermination', on_delete=models.SET_NULL, - related_name='+', blank=True, null=True ) diff --git a/netbox/extras/models.py b/netbox/extras/models.py index 8d8a05e10..356ba2978 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -533,27 +533,20 @@ class TopologyMap(models.Model): def add_network_connections(self, devices): - from circuits.models import CircuitTermination from dcim.models import Interface # Add all interface connections to the graph - connected_interfaces = Interface.objects.select_related( - '_connected_interface__device' - ).filter( - Q(device__in=devices) | Q(_connected_interface__device__in=devices), - _connected_interface__isnull=False, - pk__lt=F('_connected_interface') - ) + connected_interfaces = Interface.objects.exclude(cable=None) + seen = set() for interface in connected_interfaces: + if interface in seen: + continue style = 'solid' if interface.connection_status == CONNECTION_STATUS_CONNECTED else 'dashed' - self.graph.edge(interface.device.name, interface.connected_endpoint.device.name, style=style) - - # Add all circuits to the graph - for termination in CircuitTermination.objects.filter(term_side='A', connected_endpoint__device__in=devices): - peer_termination = termination.get_peer_termination() - if (peer_termination is not None and peer_termination.interface is not None and - peer_termination.interface.device in devices): - self.graph.edge(termination.interface.device.name, peer_termination.interface.device.name, color='blue') + trace = interface.trace(follow_circuits=True) + endpoint = trace[-1][2] + if endpoint and endpoint.device in devices: + self.graph.edge(interface.device.name, endpoint.device.name, style=style) + seen.add(endpoint) def add_console_connections(self, devices):