Compare commits

...
2 Commits
Author SHA1 Message Date
christianmanivong ab1cac3833 Merge pull request 'feat(logins): get_login_sessions on PVE and PBS, 0.21.0 (NetOrk/netork#2881)' (#83) from feature/login-sessions into main
driver / lowest (push) Successful in 34s
driver / standard (push) Successful in 19s
driver / lint (push) Successful in 13s
driver / types (push) Successful in 1m7s
driver / test (3.12) (push) Successful in 1m12s
driver / test (3.13) (push) Successful in 1m14s
driver / build (push) Successful in 30s
driver / security (push) Successful in 1m5s
driver / publish (push) Successful in 30s
CI / driver (push) Successful in 2m49s
2026-12-01 09:32:59 +00:00
Christian Manivong 3d661e0b3f feat(logins): get_login_sessions on PVE and PBS, 0.21.0 (NetOrk/netork#2881)
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 17s
driver / lowest (pull_request) Successful in 41s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / test (3.13) (pull_request) Successful in 58s
driver / types (pull_request) Successful in 1m13s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 1m18s
CI / driver (pull_request) Successful in 2m18s
driver / publish (pull_request) Skipped
napalm-device-types' LoginSessionsMixin over the node's exec path: the
interactive logins the node recorded, someone's own ssh or the web
interface's shell, with the driver's own SSH client address.
2026-12-01 09:41:28 +01:00
6 changed files with 85 additions and 2 deletions

No files matched your search

+10
View File
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.21.0] - 2026-12-01
### Added
- `get_login_sessions()` on PVE and PBS (napalm-device-types' `LoginSessionsMixin`,
4.55.0): the interactive logins the node recorded over the last seven days -- someone's
own `ssh`, or the web interface's shell -- each with its account, terminal, address and
times, and the address of the driver's own SSH session (NetOrk/netork#2881). Over the
node's exec path; an API-token-only node, which has no SSH login, raises as the other
readings over SSH do.
## [0.20.0] - 2026-11-29
### Added
+2
View File
@@ -25,6 +25,7 @@ from napalm_device_types import (
KernelFactsMixin,
LicenseMixin,
ListeningSocketsMixin,
LoginSessionsMixin,
LogSourcesMixin,
OpenSshServerMixin,
PortSpec,
@@ -73,6 +74,7 @@ class ProxmoxBackupDriver(
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
LoginSessionsMixin,
ServicesRestartMixin,
SystemIdentityMixin,
SystemdServicesMixin,
+2
View File
@@ -37,6 +37,7 @@ from napalm_device_types import (
KernelFactsMixin,
LicenseMixin,
ListeningSocketsMixin,
LoginSessionsMixin,
LogSourcesMixin,
OpenSshServerMixin,
PortSpec,
@@ -110,6 +111,7 @@ class ProxmoxDriver(
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
LoginSessionsMixin,
ServicesRestartMixin,
SystemIdentityMixin,
SystemdServicesMixin,
+6
View File
@@ -98,6 +98,12 @@ class ProxmoxHostMixin:
the exec path, which runs as root either way."""
return str(self._exec_ssh_command(command))
def _run_login_sessions_command(self, command: str) -> str:
"""The transport for ``LoginSessionsMixin.get_login_sessions`` (NetOrk/netork#2881):
the exec path, where ``SSH_CONNECTION`` names this driver's own address. wtmp is
readable to every login. No stdin."""
return str(self._exec_ssh_command(command))
def _run_log_sources_command(self, command: str, *, privileged: bool) -> str:
"""The transport for ``LogSourcesMixin.get_log_sources``: the exec path,
which runs as root either way."""
+2 -2
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-proxmox"
version = "0.20.0"
version = "0.21.0"
description = "NAPALM drivers for Proxmox VE (classic Linux networking, SDN, OVS) and Proxmox Backup Server"
readme = "README.md"
license = "Apache-2.0"
@@ -21,7 +21,7 @@ classifiers = [
requires-python = ">=3.12"
dependencies = [
"napalm>=5.0.0",
"napalm_device_types>=4.53.0", # CpuMicrocodeMixin, virtualization in the hardening; WebLoginAuthDict
"napalm_device_types>=4.55.0", # LoginSessionsMixin
"paramiko>=5.0.0", # CVE-2026-44405; imported directly for the node's SSH session (_base.py)
"proxmoxer>=2.0.0",
"netaddr>=0.9.0",
+63
View File
@@ -0,0 +1,63 @@
"""`get_login_sessions`: the interactive logins a node recorded (NetOrk/netork#2881).
A shell on a node that did not go through the application -- someone's own ``ssh``, or
the web interface's shell -- is in the node's wtmp. The command and its parse are
napalm-device-types' (``LoginSessionsMixin``); both drivers carry the command over their
own exec path, where ``SSH_CONNECTION`` names the driver's own address.
"""
from __future__ import annotations
from unittest.mock import patch
import pytest
from napalm_device_types import LoginSessionsMixin, LoginSessionsUnavailable
from napalm_proxmox.backup_driver import ProxmoxBackupDriver
from napalm_proxmox.driver import ProxmoxDriver
WIRE = "\n".join(
[
"LOGSESSIONS_BEGIN",
"[own]",
"198.51.100.2",
"[now]",
"2026-11-30T12:00:00Z",
"[wtmp since]",
"root pts/0 192.0.2.10 2026-11-30T10:15:02+01:00 still logged in",
"root pts/1 0.0.0.0 2026-11-29T09:00:00+01:00 - 2026-11-29T09:30:00+01:00 (00:30)",
"LOGSESSIONS_END",
]
)
@pytest.mark.parametrize("cls", [ProxmoxDriver, ProxmoxBackupDriver])
def test_both_drivers_declare_the_contract(cls):
assert issubclass(cls, LoginSessionsMixin)
assert hasattr(cls, "get_login_sessions")
def test_the_node_runs_the_shared_command_over_its_exec_path(driver):
with patch.object(driver, "_exec_ssh_command", return_value=WIRE) as exec_:
reading = driver.get_login_sessions()
exec_.assert_called_once()
assert exec_.call_args.args[0].startswith("sh -c ")
assert reading["own_address"] == "198.51.100.2"
assert [s["address"] for s in reading["sessions"]] == ["192.0.2.10", None]
def test_the_backup_server_reads_it_the_same_way():
drv = ProxmoxBackupDriver("192.0.2.80", "root", "", optional_args={"token_name": "a!b"})
with patch.object(drv, "_exec_ssh_command", return_value=WIRE):
reading = drv.get_login_sessions()
assert reading["sessions"][0]["user"] == "root"
def test_a_node_without_login_records_raises(driver):
empty = "LOGSESSIONS_BEGIN\n[own]\n\n[now]\n2026-11-30T12:00:00Z\nLOGSESSIONS_END"
with patch.object(driver, "_exec_ssh_command", return_value=empty):
with pytest.raises(LoginSessionsUnavailable):
driver.get_login_sessions()