Files
napalm-tplink-jetstream/napalm_tplink_jetstream/parsers.py
T
Christian Manivong 8e7be0e47e
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 59s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 50s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m26s
driver / publish (pull_request) Skipped
fix(snmp): read the community from the Name column
The switch's community table starts with an Index column, and
get_snmp_config took a row's first word, so it reported the community
as "1". The name now comes from the column headed Name, found in the
header line above the dashes; the tests read the recorded table.

Found while recording fixtures for #3.
2026-11-01 22:19:33 +01:00

30 lines
927 B
Python

"""Pure parsers: the switch's CLI output in, plain values out."""
from __future__ import annotations
import re
_DASHES = re.compile(r"^-{4,}$")
def parse_snmp_communities(output: str) -> list[str]:
"""The community names in ``show snmp-server community``, in the switch's order.
The table starts with an ``Index`` column: the name is the column headed
``Name``, found in the header line above the dashes. Without one, no name.
"""
names: list[str] = []
header: list[str] = []
column: int | None = None
for line in output.splitlines():
words = line.split()
if not words:
continue
if column is None:
if _DASHES.match(words[0]):
column = next((i for i, w in enumerate(header) if "name" in w.lower()), -1)
header = words
elif 0 <= column < len(words):
names.append(words[column])
return names