updated config services to use getattr instead of hasattr to simplify code
This commit is contained in:
parent
852eb60ab9
commit
0749dcacb2
4 changed files with 17 additions and 15 deletions
|
@ -48,7 +48,7 @@ class NrlNhdp(ConfigService):
|
||||||
has_smf = "SMF" in self.node.config_services
|
has_smf = "SMF" in self.node.config_services
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict(has_smf=has_smf, ifnames=ifnames)
|
return dict(has_smf=has_smf, ifnames=ifnames)
|
||||||
|
@ -75,7 +75,7 @@ class NrlSmf(ConfigService):
|
||||||
ifnames = []
|
ifnames = []
|
||||||
ip4_prefix = None
|
ip4_prefix = None
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
if ip4_prefix:
|
if ip4_prefix:
|
||||||
|
@ -113,7 +113,7 @@ class NrlOlsr(ConfigService):
|
||||||
has_zebra = "zebra" in self.node.config_services
|
has_zebra = "zebra" in self.node.config_services
|
||||||
ifname = None
|
ifname = None
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifname = ifc.name
|
ifname = ifc.name
|
||||||
break
|
break
|
||||||
|
@ -138,7 +138,7 @@ class NrlOlsrv2(ConfigService):
|
||||||
has_smf = "SMF" in self.node.config_services
|
has_smf = "SMF" in self.node.config_services
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict(has_smf=has_smf, ifnames=ifnames)
|
return dict(has_smf=has_smf, ifnames=ifnames)
|
||||||
|
@ -162,7 +162,7 @@ class OlsrOrg(ConfigService):
|
||||||
has_smf = "SMF" in self.node.config_services
|
has_smf = "SMF" in self.node.config_services
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict(has_smf=has_smf, ifnames=ifnames)
|
return dict(has_smf=has_smf, ifnames=ifnames)
|
||||||
|
@ -200,7 +200,7 @@ class Arouted(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
ip4_prefix = None
|
ip4_prefix = None
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
if ip4_prefix:
|
if ip4_prefix:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -32,7 +32,7 @@ def get_router_id(node: CoreNodeBase) -> str:
|
||||||
Helper to return the first IPv4 address of a node as its router ID.
|
Helper to return the first IPv4 address of a node as its router ID.
|
||||||
"""
|
"""
|
||||||
for ifc in node.netifs():
|
for ifc in node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
for a in ifc.addrlist:
|
for a in ifc.addrlist:
|
||||||
a = a.split("/")[0]
|
a = a.split("/")[0]
|
||||||
|
|
|
@ -82,7 +82,7 @@ class Nat(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict(ifnames=ifnames)
|
return dict(ifnames=ifnames)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
@ -28,6 +29,7 @@ class DefaultRouteService(ConfigService):
|
||||||
if getattr(netif, "control", False):
|
if getattr(netif, "control", False):
|
||||||
continue
|
continue
|
||||||
for addr in netif.addrlist:
|
for addr in netif.addrlist:
|
||||||
|
logging.info("default route address: %s", addr)
|
||||||
net = netaddr.IPNetwork(addr)
|
net = netaddr.IPNetwork(addr)
|
||||||
if net[1] != net[-2]:
|
if net[1] != net[-2]:
|
||||||
addresses.append(net[1])
|
addresses.append(net[1])
|
||||||
|
@ -51,7 +53,7 @@ class DefaultMulticastRouteService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
ifname = None
|
ifname = None
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifname = ifc.name
|
ifname = ifc.name
|
||||||
break
|
break
|
||||||
|
@ -75,7 +77,7 @@ class StaticRouteService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
routes = []
|
routes = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
for x in ifc.addrlist:
|
for x in ifc.addrlist:
|
||||||
addr = x.split("/")[0]
|
addr = x.split("/")[0]
|
||||||
|
@ -150,7 +152,7 @@ class DhcpService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
subnets = []
|
subnets = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
for x in ifc.addrlist:
|
for x in ifc.addrlist:
|
||||||
addr = x.split("/")[0]
|
addr = x.split("/")[0]
|
||||||
|
@ -181,7 +183,7 @@ class DhcpClientService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict(ifnames=ifnames)
|
return dict(ifnames=ifnames)
|
||||||
|
@ -219,7 +221,7 @@ class PcapService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
ifnames = []
|
ifnames = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
ifnames.append(ifc.name)
|
ifnames.append(ifc.name)
|
||||||
return dict()
|
return dict()
|
||||||
|
@ -242,7 +244,7 @@ class RadvdService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
interfaces = []
|
interfaces = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
prefixes = []
|
prefixes = []
|
||||||
for x in ifc.addrlist:
|
for x in ifc.addrlist:
|
||||||
|
@ -294,7 +296,7 @@ class HttpService(ConfigService):
|
||||||
def data(self) -> Dict[str, Any]:
|
def data(self) -> Dict[str, Any]:
|
||||||
interfaces = []
|
interfaces = []
|
||||||
for ifc in self.node.netifs():
|
for ifc in self.node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if getattr(ifc, "control", False):
|
||||||
continue
|
continue
|
||||||
interfaces.append(ifc)
|
interfaces.append(ifc)
|
||||||
return dict(interfaces=interfaces)
|
return dict(interfaces=interfaces)
|
||||||
|
|
Loading…
Reference in a new issue