diff --git a/filter_plugins/cumulus.py b/filter_plugins/cumulus.py index 7186cd9..72386e1 100644 --- a/filter_plugins/cumulus.py +++ b/filter_plugins/cumulus.py @@ -34,19 +34,21 @@ 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 - return clag_id + 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): '''Generate a system MAC address for a MLAG with the given address'''