Fix graph now that CircuitTermination.interface doesn't exist anymore

Note: it shouldn't have existed because of `related_name='+'` in the
first place, but it did…
This commit is contained in:
Sander Steffann 2019-06-12 19:59:57 +02:00
parent cb2e41ef54
commit ba07bcfbba
3 changed files with 28 additions and 17 deletions

View File

@ -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'),
),
]

View File

@ -1949,7 +1949,6 @@ class Interface(CableTermination, ComponentModel):
_connected_circuittermination = models.ForeignKey( _connected_circuittermination = models.ForeignKey(
to='circuits.CircuitTermination', to='circuits.CircuitTermination',
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name='+',
blank=True, blank=True,
null=True null=True
) )

View File

@ -533,27 +533,20 @@ class TopologyMap(models.Model):
def add_network_connections(self, devices): def add_network_connections(self, devices):
from circuits.models import CircuitTermination
from dcim.models import Interface from dcim.models import Interface
# Add all interface connections to the graph # Add all interface connections to the graph
connected_interfaces = Interface.objects.select_related( connected_interfaces = Interface.objects.exclude(cable=None)
'_connected_interface__device' seen = set()
).filter(
Q(device__in=devices) | Q(_connected_interface__device__in=devices),
_connected_interface__isnull=False,
pk__lt=F('_connected_interface')
)
for interface in connected_interfaces: for interface in connected_interfaces:
if interface in seen:
continue
style = 'solid' if interface.connection_status == CONNECTION_STATUS_CONNECTED else 'dashed' style = 'solid' if interface.connection_status == CONNECTION_STATUS_CONNECTED else 'dashed'
self.graph.edge(interface.device.name, interface.connected_endpoint.device.name, style=style) trace = interface.trace(follow_circuits=True)
endpoint = trace[-1][2]
# Add all circuits to the graph if endpoint and endpoint.device in devices:
for termination in CircuitTermination.objects.filter(term_side='A', connected_endpoint__device__in=devices): self.graph.edge(interface.device.name, endpoint.device.name, style=style)
peer_termination = termination.get_peer_termination() seen.add(endpoint)
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')
def add_console_connections(self, devices): def add_console_connections(self, devices):