From 0afafebdc8f30aa452387cc33ee2e08b7023ae49 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Tue, 14 Nov 2023 15:35:24 +0300 Subject: [PATCH 1/5] fix dialer1:0 interface --- napalm_huawei_vrp/huawei_vrp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index 2907f02..d62169e 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -616,6 +616,8 @@ def get_interfaces(self): msg = "Unexpected interface format: {}".format(interface) raise ValueError(msg) intf_name = match_intf.group("intf_name") + if intf_name == 'Dialer1:0': + continue intf_state = match_intf.group("intf_state") is_enabled = bool("up" in intf_state.lower()) From 7a1960512cefb484c3be454c0f5095589832a61f Mon Sep 17 00:00:00 2001 From: Vladislav Date: Tue, 14 Nov 2023 15:36:29 +0300 Subject: [PATCH 2/5] fix get_facts to AR, NE devices --- napalm_huawei_vrp/huawei_vrp.py | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index d62169e..629572d 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -221,22 +221,30 @@ def get_facts(self): # os_version/uptime/model for line in show_ver.splitlines(): - if "VRP (R) software" in line: - search_result = re.search(r"\(S\S+\s+(?PV\S+)\)", line) - if search_result is not None: - os_version = search_result.group("os_version") - - if "HUAWEI" in line and "uptime is" in line: - search_result = re.search(r"S\S+", line) - if search_result is not None: - model = search_result.group(0) - uptime = self._parse_uptime(line) - break + if 'VRP (R) software' in line: + line_process = re.split(' ', line) + os_version = line_process[len(line_process)-1] + os_version = os_version[:-1] + if 'HUAWEI ' in line: + if 'uptime is' in line: + line_process = re.split('uptime is', line) + model = re.split('HUAWEI', line_process[0])[1].lstrip().rstrip() + uptime = self._parse_uptime(line_process[1]) + if 'Routing Switch' in model: + model = re.split(' ', model)[0] + elif 'Huawei ' in line: + if 'uptime is' in line: + line_process = re.split('uptime is', line) + model = re.split('Huawei', line_process[0])[1].lstrip().rstrip() + uptime = self._parse_uptime(line_process[1]) + if 'Router' in model: + model = re.split(' ', model)[0] # get serial_number,due to the stack have multiple SN, so show it in a list # 由于堆叠设备会有多少个SN,所以这里用列表展示 - re_sn = r"ESN\s+of\s+slot\s+\S+\s+(?P\S+)" - serial_number = re.findall(re_sn, show_esn, flags=re.M) + serial_number = [] + for line in show_esn.splitlines(): + serial_number.append(re.split(':', line)[1].lstrip().rstrip()) if "sysname " in show_hostname: _, hostname = show_hostname.split("sysname ") From 791d3f425c6a0b331a873f6ceacfa580a26f36df Mon Sep 17 00:00:00 2001 From: Vladislav Date: Tue, 14 Nov 2023 15:37:10 +0300 Subject: [PATCH 3/5] add speed eth-trunk speed to AR, NE, CE devices --- napalm_huawei_vrp/huawei_vrp.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index 629572d..3ea2413 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -612,6 +612,8 @@ def get_interfaces(self): re_mac = r"Hardware address is\W+(?P\S+)" re_speed = r"^Speed\W+(?P\d+|\w+)" re_description = r"Description:(?:(?:)|(?P.*))\n" + re_speed_eth_ce = r"Current BW : +(?P\d+)" + re_speed_eth_ar = r"Current BW: +(?P\d+)" re_mtu = r"Maximum Transmit Unit(?:(?:\(L3\))|(?:)) is (?P\d+)" new_interfaces = self._separate_section(separator, output) @@ -651,6 +653,16 @@ def get_interfaces(self): speed = match_speed.group("speed") if speed.isdigit(): speed = float(speed) + match_speed_eth_ar = re.findall(re_speed_eth_ar, interface, flags=re.M) + + if match_speed_eth_ar: + if match_speed_eth_ar[0].isdigit(): + speed = float(match_speed_eth_ar[0]) * 1000 + + match_speed_eth_ce = re.findall(re_speed_eth_ce, interface, flags=re.M) + if match_speed_eth_ce: + if match_speed_eth_ce[0].isdigit(): + speed = float(match_speed_eth_ce[0]) * 1000 # description matching description = "" From fd9532c171a6ae0a9a47ae09804c06c3442415b8 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Tue, 14 Nov 2023 15:37:41 +0300 Subject: [PATCH 4/5] add ip address to Dialer, DHCP interfaces --- napalm_huawei_vrp/huawei_vrp.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index 3ea2413..c32db7d 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -742,6 +742,13 @@ def get_interfaces_ip(self): # v4_interfaces[intf_name] = {} match_ip = re.findall(re_intf_ip, interface, flags=re.M) + if len(match_ip) == 0: + re_intf_ip = r"Internet Address is negotiated,\s+(?P\d+.\d+.\d+.\d+)\/(?P\d+)" + match_ip = re.findall(re_intf_ip, interface, flags=re.M) + if len(match_ip) == 0: + re_intf_ip = r"Internet Address is allocated by DHCP,\s+(?P\d+.\d+.\d+.\d+)\/(?P\d+)" + match_ip = re.findall(re_intf_ip, interface, flags=re.M) + for ip_info in match_ip: val = {"prefix_length": int(ip_info[1])} # v4_interfaces[intf_name][ip_info[0]] = val From 404d1b6a4a76b4b68ce6f68c957a6aaa21f71ace Mon Sep 17 00:00:00 2001 From: Vladislav Date: Tue, 19 Dec 2023 11:27:35 +0300 Subject: [PATCH 5/5] formatted the code using black --- napalm_huawei_vrp/huawei_vrp.py | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index c32db7d..8925282 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -221,30 +221,30 @@ def get_facts(self): # os_version/uptime/model for line in show_ver.splitlines(): - if 'VRP (R) software' in line: - line_process = re.split(' ', line) - os_version = line_process[len(line_process)-1] + if "VRP (R) software" in line: + line_process = re.split(" ", line) + os_version = line_process[len(line_process) - 1] os_version = os_version[:-1] - if 'HUAWEI ' in line: - if 'uptime is' in line: - line_process = re.split('uptime is', line) - model = re.split('HUAWEI', line_process[0])[1].lstrip().rstrip() + if "HUAWEI " in line: + if "uptime is" in line: + line_process = re.split("uptime is", line) + model = re.split("HUAWEI", line_process[0])[1].lstrip().rstrip() uptime = self._parse_uptime(line_process[1]) - if 'Routing Switch' in model: - model = re.split(' ', model)[0] - elif 'Huawei ' in line: - if 'uptime is' in line: - line_process = re.split('uptime is', line) - model = re.split('Huawei', line_process[0])[1].lstrip().rstrip() + if "Routing Switch" in model: + model = re.split(" ", model)[0] + elif "Huawei " in line: + if "uptime is" in line: + line_process = re.split("uptime is", line) + model = re.split("Huawei", line_process[0])[1].lstrip().rstrip() uptime = self._parse_uptime(line_process[1]) - if 'Router' in model: - model = re.split(' ', model)[0] + if "Router" in model: + model = re.split(" ", model)[0] # get serial_number,due to the stack have multiple SN, so show it in a list # 由于堆叠设备会有多少个SN,所以这里用列表展示 serial_number = [] for line in show_esn.splitlines(): - serial_number.append(re.split(':', line)[1].lstrip().rstrip()) + serial_number.append(re.split(":", line)[1].lstrip().rstrip()) if "sysname " in show_hostname: _, hostname = show_hostname.split("sysname ") @@ -626,7 +626,7 @@ def get_interfaces(self): msg = "Unexpected interface format: {}".format(interface) raise ValueError(msg) intf_name = match_intf.group("intf_name") - if intf_name == 'Dialer1:0': + if intf_name == "Dialer1:0": continue intf_state = match_intf.group("intf_state") is_enabled = bool("up" in intf_state.lower()) @@ -653,12 +653,12 @@ def get_interfaces(self): speed = match_speed.group("speed") if speed.isdigit(): speed = float(speed) + match_speed_eth_ar = re.findall(re_speed_eth_ar, interface, flags=re.M) - if match_speed_eth_ar: if match_speed_eth_ar[0].isdigit(): speed = float(match_speed_eth_ar[0]) * 1000 - + match_speed_eth_ce = re.findall(re_speed_eth_ce, interface, flags=re.M) if match_speed_eth_ce: if match_speed_eth_ce[0].isdigit(): @@ -742,10 +742,10 @@ def get_interfaces_ip(self): # v4_interfaces[intf_name] = {} match_ip = re.findall(re_intf_ip, interface, flags=re.M) - if len(match_ip) == 0: + if not match_ip: re_intf_ip = r"Internet Address is negotiated,\s+(?P\d+.\d+.\d+.\d+)\/(?P\d+)" match_ip = re.findall(re_intf_ip, interface, flags=re.M) - if len(match_ip) == 0: + if not match_ip: re_intf_ip = r"Internet Address is allocated by DHCP,\s+(?P\d+.\d+.\d+.\d+)\/(?P\d+)" match_ip = re.findall(re_intf_ip, interface, flags=re.M)