diff --git a/config/bondethernet.py b/config/bondethernet.py index 077ccee..000708c 100644 --- a/config/bondethernet.py +++ b/config/bondethernet.py @@ -14,6 +14,15 @@ import logging import config.interface as interface +def get_bondethernets(yaml): + """ Return a list of all bondethernets. """ + ret = [] + if 'bondethernets' in yaml: + for ifname, iface in yaml['bondethernets'].items(): + ret.append(ifname) + return ret + + def get_by_name(yaml, ifname): """ Return the BondEthernet by name, if it exists. Return None,None otherwise. """ try: diff --git a/config/test_bondethernet.py b/config/test_bondethernet.py index 1cb37bc..58c9af4 100644 --- a/config/test_bondethernet.py +++ b/config/test_bondethernet.py @@ -28,3 +28,10 @@ class TestBondEthernetMethods(unittest.TestCase): self.assertTrue(bondethernet.is_bondethernet(self.cfg, "BondEthernet0")) self.assertFalse(bondethernet.is_bondethernet(self.cfg, "BondEthernet-notexist")) self.assertFalse(bondethernet.is_bondethernet(self.cfg, "GigabitEthernet1/0/0")) + + def test_enumerators(self): + ifs = bondethernet.get_bondethernets(self.cfg) + self.assertEqual(len(ifs), 1) + self.assertIn("BondEthernet0", ifs) + self.assertNotIn("BondEthernet-noexist", ifs) +