daemon: refactored InterfaceData.get_addresses to InterfaceData.get_ips
This commit is contained in:
parent
20feea8f12
commit
9e4429fbbc
5 changed files with 19 additions and 21 deletions
|
@ -213,11 +213,9 @@ class EmaneLinkMonitor:
|
|||
for node in nodes:
|
||||
for iface in node.get_ifaces():
|
||||
if isinstance(iface.net, CtrlNet):
|
||||
address = None
|
||||
ip4 = iface.get_ip4()
|
||||
if ip4:
|
||||
address = str(ip4.ip)
|
||||
if address:
|
||||
addresses.append(address)
|
||||
break
|
||||
return addresses
|
||||
|
|
|
@ -142,18 +142,18 @@ class InterfaceData:
|
|||
ip6: str = None
|
||||
ip6_mask: int = None
|
||||
|
||||
def get_addresses(self) -> List[str]:
|
||||
def get_ips(self) -> List[str]:
|
||||
"""
|
||||
Returns a list of ip4 and ip6 addresses when present.
|
||||
|
||||
:return: list of addresses
|
||||
:return: list of ip addresses
|
||||
"""
|
||||
addresses = []
|
||||
ips = []
|
||||
if self.ip4 and self.ip4_mask:
|
||||
addresses.append(f"{self.ip4}/{self.ip4_mask}")
|
||||
ips.append(f"{self.ip4}/{self.ip4_mask}")
|
||||
if self.ip6 and self.ip6_mask:
|
||||
addresses.append(f"{self.ip6}/{self.ip6_mask}")
|
||||
return addresses
|
||||
ips.append(f"{self.ip6}/{self.ip6_mask}")
|
||||
return ips
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -811,7 +811,7 @@ class CoreNode(CoreNodeBase):
|
|||
:param iface_data: interface data for new interface
|
||||
:return: interface index
|
||||
"""
|
||||
addresses = iface_data.get_addresses()
|
||||
ips = iface_data.get_ips()
|
||||
with self.lock:
|
||||
# TODO: emane specific code
|
||||
if net.is_emane is True:
|
||||
|
@ -823,15 +823,15 @@ class CoreNode(CoreNodeBase):
|
|||
self.attachnet(iface_id, net)
|
||||
iface = self.get_iface(iface_id)
|
||||
iface.set_mac(iface_data.mac)
|
||||
for address in addresses:
|
||||
iface.add_ip(address)
|
||||
for ip in ips:
|
||||
iface.add_ip(ip)
|
||||
else:
|
||||
iface_id = self.newveth(iface_data.id, iface_data.name)
|
||||
self.attachnet(iface_id, net)
|
||||
if iface_data.mac:
|
||||
self.set_mac(iface_id, iface_data.mac)
|
||||
for address in addresses:
|
||||
self.add_ip(iface_id, address)
|
||||
for ip in ips:
|
||||
self.add_ip(iface_id, ip)
|
||||
self.ifup(iface_id)
|
||||
iface = self.get_iface(iface_id)
|
||||
return iface
|
||||
|
|
|
@ -697,9 +697,9 @@ class GreTapBridge(CoreNetwork):
|
|||
:return: nothing
|
||||
"""
|
||||
self.grekey = key
|
||||
addresses = iface_data.get_addresses()
|
||||
if addresses:
|
||||
self.add_ips(addresses)
|
||||
ips = iface_data.get_ips()
|
||||
if ips:
|
||||
self.add_ips(ips)
|
||||
|
||||
|
||||
class CtrlNet(CoreNetwork):
|
||||
|
|
|
@ -156,7 +156,7 @@ class PhysicalNode(CoreNodeBase):
|
|||
self, net: CoreNetworkBase, iface_data: InterfaceData
|
||||
) -> CoreInterface:
|
||||
logging.info("creating interface")
|
||||
addresses = iface_data.get_addresses()
|
||||
ips = iface_data.get_ips()
|
||||
iface_id = iface_data.id
|
||||
if iface_id is None:
|
||||
iface_id = self.next_iface_id()
|
||||
|
@ -167,12 +167,12 @@ class PhysicalNode(CoreNodeBase):
|
|||
# this is reached when this node is linked to a network node
|
||||
# tunnel to net not built yet, so build it now and adopt it
|
||||
_, remote_tap = self.session.distributed.create_gre_tunnel(net, self.server)
|
||||
self.adopt_iface(remote_tap, iface_id, iface_data.mac, addresses)
|
||||
self.adopt_iface(remote_tap, iface_id, iface_data.mac, ips)
|
||||
return remote_tap
|
||||
else:
|
||||
# this is reached when configuring services (self.up=False)
|
||||
iface = GreTap(node=self, name=name, session=self.session, start=False)
|
||||
self.adopt_iface(iface, iface_id, iface_data.mac, addresses)
|
||||
self.adopt_iface(iface, iface_id, iface_data.mac, ips)
|
||||
return iface
|
||||
|
||||
def privatedir(self, path: str) -> None:
|
||||
|
@ -316,8 +316,8 @@ class Rj45Node(CoreNodeBase):
|
|||
self.iface_id = iface_id
|
||||
if net is not None:
|
||||
self.iface.attachnet(net)
|
||||
for addr in iface_data.get_addresses():
|
||||
self.add_ip(addr)
|
||||
for ip in iface_data.get_ips():
|
||||
self.add_ip(ip)
|
||||
return self.iface
|
||||
|
||||
def delete_iface(self, iface_id: int) -> None:
|
||||
|
|
Loading…
Reference in a new issue