mirror of
https://github.com/hansjone/netx.git
synced 2026-10-17 04:33:16 +08:00
Reorganize biz-state parsers by vendor folder and per-command modules.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
da6b159703
commit
d587bf7bb9
14 changed files with 473 additions and 434 deletions
56
netx_api/biz_state/parsers/zte/isis_adjacency.py
Normal file
56
netx_api/biz_state/parsers/zte/isis_adjacency.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"""ZTE: show isis adjacency [| one-line]."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
_ISIS_ROW_RE = re.compile(
|
||||
r"^(?P<iface>\S+)\s+(?P<sys>\S+)\s+(?P<state>\S+)\s+(?P<lev>\S+)\s+"
|
||||
r"(?P<holds>\S+)\s+(?P<snpa>\S+)\s+(?P<pri>\S+)\s+(?P<mt>\S+)\s+"
|
||||
r"(?P<nsf>\S+)\s+(?P<af>\S+)\s*$",
|
||||
re.I,
|
||||
)
|
||||
_PROCESS_RE = re.compile(r"(?i)^\s*Process\s+ID\s*:\s*(\d+)\s*$")
|
||||
|
||||
|
||||
def normalize_isis_adjacency(
|
||||
*,
|
||||
raw_text: str,
|
||||
vendor: str = "",
|
||||
device_type: str = "",
|
||||
command: str = "",
|
||||
params: dict[str, str] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
_ = (vendor, device_type, command, params)
|
||||
out: list[dict[str, Any]] = []
|
||||
process_id = ""
|
||||
for raw in str(raw_text or "").splitlines():
|
||||
line = raw.strip()
|
||||
if not line:
|
||||
continue
|
||||
pm = _PROCESS_RE.match(line)
|
||||
if pm:
|
||||
process_id = pm.group(1)
|
||||
continue
|
||||
if line.lower().startswith("interface") and "system" in line.lower():
|
||||
continue
|
||||
m = _ISIS_ROW_RE.match(line)
|
||||
if not m:
|
||||
continue
|
||||
out.append(
|
||||
{
|
||||
"process_id": process_id,
|
||||
"interface": m.group("iface")[:128],
|
||||
"system_id": m.group("sys")[:128],
|
||||
"state": m.group("state")[:32],
|
||||
"lev": m.group("lev")[:16],
|
||||
"holds": m.group("holds")[:32],
|
||||
"snpa": m.group("snpa")[:64],
|
||||
"pri": m.group("pri")[:16],
|
||||
"mt": m.group("mt")[:16],
|
||||
"nsf": m.group("nsf")[:32],
|
||||
"af": m.group("af")[:64],
|
||||
}
|
||||
)
|
||||
return out
|
||||
Loading…
Add table
Add a link
Reference in a new issue