pure CLI text helpers: uptime, port ranges, key/value lookup, port sort, route table, LAG rows #11

Open
opened 2026-10-06 17:31:30 +00:00 by christianmanivong · 1 comment
Owner

Small parsers copied between drivers.

Uptime text

  • Copies: netgear_smart.py:277 and tplink_jetstream.py:253 (same shape), and procurve/parsers.py:147.
  • The hour regexes differ.
  • Unknown input returns 0.0 in these, while hpe_officeconnect/parsers.py:96 returns -1, NAPALM's "unknown".

Port-list range expansion

  • Copies: netgear_smart.py:1251 and :343 (v7), tplink_jetstream.py:862, procurve/parsers.py:711.
  • tplink's inner loop duplicates its own _expand_ports (:892).

Key/value lookup

  • Copies: netgear_smart.py:258, tplink_jetstream.py:237, procurve/parsers.py:27.
  • In all three, "Name" also matches "System Name".

Natural port sort

  • re.split(r"(\d+)") is copied five times.
  • napalm_device_types/lag.py:16 _port_order already does it, but it is private.

IOS route table

  • Copies: netgear_smart.py:1695 and tplink_jetstream.py:1486. tplink's is a superset: more protocols, plus the outgoing interface.

LAG rows

  • procurve uses lag.py add_lag_interfaces.
  • tplink (tplink_jetstream.py:411) and netgear v7 (netgear_smart.py:679) build the rows by hand.
  • The base leaves an already-reported LAG row untouched, while the drivers annotate existing rows. It needs that option.

ARP from hosts

  • get_arp_table built from get_hosts() is identical in napalm_fritzbox/fritzbox.py:431 and napalm_zyxel/zyxel_driver.py:330.
  • This could be an arp_table_from_hosts() in residential_gateway.py.

Proposal: pure functions in napalm-device-types: parse_duration_text (returns -1.0 on no match), expand_port_ranges, kv_lookup, public port_sort_key, parse_ios_route_table, an annotate option in add_lag_interfaces, and arp_table_from_hosts. Each with fixtures from both dialects.

Prio P4.

From the NetOrk function index (NetOrk/netork#670); every location was checked against the current code. Paths are relative to each driver repo.

Small parsers copied between drivers. **Uptime text** - Copies: `netgear_smart.py`:277 and `tplink_jetstream.py`:253 (same shape), and `procurve/parsers.py`:147. - The hour regexes differ. - Unknown input returns 0.0 in these, while `hpe_officeconnect/parsers.py`:96 returns -1, NAPALM's "unknown". **Port-list range expansion** - Copies: `netgear_smart.py`:1251 and :343 (v7), `tplink_jetstream.py`:862, `procurve/parsers.py`:711. - tplink's inner loop duplicates its own `_expand_ports` (:892). **Key/value lookup** - Copies: `netgear_smart.py`:258, `tplink_jetstream.py`:237, `procurve/parsers.py`:27. - In all three, "Name" also matches "System Name". **Natural port sort** - `re.split(r"(\d+)")` is copied five times. - `napalm_device_types/lag.py`:16 `_port_order` already does it, but it is private. **IOS route table** - Copies: `netgear_smart.py`:1695 and `tplink_jetstream.py`:1486. tplink's is a superset: more protocols, plus the outgoing interface. **LAG rows** - procurve uses `lag.py` `add_lag_interfaces`. - tplink (`tplink_jetstream.py`:411) and netgear v7 (`netgear_smart.py`:679) build the rows by hand. - The base leaves an already-reported LAG row untouched, while the drivers annotate existing rows. It needs that option. **ARP from hosts** - `get_arp_table` built from `get_hosts()` is identical in `napalm_fritzbox/fritzbox.py`:431 and `napalm_zyxel/zyxel_driver.py`:330. - This could be an `arp_table_from_hosts()` in `residential_gateway.py`. **Proposal:** pure functions in napalm-device-types: `parse_duration_text` (returns -1.0 on no match), `expand_port_ranges`, `kv_lookup`, public `port_sort_key`, `parse_ios_route_table`, an annotate option in `add_lag_interfaces`, and `arp_table_from_hosts`. Each with fixtures from both dialects. Prio P4. From the NetOrk function index (NetOrk/netork#670); every location was checked against the current code. Paths are relative to each driver repo.
Author
Owner

Re-homed by docs/STRUCTURE.md (NAPALM/napalm-device-types#37, NetOrk/netork#1105): CLI text parsers do not go here. The natural port sort that lag already has may become public.

Re-homed by `docs/STRUCTURE.md` (NAPALM/napalm-device-types#37, NetOrk/netork#1105): CLI text parsers do not go here. The natural port sort that `lag` already has may become public.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-device-types#11