address pylint
This commit is contained in:
@ -13,7 +13,6 @@
|
|||||||
#
|
#
|
||||||
""" A vppcfg configuration module that validates prefixlists """
|
""" A vppcfg configuration module that validates prefixlists """
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
@ -41,11 +40,11 @@ def get_network_list(yaml, plname, want_ipv4=True, want_ipv6=True):
|
|||||||
in a prefixlist of given name. Return the empty list if the prefixlist doesn't
|
in a prefixlist of given name. Return the empty list if the prefixlist doesn't
|
||||||
exist. Optionally, want_ipv4 or want_ipv6 can be set to False to filter the list."""
|
exist. Optionally, want_ipv4 or want_ipv6 can be set to False to filter the list."""
|
||||||
ret = []
|
ret = []
|
||||||
plname, pl = get_by_name(yaml, plname)
|
plname, plist = get_by_name(yaml, plname)
|
||||||
if not pl:
|
if not plist:
|
||||||
return ret
|
return ret
|
||||||
for m in pl["members"]:
|
for member in plist["members"]:
|
||||||
ipn = ipaddress.ip_network(m, strict=False)
|
ipn = ipaddress.ip_network(member, strict=False)
|
||||||
if ipn.version == 4 and want_ipv4:
|
if ipn.version == 4 and want_ipv4:
|
||||||
ret.append(ipn)
|
ret.append(ipn)
|
||||||
if ipn.version == 6 and want_ipv6:
|
if ipn.version == 6 and want_ipv6:
|
||||||
@ -56,49 +55,49 @@ def get_network_list(yaml, plname, want_ipv4=True, want_ipv6=True):
|
|||||||
def count(yaml, plname):
|
def count(yaml, plname):
|
||||||
"""Return the number of IPv4 and IPv6 entries in the prefixlist.
|
"""Return the number of IPv4 and IPv6 entries in the prefixlist.
|
||||||
Returns 0, 0 if it doesn't exist"""
|
Returns 0, 0 if it doesn't exist"""
|
||||||
v4, v6 = 0, 0
|
ipv4, ipv6 = 0, 0
|
||||||
|
|
||||||
plname, pl = get_by_name(yaml, plname)
|
plname, plist = get_by_name(yaml, plname)
|
||||||
if not pl:
|
if not plist:
|
||||||
return 0, 0
|
return 0, 0
|
||||||
for m in pl["members"]:
|
for member in plist["members"]:
|
||||||
ipn = ipaddress.ip_network(m, strict=False)
|
ipn = ipaddress.ip_network(member, strict=False)
|
||||||
if ipn.version == 4:
|
if ipn.version == 4:
|
||||||
v4 += 1
|
ipv4 += 1
|
||||||
elif ipn.version == 6:
|
elif ipn.version == 6:
|
||||||
v6 += 1
|
ipv6 += 1
|
||||||
|
|
||||||
return v4, v6
|
return ipv4, ipv6
|
||||||
|
|
||||||
|
|
||||||
def count_ipv4(yaml, plname):
|
def count_ipv4(yaml, plname):
|
||||||
"""Return the number of IPv4 entries in the prefixlist."""
|
"""Return the number of IPv4 entries in the prefixlist."""
|
||||||
v4, v6 = count(yaml, plname)
|
ipv4, _ = count(yaml, plname)
|
||||||
return v4
|
return ipv4
|
||||||
|
|
||||||
|
|
||||||
def count_ipv6(yaml, plname):
|
def count_ipv6(yaml, plname):
|
||||||
"""Return the number of IPv6 entries in the prefixlist."""
|
"""Return the number of IPv6 entries in the prefixlist."""
|
||||||
v4, v6 = count(yaml, plname)
|
_, ipv6 = count(yaml, plname)
|
||||||
return v6
|
return ipv6
|
||||||
|
|
||||||
|
|
||||||
def has_ipv4(yaml, plname):
|
def has_ipv4(yaml, plname):
|
||||||
"""Return True if the prefixlist has at least one IPv4 entry."""
|
"""Return True if the prefixlist has at least one IPv4 entry."""
|
||||||
v4, v6 = count(yaml, plname)
|
ipv4, _ = count(yaml, plname)
|
||||||
return v4 > 0
|
return ipv4 > 0
|
||||||
|
|
||||||
|
|
||||||
def has_ipv6(yaml, plname):
|
def has_ipv6(yaml, plname):
|
||||||
"""Return True if the prefixlist has at least one IPv6 entry."""
|
"""Return True if the prefixlist has at least one IPv6 entry."""
|
||||||
v4, v6 = count(yaml, plname)
|
_, ipv6 = count(yaml, plname)
|
||||||
return v6 > 0
|
return ipv6 > 0
|
||||||
|
|
||||||
|
|
||||||
def is_empty(yaml, plname):
|
def is_empty(yaml, plname):
|
||||||
"""Return True if the prefixlist has no entries."""
|
"""Return True if the prefixlist has no entries."""
|
||||||
v4, v6 = count(yaml, plname)
|
ipv4, ipv6 = count(yaml, plname)
|
||||||
return v4 + v6 == 0
|
return ipv4 + ipv6 == 0
|
||||||
|
|
||||||
|
|
||||||
def validate_prefixlists(yaml):
|
def validate_prefixlists(yaml):
|
||||||
@ -111,8 +110,8 @@ def validate_prefixlists(yaml):
|
|||||||
if not "prefixlists" in yaml:
|
if not "prefixlists" in yaml:
|
||||||
return result, msgs
|
return result, msgs
|
||||||
|
|
||||||
for plname, pl in yaml["prefixlists"].items():
|
for plname, plist in yaml["prefixlists"].items():
|
||||||
logger.debug(f"prefixlist {plname}: {pl}")
|
logger.debug(f"prefixlist {plname}: {plist}")
|
||||||
if plname in ["any"]:
|
if plname in ["any"]:
|
||||||
## Note: ACL 'source' and 'destination', when they are empty, will resolve
|
## Note: ACL 'source' and 'destination', when they are empty, will resolve
|
||||||
## to 'any', and can thus never refer to a prefixlist called 'any'.
|
## to 'any', and can thus never refer to a prefixlist called 'any'.
|
||||||
@ -120,7 +119,7 @@ def validate_prefixlists(yaml):
|
|||||||
result = False
|
result = False
|
||||||
|
|
||||||
members = 0
|
members = 0
|
||||||
for pl_member in pl["members"]:
|
for pl_member in plist["members"]:
|
||||||
members += 1
|
members += 1
|
||||||
logger.debug(f"prefixlist {plname} member {members} is {pl_member}")
|
logger.debug(f"prefixlist {plname} member {members} is {pl_member}")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user