From b35e64397a98eeeaa31f2f4c64f4a473d6ef7c3c Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Mon, 31 Oct 2022 13:28:20 +0200 Subject: [PATCH 1/7] fix evpn parameters for auto-create --- plugins/modules/onyx_bgp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/onyx_bgp.py b/plugins/modules/onyx_bgp.py index 0025ed0..5a79f57 100644 --- a/plugins/modules/onyx_bgp.py +++ b/plugins/modules/onyx_bgp.py @@ -111,7 +111,7 @@ - router bgp 320 vrf default neighbor evpn send-community extended - router bgp 320 vrf default address-family l2vpn-evpn neighbor evpn next-hop-unchanged - router bgp 320 vrf default address-family l2vpn-evpn neighbor evpn activate - - router bgp 320 vrf default address-family l2vpn-evpn auto-create + - router bgp 320 vrf default address-family l2vpn-evpn vni auto-create - router bgp 320 vrf default neighbor 10.3.3.4 remote-as 321 - router bgp 320 vrf default neighbor 10.3.3.4 ebgp-multihop 250 - router bgp 320 vrf default neighbor 10.3.3.5 remote-as 322 @@ -152,7 +152,7 @@ class OnyxBgpModule(BaseOnyxModule): EVPN_ACTIVATE_REGEX = re.compile( r'^\s.*router bgp\s+(\d+)\s+vrf\s+(\S+)\s+address-family l2vpn\-evpn neighbor evpn activate.*') EVPN_AUTO_CREATE_REGEX = re.compile( - r'^\s.*router bgp\s+(\d+)\s+vrf\s+(\S+)\s+address-family l2vpn\-evpn auto-create.*') + r'^\s.*router bgp\s+(\d+)\s+vrf\s+(\S+)\s+address-family l2vpn\-evpn vni auto-create.*') _purge = False @@ -166,7 +166,7 @@ class OnyxBgpModule(BaseOnyxModule): EVPN_SEND_COMMUNITY_EXTENDED_CMD = "router bgp %s vrf %s neighbor evpn send-community extended" EVPN_NEXT_HOP_UNCHANGED_CMD = "router bgp %s vrf %s address-family l2vpn-evpn neighbor evpn next-hop-unchanged" EVPN_ACTIVATE_CMD = "router bgp %s vrf %s address-family l2vpn-evpn neighbor evpn activate" - EVPN_AUTO_CREATE_CMD = "router bgp %s vrf %s address-family l2vpn-evpn auto-create" + EVPN_AUTO_CREATE_CMD = "router bgp %s vrf %s address-family l2vpn-evpn vni auto-create" EVPN_ENABLE_ATTRS = [EVPN_PEER_GROUP_ATTR, EVPN_SEND_COMMUNITY_EXTENDED_ATTR, EVPN_NEXT_HOP_UNCHANGED_ATTR, EVPN_ACTIVATE_ATTR, EVPN_AUTO_CREATE_ATTR] From c2cca0f32f14e91a1a4cb056473acf72fd9f2f10 Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Tue, 1 Nov 2022 14:02:22 +0200 Subject: [PATCH 2/7] fix vxlan support for 3.10.3100 --- plugins/modules/onyx_vxlan.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/modules/onyx_vxlan.py b/plugins/modules/onyx_vxlan.py index 747e62e..186d46c 100644 --- a/plugins/modules/onyx_vxlan.py +++ b/plugins/modules/onyx_vxlan.py @@ -83,8 +83,8 @@ class OnyxVxlanModule(BaseOnyxModule): - LOOPBACK_REGEX = re.compile(r'^loopback (\d+).*') - NVE_ID_REGEX = re.compile(r'^Interface NVE (\d+).*') + LOOPBACK_REGEX = re.compile(r'^loopback (\d*).*') + NVE_ID_REGEX = re.compile(r'^Interface NVE (\d*).*') def init_module(self): """ initialize module @@ -116,13 +116,16 @@ def _set_vxlan_config(self, vxlan_config): vxlan_config = vxlan_config[0] if not vxlan_config: return - nve_header = vxlan_config.get("header") - match = self.NVE_ID_REGEX.match(nve_header) - if match: - current_nve_id = int(match.group(1)) - self._current_config['nve_id'] = current_nve_id - if int(current_nve_id) != self._required_config.get("nve_id"): - return + interface_key='' + for key in vxlan_config.keys(): + if key.startswith('Interface NVE'): + match = self.NVE_ID_REGEX.match(key) + if match: + interface_key=key + current_nve_id = int(match.group(1)) + self._current_config['nve_id'] = current_nve_id + if int(current_nve_id) != self._required_config.get("nve_id"): + return self._current_config['mlag_tunnel_ip'] = vxlan_config.get("Mlag tunnel IP") controller_mode = vxlan_config.get("Controller mode") @@ -130,8 +133,7 @@ def _set_vxlan_config(self, vxlan_config): self._current_config['bgp'] = True else: self._current_config['bgp'] = False - - loopback_str = vxlan_config.get("Source interface") + loopback_str = vxlan_config.get(interface_key)[0].get("Source interface") match = self.LOOPBACK_REGEX.match(loopback_str) if match: loopback_id = match.group(1) @@ -143,8 +145,7 @@ def _set_vxlan_config(self, vxlan_config): nve_detail = self._show_nve_detail() if nve_detail is not None: - nve_detail = nve_detail[0] - + nve_detail = nve_detail[1] if nve_detail: for vlan_id in nve_detail: vni_vlan_mapping[int(vlan_id)] = dict( From b2476dc820f609c0f9e334992ec0c66610922957 Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Tue, 1 Nov 2022 14:35:33 +0200 Subject: [PATCH 3/7] fix api version check, it fails for 3.10 or higher --- plugins/modules/onyx_interface.py | 2 +- plugins/modules/onyx_l2_interface.py | 2 +- plugins/modules/onyx_l3_interface.py | 2 +- plugins/modules/onyx_linkagg.py | 2 +- plugins/modules/onyx_magp.py | 2 +- plugins/modules/onyx_pfc_interface.py | 2 +- plugins/modules/onyx_vlan.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/modules/onyx_interface.py b/plugins/modules/onyx_interface.py index 6926d24..ce16270 100644 --- a/plugins/modules/onyx_interface.py +++ b/plugins/modules/onyx_interface.py @@ -340,7 +340,7 @@ def load_current_config(self): config = self._get_interfaces_config() if not config: return - if self._os_version < self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): for if_data in config: if_name = self.get_if_name(if_data) self._current_config[if_name] = self._create_if_data( diff --git a/plugins/modules/onyx_l2_interface.py b/plugins/modules/onyx_l2_interface.py index 8dc43ef..23dae24 100644 --- a/plugins/modules/onyx_l2_interface.py +++ b/plugins/modules/onyx_l2_interface.py @@ -168,7 +168,7 @@ def get_access_vlan(cls, if_data): return None def _create_switchport_data(self, if_name, if_data): - if self._os_version >= self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): if_data = if_data[0] return { diff --git a/plugins/modules/onyx_l3_interface.py b/plugins/modules/onyx_l3_interface.py index c28c84f..f04025d 100644 --- a/plugins/modules/onyx_l3_interface.py +++ b/plugins/modules/onyx_l3_interface.py @@ -192,7 +192,7 @@ def _get_interfaces_config(self, interface_type): return get_interfaces_config(self._module, interface_type) def _parse_interfaces_config(self, if_type, if_config): - if self._os_version < self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): for if_data in if_config: if_name = self.get_config_attr(if_data, 'header') self._get_if_attributes(if_type, if_name, if_data) diff --git a/plugins/modules/onyx_linkagg.py b/plugins/modules/onyx_linkagg.py index 7ed02a7..1e07e43 100644 --- a/plugins/modules/onyx_linkagg.py +++ b/plugins/modules/onyx_linkagg.py @@ -221,7 +221,7 @@ def _get_port_channels(self, if_type): def _parse_port_channels_summary(self, lag_type, lag_summary): if lag_type == self.MLAG_TYPE: - if self._os_version >= self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): found_summary = False for summary_item in lag_summary: if self.MLAG_SUMMARY in summary_item: diff --git a/plugins/modules/onyx_magp.py b/plugins/modules/onyx_magp.py index 94189cd..257601a 100644 --- a/plugins/modules/onyx_magp.py +++ b/plugins/modules/onyx_magp.py @@ -129,7 +129,7 @@ def _create_magp_instance_data(self, magp_id, item): router_mac=self.get_config_attr(item, "Virtual MAC")) def _update_magp_data(self, magp_data): - if self._os_version >= self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): for magp_config in magp_data: for magp_name, data in iteritems(magp_config): magp_id = int(magp_name.replace('MAGP ', '')) diff --git a/plugins/modules/onyx_pfc_interface.py b/plugins/modules/onyx_pfc_interface.py index 21ab4fb..550b1bd 100644 --- a/plugins/modules/onyx_pfc_interface.py +++ b/plugins/modules/onyx_pfc_interface.py @@ -140,7 +140,7 @@ def load_current_config(self): pfc_config = self._get_pfc_config() if not pfc_config: return - if self._os_version >= self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): if len(pfc_config) >= 3: pfc_config = pfc_config[2] else: diff --git a/plugins/modules/onyx_vlan.py b/plugins/modules/onyx_vlan.py index d4e10cc..7ef167e 100644 --- a/plugins/modules/onyx_vlan.py +++ b/plugins/modules/onyx_vlan.py @@ -134,7 +134,7 @@ def get_required_config(self): self._required_config.append(params) def _create_vlan_data(self, vlan_id, vlan_data): - if self._os_version >= self.ONYX_API_VERSION: + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): vlan_data = vlan_data[0] return { 'vlan_id': vlan_id, From 7569e361c72876e07e88a7de885f9f5aacc0c89b Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Tue, 1 Nov 2022 14:45:08 +0200 Subject: [PATCH 4/7] maintain compatibility with older version --- plugins/modules/onyx_vxlan.py | 42 +++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/modules/onyx_vxlan.py b/plugins/modules/onyx_vxlan.py index 186d46c..fc1dd48 100644 --- a/plugins/modules/onyx_vxlan.py +++ b/plugins/modules/onyx_vxlan.py @@ -116,16 +116,26 @@ def _set_vxlan_config(self, vxlan_config): vxlan_config = vxlan_config[0] if not vxlan_config: return - interface_key='' - for key in vxlan_config.keys(): - if key.startswith('Interface NVE'): - match = self.NVE_ID_REGEX.match(key) - if match: - interface_key=key - current_nve_id = int(match.group(1)) - self._current_config['nve_id'] = current_nve_id - if int(current_nve_id) != self._required_config.get("nve_id"): - return + + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + interface_key='' + for key in vxlan_config.keys(): + if key.startswith('Interface NVE'): + match = self.NVE_ID_REGEX.match(key) + if match: + interface_key=key + current_nve_id = int(match.group(1)) + self._current_config['nve_id'] = current_nve_id + if int(current_nve_id) != self._required_config.get("nve_id"): + return + else: + nve_header = vxlan_config.get("header") + match = self.NVE_ID_REGEX.match(nve_header) + if match: + current_nve_id = int(match.group(1)) + self._current_config['nve_id'] = current_nve_id + if int(current_nve_id) != self._required_config.get("nve_id"): + return self._current_config['mlag_tunnel_ip'] = vxlan_config.get("Mlag tunnel IP") controller_mode = vxlan_config.get("Controller mode") @@ -133,7 +143,11 @@ def _set_vxlan_config(self, vxlan_config): self._current_config['bgp'] = True else: self._current_config['bgp'] = False - loopback_str = vxlan_config.get(interface_key)[0].get("Source interface") + + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + loopback_str = vxlan_config.get(interface_key)[0].get("Source interface") + else: + loopback_str = vxlan_config.get("Source interface") match = self.LOOPBACK_REGEX.match(loopback_str) if match: loopback_id = match.group(1) @@ -145,7 +159,10 @@ def _set_vxlan_config(self, vxlan_config): nve_detail = self._show_nve_detail() if nve_detail is not None: - nve_detail = nve_detail[1] + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + nve_detail = nve_detail[1] + else: + nve_detail = nve_detail[0] if nve_detail: for vlan_id in nve_detail: vni_vlan_mapping[int(vlan_id)] = dict( @@ -162,6 +179,7 @@ def _show_nve_detail(self): def load_current_config(self): self._current_config = dict() + self._os_version = self._get_os_version() vxlan_config = self._show_vxlan_config() if vxlan_config: self._set_vxlan_config(vxlan_config) From 9847731b50833222232524e28723a016a658cb02 Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Tue, 1 Nov 2022 14:46:02 +0200 Subject: [PATCH 5/7] revert regexp --- plugins/modules/onyx_vxlan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/onyx_vxlan.py b/plugins/modules/onyx_vxlan.py index fc1dd48..e71bd81 100644 --- a/plugins/modules/onyx_vxlan.py +++ b/plugins/modules/onyx_vxlan.py @@ -83,8 +83,8 @@ class OnyxVxlanModule(BaseOnyxModule): - LOOPBACK_REGEX = re.compile(r'^loopback (\d*).*') - NVE_ID_REGEX = re.compile(r'^Interface NVE (\d*).*') + LOOPBACK_REGEX = re.compile(r'^loopback (\d+).*') + NVE_ID_REGEX = re.compile(r'^Interface NVE (\d+).*') def init_module(self): """ initialize module From 77cfe79c452f1d401a95d0654126e0254d2fc38a Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Fri, 4 Nov 2022 16:31:56 +0200 Subject: [PATCH 6/7] correct the version compare --- plugins/modules/onyx_interface.py | 2 +- plugins/modules/onyx_linkagg.py | 2 +- plugins/modules/onyx_magp.py | 2 +- plugins/modules/onyx_pfc_interface.py | 2 +- plugins/modules/onyx_vlan.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/onyx_interface.py b/plugins/modules/onyx_interface.py index ce16270..a838239 100644 --- a/plugins/modules/onyx_interface.py +++ b/plugins/modules/onyx_interface.py @@ -340,7 +340,7 @@ def load_current_config(self): config = self._get_interfaces_config() if not config: return - if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + if int(self._os_version.replace('.',''))int(self.ONYX_API_VERSION.replace('.','')): + if int(self._os_version.replace('.',''))>=int(self.ONYX_API_VERSION.replace('.','')): found_summary = False for summary_item in lag_summary: if self.MLAG_SUMMARY in summary_item: diff --git a/plugins/modules/onyx_magp.py b/plugins/modules/onyx_magp.py index 257601a..20ed759 100644 --- a/plugins/modules/onyx_magp.py +++ b/plugins/modules/onyx_magp.py @@ -129,7 +129,7 @@ def _create_magp_instance_data(self, magp_id, item): router_mac=self.get_config_attr(item, "Virtual MAC")) def _update_magp_data(self, magp_data): - if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + if int(self._os_version.replace('.',''))>=int(self.ONYX_API_VERSION.replace('.','')): for magp_config in magp_data: for magp_name, data in iteritems(magp_config): magp_id = int(magp_name.replace('MAGP ', '')) diff --git a/plugins/modules/onyx_pfc_interface.py b/plugins/modules/onyx_pfc_interface.py index 550b1bd..b191ed8 100644 --- a/plugins/modules/onyx_pfc_interface.py +++ b/plugins/modules/onyx_pfc_interface.py @@ -140,7 +140,7 @@ def load_current_config(self): pfc_config = self._get_pfc_config() if not pfc_config: return - if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + if int(self._os_version.replace('.',''))>=int(self.ONYX_API_VERSION.replace('.','')): if len(pfc_config) >= 3: pfc_config = pfc_config[2] else: diff --git a/plugins/modules/onyx_vlan.py b/plugins/modules/onyx_vlan.py index 7ef167e..5eff6cf 100644 --- a/plugins/modules/onyx_vlan.py +++ b/plugins/modules/onyx_vlan.py @@ -134,7 +134,7 @@ def get_required_config(self): self._required_config.append(params) def _create_vlan_data(self, vlan_id, vlan_data): - if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + if int(self._os_version.replace('.',''))>=int(self.ONYX_API_VERSION.replace('.','')): vlan_data = vlan_data[0] return { 'vlan_id': vlan_id, From 03dafb91f70c75e12a769b5d8fca28290425a1ed Mon Sep 17 00:00:00 2001 From: Mihai Vintila Date: Wed, 9 Nov 2022 18:17:40 +0200 Subject: [PATCH 7/7] correctly identify running nve settings --- plugins/modules/onyx_vxlan.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/modules/onyx_vxlan.py b/plugins/modules/onyx_vxlan.py index e71bd81..101feea 100644 --- a/plugins/modules/onyx_vxlan.py +++ b/plugins/modules/onyx_vxlan.py @@ -136,9 +136,13 @@ def _set_vxlan_config(self, vxlan_config): self._current_config['nve_id'] = current_nve_id if int(current_nve_id) != self._required_config.get("nve_id"): return + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + self._current_config['mlag_tunnel_ip'] = vxlan_config.get(interface_key)[0].get("MLAG tunnel ip") + controller_mode = vxlan_config.get(interface_key)[0].get("Controller mode") + else: + self._current_config['mlag_tunnel_ip'] = vxlan_config.get("Mlag tunnel IP") + controller_mode = vxlan_config.get("Controller mode") - self._current_config['mlag_tunnel_ip'] = vxlan_config.get("Mlag tunnel IP") - controller_mode = vxlan_config.get("Controller mode") if controller_mode == "BGP": self._current_config['bgp'] = True else: @@ -153,7 +157,10 @@ def _set_vxlan_config(self, vxlan_config): loopback_id = match.group(1) self._current_config['loopback_id'] = int(loopback_id) - self._current_config['global_neigh_suppression'] = vxlan_config.get("Global Neigh-Suppression") + if int(self._os_version.replace('.',''))>int(self.ONYX_API_VERSION.replace('.','')): + self._current_config['global_neigh_suppression'] = vxlan_config.get(interface_key)[0].get("Global neigh-suppression") + else: + self._current_config['global_neigh_suppression'] = vxlan_config.get("Global Neigh-Suppression") vni_vlan_mapping = self._current_config['vni_vlan_mapping'] = dict() nve_detail = self._show_nve_detail() @@ -222,9 +229,9 @@ def generate_commands(self): def _generate_vni_vlan_cmds(self, vni_vlan_list, nve_id, arp_suppression): current_global_arp_suppression = self._current_config.get('global_neigh_suppression') - if arp_suppression is True and current_global_arp_suppression != "Enable": + if arp_suppression is True and (not current_global_arp_suppression.startswith("Enable")): self._commands.append('interface nve {0} nve neigh-suppression'.format(nve_id)) - + current_vni_vlan_mapping = self._current_config.get('vni_vlan_mapping') if current_vni_vlan_mapping is None: for vni_vlan in vni_vlan_list: