feat: start, stop, restart, enable and disable services, and list them in one round trip #9

Merged
christianmanivong merged 1 commits from feat/manage-service into master 2026-10-05 11:12:14 +00:00
Owner

Closes #7. Builds on NAPALM/napalm-device-types#5 (2.2.0, SystemdServicesMixin).

get_services() and manage_service() now come from the shared mixin, and this driver only carries the commands. Root logins run commands directly. With a sudo password, commands go through _sudo(). Without one, they use sudo -n, which fails at once instead of waiting 100 s for a prompt. The commit message has the details.

Checked against real hosts (netOrk test server)

The new driver code was loaded into the engine container and used live:

Host get_services() before now manage_service("<missing unit>", "restart")
Ubuntu 24.04 (LinuxDriver) 6.0 s 0.8 s 0.06 s, failure carrying systemctl's message
Debian 13 (LinuxDriver) 11.5 s 3.9 s 0.14 s, likewise
OpenMediaVault (inherits) 5.5 s 1.7 s 0.05 s, likewise

On every host the running state matches the old reader exactly.

Tests (no CI in this repo, run locally)

$ PYTHONPATH=.:../napalm-device-types pytest -q tests
99 passed

ruff and mypy report nothing that master does not already report. The file was not reformatted wholesale, because master isn't formatted either.

Closes #7. Builds on NAPALM/napalm-device-types#5 (2.2.0, `SystemdServicesMixin`). `get_services()` and `manage_service()` now come from the shared mixin, and this driver only carries the commands. Root logins run commands directly. With a sudo password, commands go through `_sudo()`. Without one, they use `sudo -n`, which fails at once instead of waiting 100 s for a prompt. The commit message has the details. ## Checked against real hosts (netOrk test server) The new driver code was loaded into the engine container and used live: | Host | `get_services()` before | now | `manage_service("<missing unit>", "restart")` | |---|---|---|---| | Ubuntu 24.04 (LinuxDriver) | 6.0 s | 0.8 s | 0.06 s, failure carrying systemctl's message | | Debian 13 (LinuxDriver) | 11.5 s | 3.9 s | 0.14 s, likewise | | OpenMediaVault (inherits) | 5.5 s | 1.7 s | 0.05 s, likewise | On every host the running state matches the old reader exactly. ## Tests (no CI in this repo, run locally) ``` $ PYTHONPATH=.:../napalm-device-types pytest -q tests 99 passed ``` ruff and mypy report nothing that `master` does not already report. The file was not reformatted wholesale, because `master` isn't formatted either.
christianmanivong added 1 commit 2026-10-05 11:12:14 +00:00
napalm-device-types' SystemdServicesMixin (2.2.0) now provides get_services()
and manage_service(); this driver supplies only the transport (#7):

- _run_service_command(): unprivileged reads and root logins run as they
  are -- the user is asked once per session with "id -u", so a root login on a
  box without sudo is not prefixed with one. With a sudo password the command
  goes through _sudo(); without one through "sudo -n", which fails at once
  instead of hanging the session on a password prompt until the read timeout.
- get_services(): one round trip instead of an is-enabled and a show per unit
  (6.0 s -> 0.8 s on a 184-unit Ubuntu host). A host without systemd still
  falls back to "service --status-all".
- manage_service(): when sudo wants a password netOrk does not have, the
  failure says how to fix it -- the same hint the apt and SNMP actions give,
  now one constant (_SUDO_PASSWORD_HINT) instead of two copies.

OpenMediaVault and QNAP inherit this driver. OMV gets service control with
it; QNAP opts out (napalm-qnap-qts), since QTS has no systemd.

README: the sudo option is sudo_password, not secret; manage_service and the
systemctl permissions are listed.

Closes #7
christianmanivong merged commit e31bc2a3bf into master 2026-10-05 11:12:14 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#9