Add get_bridgedomains()

This commit is contained in:
Pim van Pelt
2022-03-22 18:57:45 +00:00
parent 27ce2351c7
commit 0ab907f155
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,16 @@ class NullHandler(logging.Handler):
pass pass
def get_bridgedomains(yaml):
""" Return a list of all bridgedomains. """
ret = []
if not 'bridgedomains' in yaml:
return ret
for ifname, iface in yaml['bridgedomains'].items():
ret.append(ifname)
return ret
def get_by_name(yaml, ifname): def get_by_name(yaml, ifname):
""" Return the BridgeDomain by name, if it exists. Return None,None otherwise. """ """ Return the BridgeDomain by name, if it exists. Return None,None otherwise. """
try: try:

View File

@ -34,3 +34,7 @@ class TestBridgeDomainMethods(unittest.TestCase):
self.assertIn("BondEthernet0", ifs) self.assertIn("BondEthernet0", ifs)
self.assertIn("GigabitEthernet1/0/0", ifs) self.assertIn("GigabitEthernet1/0/0", ifs)
self.assertIn("GigabitEthernet2/0/0.100", ifs) self.assertIn("GigabitEthernet2/0/0.100", ifs)
def test_get_bridgedomains(self):
ifs = bridgedomain.get_bridgedomains(self.cfg)
self.assertEqual(len(ifs), 3)