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