Add MPLS config option and interface.is_mpls()

Also add tests and documentation
This commit is contained in:
Pim van Pelt
2023-06-10 15:31:09 +02:00
parent 0f27a15bee
commit 52b8cb5477
6 changed files with 28 additions and 1 deletions

View File

@ -701,3 +701,14 @@ def validate_interfaces(yaml):
result = False
return result, msgs
def is_mpls(yaml, ifname):
"""Returns True if the interface exists and has mpls enabled. Returns false otherwise."""
ifname, iface = get_by_name(yaml, ifname)
try:
if iface["mpls"] == True:
return True
except:
pass
return False

View File

@ -277,3 +277,10 @@ class TestInterfaceMethods(unittest.TestCase):
self.assertFalse(
interface.get_admin_state(self.cfg, "GigabitEthernet1/0/0.102")
)
def test_is_mpls(self):
self.assertTrue(interface.is_mpls(self.cfg, "GigabitEthernet1/0/1"))
self.assertTrue(interface.is_mpls(self.cfg, "GigabitEthernet1/0/1.101"))
self.assertFalse(interface.is_mpls(self.cfg, "GigabitEthernet1/0/0"))
self.assertFalse(interface.is_mpls(self.cfg, "GigabitEthernet1/0/0.100"))
self.assertFalse(interface.is_mpls(self.cfg, "notexist"))