updated network.py to leverage super()
This commit is contained in:
parent
68be311c7a
commit
b185c3c679
2 changed files with 16 additions and 24 deletions
|
@ -139,7 +139,7 @@ class NodeBase:
|
|||
if sort:
|
||||
return [self._netif[x] for x in sorted(self._netif)]
|
||||
else:
|
||||
return self._netif.values()
|
||||
return list(self._netif.values())
|
||||
|
||||
def numnetif(self):
|
||||
"""
|
||||
|
@ -158,11 +158,9 @@ class NodeBase:
|
|||
:return: interface index if found, -1 otherwise
|
||||
:rtype: int
|
||||
"""
|
||||
|
||||
for ifindex in self._netif:
|
||||
if self._netif[ifindex] is netif:
|
||||
return ifindex
|
||||
|
||||
return -1
|
||||
|
||||
def newifindex(self):
|
||||
|
|
|
@ -257,7 +257,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
will run on, default is None for localhost
|
||||
:param policy: network policy
|
||||
"""
|
||||
CoreNetworkBase.__init__(self, session, _id, name, start, server)
|
||||
super().__init__(session, _id, name, start, server)
|
||||
if name is None:
|
||||
name = str(self.id)
|
||||
if policy is not None:
|
||||
|
@ -346,8 +346,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
if self.up:
|
||||
netif.net_client.create_interface(self.brname, netif.localname)
|
||||
|
||||
CoreNetworkBase.attach(self, netif)
|
||||
super().attach(netif)
|
||||
|
||||
def detach(self, netif):
|
||||
"""
|
||||
|
@ -358,8 +357,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
if self.up:
|
||||
netif.net_client.delete_interface(self.brname, netif.localname)
|
||||
|
||||
CoreNetworkBase.detach(self, netif)
|
||||
super().detach(netif)
|
||||
|
||||
def linked(self, netif1, netif2):
|
||||
"""
|
||||
|
@ -652,7 +650,7 @@ class GreTapBridge(CoreNetwork):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
CoreNetwork.startup(self)
|
||||
super().startup()
|
||||
if self.gretap:
|
||||
self.attach(self.gretap)
|
||||
|
||||
|
@ -666,7 +664,7 @@ class GreTapBridge(CoreNetwork):
|
|||
self.detach(self.gretap)
|
||||
self.gretap.shutdown()
|
||||
self.gretap = None
|
||||
CoreNetwork.shutdown(self)
|
||||
super().shutdown()
|
||||
|
||||
def addrconfig(self, addrlist):
|
||||
"""
|
||||
|
@ -753,7 +751,7 @@ class CtrlNet(CoreNetwork):
|
|||
self.assign_address = assign_address
|
||||
self.updown_script = updown_script
|
||||
self.serverintf = serverintf
|
||||
CoreNetwork.__init__(self, session, _id, name, start, server)
|
||||
super().__init__(session, _id, name, start, server)
|
||||
|
||||
def add_addresses(self, address):
|
||||
"""
|
||||
|
@ -784,8 +782,7 @@ class CtrlNet(CoreNetwork):
|
|||
if self.net_client.existing_bridges(self.id):
|
||||
raise CoreError(f"old bridges exist for node: {self.id}")
|
||||
|
||||
CoreNetwork.startup(self)
|
||||
|
||||
super().startup()
|
||||
logging.info("added control network bridge: %s %s", self.brname, self.prefix)
|
||||
|
||||
if self.hostid and self.assign_address:
|
||||
|
@ -833,7 +830,7 @@ class CtrlNet(CoreNetwork):
|
|||
except CoreCommandError:
|
||||
logging.exception("error issuing shutdown script shutdown")
|
||||
|
||||
CoreNetwork.shutdown(self)
|
||||
super().shutdown()
|
||||
|
||||
def all_link_data(self, flags):
|
||||
"""
|
||||
|
@ -864,8 +861,7 @@ class PtpNet(CoreNetwork):
|
|||
raise ValueError(
|
||||
"Point-to-point links support at most 2 network interfaces"
|
||||
)
|
||||
|
||||
CoreNetwork.attach(self, netif)
|
||||
super().attach(netif)
|
||||
|
||||
def data(self, message_type, lat=None, lon=None, alt=None):
|
||||
"""
|
||||
|
@ -1017,7 +1013,7 @@ class HubNode(CoreNetwork):
|
|||
will run on, default is None for localhost
|
||||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
CoreNetwork.__init__(self, session, _id, name, start, server)
|
||||
super().__init__(session, _id, name, start, server)
|
||||
|
||||
# TODO: move to startup method
|
||||
if start:
|
||||
|
@ -1048,7 +1044,7 @@ class WlanNode(CoreNetwork):
|
|||
will run on, default is None for localhost
|
||||
:param policy: wlan policy
|
||||
"""
|
||||
CoreNetwork.__init__(self, session, _id, name, start, server, policy)
|
||||
super().__init__(session, _id, name, start, server, policy)
|
||||
# wireless model such as basic range
|
||||
self.model = None
|
||||
# mobility model such as scripted
|
||||
|
@ -1065,7 +1061,7 @@ class WlanNode(CoreNetwork):
|
|||
:param core.nodes.interface.Veth netif: network interface
|
||||
:return: nothing
|
||||
"""
|
||||
CoreNetwork.attach(self, netif)
|
||||
super().attach(netif)
|
||||
if self.model:
|
||||
netif.poshook = self.model.position_callback
|
||||
if netif.node is None:
|
||||
|
@ -1097,12 +1093,12 @@ class WlanNode(CoreNetwork):
|
|||
|
||||
def update_mobility(self, config):
|
||||
if not self.mobility:
|
||||
raise ValueError("no mobility set to update for node(%s)", self.id)
|
||||
raise ValueError(f"no mobility set to update for node({self.id})")
|
||||
self.mobility.update_config(config)
|
||||
|
||||
def updatemodel(self, config):
|
||||
if not self.model:
|
||||
raise ValueError("no model set to update for node(%s)", self.id)
|
||||
raise ValueError(f"no model set to update for node({self.id})")
|
||||
logging.debug(
|
||||
"node(%s) updating model(%s): %s", self.id, self.model.name, config
|
||||
)
|
||||
|
@ -1120,11 +1116,9 @@ class WlanNode(CoreNetwork):
|
|||
:return: list of link data
|
||||
:rtype: list[core.emulator.data.LinkData]
|
||||
"""
|
||||
all_links = CoreNetwork.all_link_data(self, flags)
|
||||
|
||||
all_links = super().all_link_data(flags)
|
||||
if self.model:
|
||||
all_links.extend(self.model.all_link_data(flags))
|
||||
|
||||
return all_links
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue