added othernet to CoreInterface to avoid hasattr checks

This commit is contained in:
Blake Harnden 2020-05-23 01:14:47 -07:00
parent c580e15f8e
commit 964f78f06a
3 changed files with 4 additions and 3 deletions

View file

@ -1086,11 +1086,11 @@ class CoreNetworkBase(NodeBase):
for netif in self.netifs(sort=True): for netif in self.netifs(sort=True):
if not hasattr(netif, "node"): if not hasattr(netif, "node"):
continue continue
linked_node = netif.node
uni = False uni = False
linked_node = netif.node
if linked_node is None: if linked_node is None:
# two layer-2 switches/hubs linked together via linknet() # two layer-2 switches/hubs linked together via linknet()
if not hasattr(netif, "othernet"): if not netif.othernet:
continue continue
linked_node = netif.othernet linked_node = netif.othernet
if linked_node.id == self.id: if linked_node.id == self.id:

View file

@ -51,6 +51,7 @@ class CoreInterface:
raise ValueError raise ValueError
self.mtu = mtu self.mtu = mtu
self.net = None self.net = None
self.othernet = None
self._params = {} self._params = {}
self.addrlist = [] self.addrlist = []
self.hwaddr = None self.hwaddr = None

View file

@ -580,7 +580,7 @@ class CoreNetwork(CoreNetworkBase):
:return: interface the provided network is linked to :return: interface the provided network is linked to
""" """
for netif in self.netifs(): for netif in self.netifs():
if hasattr(netif, "othernet") and netif.othernet == net: if netif.othernet == net:
return netif return netif
return None return None