Add prefixlist.get_network_list() + tests
This commit is contained in:
@ -36,6 +36,20 @@ def get_by_name(yaml, plname):
|
||||
return None, None
|
||||
|
||||
|
||||
def get_network_list(yaml, plname):
|
||||
"""Returns a list of 0 or more ip_network elements, that represent the members
|
||||
in a prefixlist of given name. Return the empty list if the prefixlist doesn't
|
||||
exist"""
|
||||
ret = []
|
||||
plname, pl = get_by_name(yaml, plname)
|
||||
if not pl:
|
||||
return ret
|
||||
for m in pl["members"]:
|
||||
ipn = ipaddress.ip_network(m, strict=False)
|
||||
ret.append(ipn)
|
||||
return ret
|
||||
|
||||
|
||||
def count(yaml, plname):
|
||||
"""Return the number of IPv4 and IPv6 entries in the prefixlist.
|
||||
Returns 0, 0 if it doesn't exist"""
|
||||
|
@ -75,3 +75,12 @@ class TestACLMethods(unittest.TestCase):
|
||||
self.assertFalse(prefixlist.is_empty(self.cfg, "trusted"))
|
||||
self.assertTrue(prefixlist.is_empty(self.cfg, "empty"))
|
||||
self.assertTrue(prefixlist.is_empty(self.cfg, "pl-noexist"))
|
||||
|
||||
def test_get_network_list(self):
|
||||
l = prefixlist.get_network_list(self.cfg, "trusted")
|
||||
self.assertIsInstance(l, list)
|
||||
self.assertEquals(4, len(l))
|
||||
|
||||
l = prefixlist.get_network_list(self.cfg, "pl-notexist")
|
||||
self.assertIsInstance(l, list)
|
||||
self.assertEquals(0, len(l))
|
||||
|
Reference in New Issue
Block a user