mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 05:21:55 -06:00
Extend Interface.link_peers() to support WirelessLinks
This commit is contained in:
parent
9a7f3f8c1a
commit
13ef5dc0b3
@ -143,13 +143,19 @@ class CabledObjectModel(models.Model):
|
||||
"mark_connected": "Cannot mark as connected with a cable attached."
|
||||
})
|
||||
|
||||
@property
|
||||
def link(self):
|
||||
"""
|
||||
Generic wrapper for a Cable, WirelessLink, or some other relation to a connected termination.
|
||||
"""
|
||||
return self.cable
|
||||
|
||||
@property
|
||||
def link_peers(self):
|
||||
# TODO: Support WirelessLinks
|
||||
if not self.cable:
|
||||
if self.cable:
|
||||
peers = self.cable.terminations.exclude(cable_end=self.cable_end).prefetch_related('termination')
|
||||
return [peer.termination for peer in peers]
|
||||
return []
|
||||
peer_terminations = self.cable.terminations.exclude(cable_end=self.cable_end).prefetch_related('termination')
|
||||
return [ct.termination for ct in peer_terminations]
|
||||
|
||||
@property
|
||||
def _occupied(self):
|
||||
@ -165,14 +171,6 @@ class CabledObjectModel(models.Model):
|
||||
return None
|
||||
return CableEndChoices.SIDE_A if self.cable_end == CableEndChoices.SIDE_B else CableEndChoices.SIDE_B
|
||||
|
||||
@property
|
||||
def link(self):
|
||||
"""
|
||||
Generic wrapper for a Cable, WirelessLink, or some other relation to a connected termination.
|
||||
"""
|
||||
# TODO: Support WirelessLinks
|
||||
return self.cable
|
||||
|
||||
|
||||
class PathEndpoint(models.Model):
|
||||
"""
|
||||
@ -832,6 +830,18 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd
|
||||
def link(self):
|
||||
return self.cable or self.wireless_link
|
||||
|
||||
@property
|
||||
def link_peers(self):
|
||||
if self.cable:
|
||||
return super().link_peers
|
||||
if self.wireless_link:
|
||||
# Return the opposite side of the attached wireless link
|
||||
if self.wireless_link.interface_a == self:
|
||||
return [self.wireless_link.interface_b]
|
||||
else:
|
||||
return [self.wireless_link.interface_a]
|
||||
return []
|
||||
|
||||
@property
|
||||
def l2vpn_termination(self):
|
||||
return self.l2vpn_terminations.first()
|
||||
|
Loading…
Reference in New Issue
Block a user