Initial formatting run with Black. Integration tests and unit tests pass before and after this change.
This commit is contained in:
@ -16,37 +16,38 @@ import config.lcp as lcp
|
||||
import config.address as address
|
||||
import config.mac as mac
|
||||
|
||||
|
||||
def get_loopbacks(yaml):
|
||||
""" Return a list of all loopbacks. """
|
||||
"""Return a list of all loopbacks."""
|
||||
ret = []
|
||||
if 'loopbacks' in yaml:
|
||||
for ifname, iface in yaml['loopbacks'].items():
|
||||
if "loopbacks" in yaml:
|
||||
for ifname, iface in yaml["loopbacks"].items():
|
||||
ret.append(ifname)
|
||||
return ret
|
||||
|
||||
|
||||
def get_by_lcp_name(yaml, lcpname):
|
||||
""" Returns the loopback by a given lcp name, or None,None if it does not exist """
|
||||
if not 'loopbacks' in yaml:
|
||||
return None,None
|
||||
for ifname, iface in yaml['loopbacks'].items():
|
||||
if 'lcp' in iface and iface['lcp'] == lcpname:
|
||||
"""Returns the loopback by a given lcp name, or None,None if it does not exist"""
|
||||
if not "loopbacks" in yaml:
|
||||
return None, None
|
||||
for ifname, iface in yaml["loopbacks"].items():
|
||||
if "lcp" in iface and iface["lcp"] == lcpname:
|
||||
return ifname, iface
|
||||
return None,None
|
||||
return None, None
|
||||
|
||||
|
||||
def get_by_name(yaml, ifname):
|
||||
""" Return the loopback by name, if it exists. Return None otherwise. """
|
||||
"""Return the loopback by name, if it exists. Return None otherwise."""
|
||||
try:
|
||||
if ifname in yaml['loopbacks']:
|
||||
return ifname, yaml['loopbacks'][ifname]
|
||||
if ifname in yaml["loopbacks"]:
|
||||
return ifname, yaml["loopbacks"][ifname]
|
||||
except:
|
||||
pass
|
||||
return None, None
|
||||
|
||||
|
||||
def is_loopback(yaml, ifname):
|
||||
""" Returns True if the interface name is an existing loopback. """
|
||||
"""Returns True if the interface name is an existing loopback."""
|
||||
ifname, iface = get_by_name(yaml, ifname)
|
||||
return not iface == None
|
||||
|
||||
@ -54,28 +55,36 @@ def is_loopback(yaml, ifname):
|
||||
def validate_loopbacks(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.config')
|
||||
logger = logging.getLogger("vppcfg.config")
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'loopbacks' in yaml:
|
||||
if not "loopbacks" in yaml:
|
||||
return result, msgs
|
||||
|
||||
for ifname, iface in yaml['loopbacks'].items():
|
||||
for ifname, iface in yaml["loopbacks"].items():
|
||||
logger.debug(f"loopback {iface}")
|
||||
instance = int(ifname[4:])
|
||||
if instance > 4095:
|
||||
msgs.append(f"loopback {ifname} has instance {int(instance)} which is too large")
|
||||
msgs.append(
|
||||
f"loopback {ifname} has instance {int(instance)} which is too large"
|
||||
)
|
||||
result = False
|
||||
if 'lcp' in iface and not lcp.is_unique(yaml, iface['lcp']):
|
||||
msgs.append(f"loopback {ifname} does not have a unique LCP name {iface['lcp']}")
|
||||
if "lcp" in iface and not lcp.is_unique(yaml, iface["lcp"]):
|
||||
msgs.append(
|
||||
f"loopback {ifname} does not have a unique LCP name {iface['lcp']}"
|
||||
)
|
||||
result = False
|
||||
if 'addresses' in iface:
|
||||
for a in iface['addresses']:
|
||||
if not address.is_allowed(yaml, ifname, iface['addresses'], a):
|
||||
msgs.append(f"loopback {ifname} IP address {a} conflicts with another")
|
||||
if "addresses" in iface:
|
||||
for a in iface["addresses"]:
|
||||
if not address.is_allowed(yaml, ifname, iface["addresses"], a):
|
||||
msgs.append(
|
||||
f"loopback {ifname} IP address {a} conflicts with another"
|
||||
)
|
||||
result = False
|
||||
if 'mac' in iface and mac.is_multicast(iface['mac']):
|
||||
msgs.append(f"loopback {ifname} MAC address {iface['mac']} cannot be multicast")
|
||||
if "mac" in iface and mac.is_multicast(iface["mac"]):
|
||||
msgs.append(
|
||||
f"loopback {ifname} MAC address {iface['mac']} cannot be multicast"
|
||||
)
|
||||
result = False
|
||||
|
||||
return result, msgs
|
||||
|
Reference in New Issue
Block a user