Fix / change the format of clag_id since the old format does not work for 800G switches

This commit is contained in:
Gašper Fele-Žorž 2026-04-10 16:40:27 +02:00
parent cbe9884684
commit c04538d4f6

View file

@ -34,19 +34,21 @@ class FilterModule(object):
''' '''
Generate a clag-id from a list of interfaces making up a MLAG bond Generate a clag-id from a list of interfaces making up a MLAG bond
The clag-id for a bond must be between 1 and 65535. Generate it by Interfaces on both sides must be the same. The clag-id is generated
combining the indexes of the lowest-numbered interface on each switch. from the interface name such as:
This avoids manual ID assignment while keeping them mostly stable. swp3 -> 3
swpX -> X
This clag-id does not change unless the lowest-numbered interface for swpXsY -> X0Y
the bond on any switch changes. IDs of other bonds are not affected. This may fail on very large switches with more than 1000 ports.
''' '''
clag_id = 0 clag_id = 0
key = lambda i: i.get('device', {}).get('name') key = lambda i: i.get('device', {}).get('name')
for device, ifaces in itertools.groupby(sorted(interfaces, key=key), key): proto_iface = sorted(interfaces, key=key)[0]
clag_id = 256 * clag_id + min(self.cl_iface_index(ifaces)) g = re.match(r"[^0-9]*([0-9]+)(s([0-9]+))?", proto_iface["name"]).groups()
if 1 <= clag_id <= 65535: # sanity checking clag_id = g[0]
return clag_id if g[2] is not None:
clag_id += '0' + g[2]
return clag_id
def cl_clag_sys_mac(self, address): def cl_clag_sys_mac(self, address):
'''Generate a system MAC address for a MLAG with the given address''' '''Generate a system MAC address for a MLAG with the given address'''