diff --git a/README.md b/README.md index ea55c64..63f6630 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Looking forward to your testing and feedback :). - :white_check_mark: get_facts() - :white_check_mark: get_interfaces() - :white_check_mark: get_interfaces_ip() -- :white_check_mark: get_interfaces_counters() +- ~~:white_check_mark: get_interfaces_counters():x:needs to be rewritten~~ - :white_check_mark: get_lldp_neighbors() - :white_check_mark: get_lldp_neighbors_detail() - :white_check_mark: get_environment() diff --git a/README_CN.md b/README_CN.md index 0a5e774..4640d38 100644 --- a/README_CN.md +++ b/README_CN.md @@ -30,7 +30,7 @@ - :white_check_mark: get_facts():获取设备基础信息,如型号、软件版本、序列号等 - :white_check_mark: get_interfaces():获取所有接口列表 - :white_check_mark: get_interfaces_ip():获取当前存在 IP 地址的接口列表,目前只支持 IPv4 -- :white_check_mark: get_interfaces_counters():获取接口的计数信息,包括收发包、收发字节、错包、丢包、CRC 等 +- ~~:white_check_mark: get_interfaces_counters():获取接口的计数信息,包括收发包、收发字节、错包、丢包、CRC 等:x:需要重写~~ - :white_check_mark: get_lldp_neighbors():获取 LLDP 邻居信息 - :white_check_mark: get_lldp_neighbors_detail():获取 LLDP 的详细信息,包括对端的系统名称及描述、接口名称及描述等 - :white_check_mark: get_environment():获取设备运行信息,包括 CPU、内存、电源、风扇、温度等状态 diff --git a/napalm_h3c_comware/__init__.py b/napalm_h3c_comware/__init__.py index d667d00..e1f432a 100644 --- a/napalm_h3c_comware/__init__.py +++ b/napalm_h3c_comware/__init__.py @@ -15,4 +15,4 @@ from napalm_h3c_comware.comware import ComwareDriver __all__ = ("ComwareDriver",) -__version__ = "0.1.4" \ No newline at end of file +__version__ = "0.1.5" \ No newline at end of file diff --git a/napalm_h3c_comware/comware.py b/napalm_h3c_comware/comware.py index cad2a79..0580894 100644 --- a/napalm_h3c_comware/comware.py +++ b/napalm_h3c_comware/comware.py @@ -369,34 +369,36 @@ def get_environment(self): return environment - def get_interfaces_counters(self): - counters = {} - keys = ( - "tx_errors", "rx_errors", "rx_crc", - "tx_discards", "rx_discards", - "tx_octets", "rx_octets", - "tx_packets", "rx_packets", - "tx_unicast_packets", "rx_unicast_packets", - "tx_multicast_packets", "rx_multicast_packets", - "tx_broadcast_packets", "rx_broadcast_packets", - ) - structured_int_info = self._get_structured_output("display interface") - - for interface in structured_int_info: - values = itemgetter( - "tx_errors", "rx_errors", "rx_crc", - "tx_aborts", "rx_aborts", - "tx_bytes", "rx_bytes", - "tx_pkts", "rx_pkts", - "tx_unicast", "rx_unicast", - "tx_multicast", "rx_multicast", - "tx_broadcast", "rx_broadcast", - )(interface) - - values = (parse_null(value, -1, int) for value in values) - counters[interface.get("interface")] = dict(zip(keys, values)) - - return counters + # TODO: 从 textfsm 的 display interface 模板中移除,模板无法支持太多类型的输出,重构为正则表达式比较好 + + # def get_interfaces_counters(self): + # counters = {} + # keys = ( + # "tx_errors", "rx_errors", "rx_crc", + # "tx_discards", "rx_discards", + # "tx_octets", "rx_octets", + # "tx_packets", "rx_packets", + # "tx_unicast_packets", "rx_unicast_packets", + # "tx_multicast_packets", "rx_multicast_packets", + # "tx_broadcast_packets", "rx_broadcast_packets", + # ) + # structured_int_info = self._get_structured_output("display interface") + + # for interface in structured_int_info: + # values = itemgetter( + # "tx_errors", "rx_errors", "rx_crc", + # "tx_aborts", "rx_aborts", + # "tx_bytes", "rx_bytes", + # "tx_pkts", "rx_pkts", + # "tx_unicast", "rx_unicast", + # "tx_multicast", "rx_multicast", + # "tx_broadcast", "rx_broadcast", + # )(interface) + + # values = (parse_null(value, -1, int) for value in values) + # counters[interface.get("interface")] = dict(zip(keys, values)) + + # return counters def get_lldp_neighbors_detail(self, interface: str = ""): lldp = {} diff --git a/napalm_h3c_comware/utils/textfsm_templates/display_interface.tpl b/napalm_h3c_comware/utils/textfsm_templates/display_interface.tpl index ed4a14e..12f39f3 100644 --- a/napalm_h3c_comware/utils/textfsm_templates/display_interface.tpl +++ b/napalm_h3c_comware/utils/textfsm_templates/display_interface.tpl @@ -13,26 +13,10 @@ Value PVID (\d+) Value LINK_TYPE (\S+) Value LAST_FLAPPING (.+) Value PRIMARY_IPADDR (\d+\.\d+\.\d+\.\d+/\d+) -Value RX_PKTS (\d+|-) -Value RX_BYTES (\d+|-) -Value RX_UNICAST (\d+|-) -Value RX_BROADCAST (\d+|-) -Value RX_MULTICAST (\d+|-) -Value RX_ERRORS (\d+|-) -Value RX_ABORTS (\d+|-) -Value RX_CRC (\d+|-) -Value TX_PKTS (\d+|-) -Value TX_BYTES (\d+|-) -Value TX_UNICAST (\d+|-) -Value TX_BROADCAST (\d+|-) -Value TX_MULTICAST (\d+|-) -Value TX_ERRORS (\d+|-) -Value TX_ABORTS (\d+|-) Start # 接口名所在行是一个独立的字符串,以此开始记录 ^\S+\s*$$ -> Continue.Record - # 路由器某个 Serial 接口后面出现了空格,莫名奇妙的 comware bug ^${INTERFACE}\s*$$ ^(C|c)urrent\s+state:\s+${LINK_STATUS} ^(L|l)ine\s+protocol\s+state:\s+${PROTOCOL_STATUS} @@ -46,26 +30,4 @@ Start ^PVID:\s+${PVID} ^Port\s+link-type:\s+${LINK_TYPE} ^Last\s+link\s+flapping:\s+${LAST_FLAPPING} - # 如果接口不存在计数信息(例如 Serial),直接开始匹配下一个接口 - ^\s*$$ -> Start - # 虚拟接口计数匹配 - ^\s?Input:\s*${RX_PKTS}\s+packets,\s+${RX_BYTES}\s+bytes(,\s+\d+\s+buffers)?(,\s+${RX_ABORTS}\s+drops)? - ^\s?Output:\s*${TX_PKTS}\s+packets,\s+${TX_BYTES}\s+bytes(,\s+\d+\s+buffers)?(,\s+${TX_ABORTS}\s+drops)? -> Start - # 物理接口计数匹配 - ^\s*Input\s+\(total\) -> INPUT - - - -# for physical interfaces -INPUT - ^\s*Input\s+\(normal\):\s+${RX_PKTS}\s+packets,\s+${RX_BYTES}\s+bytes - ^\s*${RX_UNICAST}\s+unicasts,\s+${RX_BROADCAST}\s+broadcasts,\s+${RX_MULTICAST}\s+multicasts,\s+\d+\s+pauses - ^\s*Input:\s+${RX_ERRORS}\s+input\s+errors, - ^\s*${RX_CRC}\s+CRC,\s+\d+\s+frame,\s+\d+\s+overruns,\s+${RX_ABORTS}\s+aborts -> OUTPUT - -# for physical interfaces -OUTPUT - ^\s*Output\s+\(normal\):\s+${TX_PKTS}\s+packets,\s+${TX_BYTES}\s+bytes - ^\s*${TX_UNICAST}\s+unicasts,\s+${TX_BROADCAST}\s+broadcasts,\s+${TX_MULTICAST}\s+multicasts,\s+\d+\s+pauses - ^\s*Output:\s+${TX_ERRORS}\s+output\s+errors, - ^\s*${TX_ABORTS}\s+aborts,\s+\d+\s+deferred, -> Start \ No newline at end of file + ^\s*$$ \ No newline at end of file