run_device_action: one dispatcher, and the contract the drivers actually follow #14

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

Every driver writes run_device_action as an if-chain over _action_<name>:

  • Several actions: napalm_openwrt/openwrt.py:343, napalm_proxmox/system_mixin.py:472, napalm_linux/linux.py:2196.
  • fix_snmp only, byte-identical: netgear, tplink, procurve and opnsense.

Contract drift

  • Unknown action. os.py:299–301 documents ValueError, but every driver raises NotImplementedError (e.g. openwrt.py:353). NetOrk maps NotImplementedError to "not supported".
  • Result shape. sonos_driver.py:445 and zyxel_driver.py:813 return {"success", "action", "message"} instead of DeviceActionResultDict {"success", "output"} (models.py:824). NetOrk reads output (netork/api/v1/routers/devices/actions/_snmp.py:97).

Proposal

  • A DeviceActionsMixin with DEVICE_ACTIONS: ClassVar[frozenset[str]] as an allowlist (so private methods are not reachable by name), and a concrete dispatcher.
  • Decide which exception means "unknown action" and make the docstring say it.
  • Bring sonos and zyxel to the documented result shape.

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.

Every driver writes `run_device_action` as an if-chain over `_action_<name>`: - **Several actions:** `napalm_openwrt/openwrt.py`:343, `napalm_proxmox/system_mixin.py`:472, `napalm_linux/linux.py`:2196. - **fix_snmp only, byte-identical:** netgear, tplink, procurve and opnsense. **Contract drift** - **Unknown action.** `os.py`:299–301 documents `ValueError`, but every driver raises `NotImplementedError` (e.g. `openwrt.py`:353). NetOrk maps `NotImplementedError` to "not supported". - **Result shape.** `sonos_driver.py`:445 and `zyxel_driver.py`:813 return `{"success", "action", "message"}` instead of `DeviceActionResultDict` `{"success", "output"}` (`models.py`:824). NetOrk reads `output` (`netork/api/v1/routers/devices/actions/_snmp.py`:97). **Proposal** - A `DeviceActionsMixin` with `DEVICE_ACTIONS: ClassVar[frozenset[str]]` as an allowlist (so private methods are not reachable by name), and a concrete dispatcher. - Decide which exception means "unknown action" and make the docstring say it. - Bring sonos and zyxel to the documented result shape. 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): replaced by the fix templates in #33, which deprecate run_device_action.

Re-homed by `docs/STRUCTURE.md` (NAPALM/napalm-device-types#37, NetOrk/netork#1105): replaced by the fix templates in #33, which deprecate `run_device_action`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-device-types#14