Add bond/bridge YAML emitter
Add int_to_mode() and int_to_lb() in config/bondethernet.py to map back the retrieved values from VPP into their config strings. Implement bond and bridge settings dumper, dumping all settings even if they are default. This helps the user understand the configurable options.
This commit is contained in:
@ -81,6 +81,20 @@ def mode_to_int(mode):
|
||||
return -1
|
||||
|
||||
|
||||
def int_to_mode(mode):
|
||||
""" Returns the string representation in VPP of a given bondethernet mode,
|
||||
or "" if 'mode' is not a valid id.
|
||||
|
||||
See src/vnet/bonding/bond.api and schema.yaml for valid pairs. """
|
||||
|
||||
ret = { 1: 'round-robin', 2: 'active-backup', 3: 'xor', 4: 'broadcast', 5: 'lacp' }
|
||||
try:
|
||||
return ret[mode]
|
||||
except:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def get_lb(yaml, ifname):
|
||||
""" Return the loadbalance strategy of the BondEthernet as a string. Only
|
||||
'xor' and 'lacp' modes have loadbalance strategies, so return None if
|
||||
@ -116,6 +130,21 @@ def lb_to_int(lb):
|
||||
return -1
|
||||
|
||||
|
||||
def int_to_lb(lb):
|
||||
""" Returns the string representation in VPP of a given load-balance strategy,
|
||||
or "" if 'lb' is not a valid int.
|
||||
|
||||
See src/vnet/bonding/bond.api and schema.yaml for valid pairs, although
|
||||
bond.api defined more than we use in vppcfg. """
|
||||
|
||||
ret = { 0: 'l2', 1: 'l34', 2: 'l23', 3: 'round-robin', 4: 'broadcast', 5: 'active-backup' }
|
||||
try:
|
||||
return ret[lb]
|
||||
except:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def validate_bondethernets(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
|
@ -49,6 +49,15 @@ class TestBondEthernetMethods(unittest.TestCase):
|
||||
self.assertEqual(5, bondethernet.mode_to_int("lacp"))
|
||||
self.assertEqual(-1, bondethernet.mode_to_int("not-exist"))
|
||||
|
||||
def test_int_to_mode(self):
|
||||
self.assertEqual("round-robin", bondethernet.int_to_mode(1))
|
||||
self.assertEqual("active-backup", bondethernet.int_to_mode(2))
|
||||
self.assertEqual("xor", bondethernet.int_to_mode(3))
|
||||
self.assertEqual("broadcast", bondethernet.int_to_mode(4))
|
||||
self.assertEqual("lacp", bondethernet.int_to_mode(5))
|
||||
self.assertEqual("", bondethernet.int_to_mode(0))
|
||||
self.assertEqual("", bondethernet.int_to_mode(6))
|
||||
|
||||
def test_get_lb(self):
|
||||
self.assertEqual('l34', bondethernet.get_lb(self.cfg, "BondEthernet0"))
|
||||
self.assertEqual('l2', bondethernet.get_lb(self.cfg, "BondEthernet1"))
|
||||
@ -62,3 +71,12 @@ class TestBondEthernetMethods(unittest.TestCase):
|
||||
self.assertEqual(4, bondethernet.lb_to_int("broadcast"))
|
||||
self.assertEqual(5, bondethernet.lb_to_int("active-backup"))
|
||||
self.assertEqual(-1, bondethernet.lb_to_int("not-exist"))
|
||||
|
||||
def test_int_to_lb(self):
|
||||
self.assertEqual("l2", bondethernet.int_to_lb(0))
|
||||
self.assertEqual("l34", bondethernet.int_to_lb(1))
|
||||
self.assertEqual("l23", bondethernet.int_to_lb(2))
|
||||
self.assertEqual("round-robin", bondethernet.int_to_lb(3))
|
||||
self.assertEqual("broadcast", bondethernet.int_to_lb(4))
|
||||
self.assertEqual("active-backup", bondethernet.int_to_lb(5))
|
||||
self.assertEqual("", bondethernet.int_to_lb(-1))
|
||||
|
Reference in New Issue
Block a user