From 40b2144c1b94d863d59f15b9667ca6906af002fe Mon Sep 17 00:00:00 2001 From: hgaliza Date: Sat, 15 Jun 2024 12:23:39 +0100 Subject: [PATCH] chore: fixing get_interfaces() to support interfaces without line protocol row --- napalm_huawei_vrp/huawei_vrp.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/napalm_huawei_vrp/huawei_vrp.py b/napalm_huawei_vrp/huawei_vrp.py index fc8fc80..06001c7 100644 --- a/napalm_huawei_vrp/huawei_vrp.py +++ b/napalm_huawei_vrp/huawei_vrp.py @@ -311,7 +311,7 @@ def get_environment(self): # 定义执行命令 fan_cmd = "display fan" """ - Slot FanID Online Status Speed Mode Airflow + Slot FanID Online Status Speed Mode Airflow ------------------------------------------------------------------------- 0 1 Present Normal 55% Auto Side-to-Back 1 1 Present Normal 55% Auto Side-to-Back @@ -321,10 +321,10 @@ def get_environment(self): ------------------------------------------------------------ Slot PowerID Online Mode State Power(W) ------------------------------------------------------------ - 0 PWR1 Present AC Supply 600.00 - 0 PWR2 Present AC Supply 600.00 - 1 PWR1 Present AC Supply 600.00 - 1 PWR2 Present AC Supply 600.00 + 0 PWR1 Present AC Supply 600.00 + 0 PWR2 Present AC Supply 600.00 + 1 PWR1 Present AC Supply 600.00 + 1 PWR2 Present AC Supply 600.00 """ temp_cmd = "display temperature all" """ @@ -339,7 +339,7 @@ def get_environment(self): """ CPU Usage Stat. Cycle: 60 (Second) CPU Usage : 28% Max: 87% - CPU Usage Stat. Time : 2022-01-13 18:57:06 + CPU Usage Stat. Time : 2022-01-13 18:57:06 CPU utilization for five seconds: 28%: one minute: 28%: five minutes: 20% Max CPU Usage Stat. Time : 2021-10-05 17:50:44. """ @@ -618,15 +618,17 @@ def get_interfaces(self): match_intf = re.search(re_intf_name_state, interface, flags=re.M) match_proto = re.search(re_protocol, interface, flags=re.M) - if match_intf is None or match_proto is None: + if match_intf is None: msg = "Unexpected interface format: {}".format(interface) raise ValueError(msg) intf_name = match_intf.group("intf_name") intf_state = match_intf.group("intf_state") is_enabled = bool("up" in intf_state.lower()) - protocol = match_proto.group("protocol") - is_up = bool("up" in protocol.lower()) + is_up = False + if match_proto: + protocol = match_proto.group("protocol") + is_up = bool("up" in protocol.lower()) match_mac = re.search(re_mac, interface, flags=re.M) if match_mac: