mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 19:52:52 -06:00
Rewrote get_connected_interface() to return first connection if more than one exist (erroneously)
This commit is contained in:
parent
05debf7e40
commit
7d6d7942d9
@ -1173,16 +1173,13 @@ class Interface(models.Model):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_connected_interface(self):
|
def get_connected_interface(self):
|
||||||
try:
|
connection = InterfaceConnection.objects.select_related().filter(Q(interface_a=self) | Q(interface_b=self))\
|
||||||
connection = InterfaceConnection.objects.select_related().get(Q(interface_a=self) | Q(interface_b=self))
|
.first()
|
||||||
if connection.interface_a == self:
|
if connection and connection.interface_a == self:
|
||||||
return connection.interface_b
|
return connection.interface_b
|
||||||
else:
|
elif connection:
|
||||||
return connection.interface_a
|
return connection.interface_a
|
||||||
except InterfaceConnection.DoesNotExist:
|
return None
|
||||||
return None
|
|
||||||
except InterfaceConnection.MultipleObjectsReturned:
|
|
||||||
raise MultipleObjectsReturned("Multiple connections found for {} interface {}!".format(self.device, self))
|
|
||||||
|
|
||||||
|
|
||||||
class InterfaceConnection(models.Model):
|
class InterfaceConnection(models.Model):
|
||||||
|
Loading…
Reference in New Issue
Block a user