feat(updates): the update history before PVE 9.3 from apt's log over SSH (NetOrk/netork#2728)
Below 9.3 get_update_history reads apt's history log over the node's SSH session
with napalm-device-types' AptHistoryMixin, which names a transaction as
GET /nodes/{node}/apt/history does, so the ids stay when the node moves to 9.3.
A node without an SSH login still raises NotImplementedError. Requires
napalm-device-types 4.47.0.
This commit is contained in:
1 parent
dc0d6345a8
commit
707b24748b
5 files changed
+123
-17
No files matched your search
@@ -4,15 +4,23 @@ PVE 9.3 reads apt's history log for ``GET /nodes/{node}/apt/history``, newest
|
||||
first, also the transactions netOrk did not start (an operator's ``apt``,
|
||||
unattended-upgrades). A transaction is named by its ``start-time`` and its
|
||||
``start-index`` among those that started in the same second of the same log
|
||||
file. An older node has no such endpoint: the driver raises
|
||||
``NotImplementedError`` and parses no log over SSH.
|
||||
file. An older node has no such endpoint: the driver reads the same log over
|
||||
its SSH session with napalm-device-types' ``AptHistoryMixin``, which names a
|
||||
transaction the same way, so the ids stay when the node moves to 9.3. A node
|
||||
without an SSH login raises ``NotImplementedError`` there.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from napalm_device_types import UpdateHistoryAction, UpdateHistoryDict, UpdateHistoryPackageDict
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
from napalm_device_types import (
|
||||
AptHistoryMixin,
|
||||
UpdateHistoryAction,
|
||||
UpdateHistoryDict,
|
||||
UpdateHistoryPackageDict,
|
||||
)
|
||||
|
||||
from napalm_proxmox.pve_values import PVE_9_3
|
||||
|
||||
@@ -46,8 +54,9 @@ def _transaction(row: _JsonDict) -> UpdateHistoryDict:
|
||||
}
|
||||
|
||||
|
||||
class ProxmoxUpdateHistoryMixin:
|
||||
"""Relies on the driver's ``_node_api`` and ``_version_at_least``."""
|
||||
class ProxmoxUpdateHistoryMixin(AptHistoryMixin):
|
||||
"""Relies on the driver's ``_node_api``, ``_version_at_least``, ``_has_ssh_login``
|
||||
and ``run_command``."""
|
||||
|
||||
_node_name: str
|
||||
|
||||
@@ -55,21 +64,31 @@ class ProxmoxUpdateHistoryMixin:
|
||||
|
||||
def _node_api(self) -> Any: ...
|
||||
def _version_at_least(self, major: int, minor: int) -> bool: ...
|
||||
def _has_ssh_login(self) -> bool: ...
|
||||
|
||||
def get_update_history(self, since: int | None = None) -> list[UpdateHistoryDict]:
|
||||
"""The node's APT transactions, newest first, from ``since`` (unix seconds) on.
|
||||
|
||||
:raises NotImplementedError: before PVE 9.3, which has no history endpoint.
|
||||
:raises NotImplementedError: before PVE 9.3 on a node without an SSH login.
|
||||
:raises RuntimeError: the history could not be read; never an empty list.
|
||||
"""
|
||||
if not self._version_at_least(*PVE_9_3):
|
||||
raise NotImplementedError(
|
||||
f"Proxmox VE on {self._node_name} keeps no APT history its API reports "
|
||||
"(from 9.3 on)"
|
||||
)
|
||||
return self._history_over_ssh(since)
|
||||
params = {} if since is None else {"since": since}
|
||||
try:
|
||||
rows = self._node_api().apt.history.get(**params) or []
|
||||
except Exception as exc:
|
||||
raise RuntimeError(f"Cannot read the APT history of {self._node_name}: {exc}") from exc
|
||||
return [_transaction(row) for row in rows]
|
||||
|
||||
def _history_over_ssh(self, since: int | None) -> list[UpdateHistoryDict]:
|
||||
"""Before 9.3: apt's log over the SSH session, root's login."""
|
||||
if not self._has_ssh_login():
|
||||
raise NotImplementedError(
|
||||
f"Proxmox VE on {self._node_name} reports its APT history from 9.3 on; "
|
||||
"before that it is read over SSH, and the node has no SSH login"
|
||||
)
|
||||
try:
|
||||
return super().get_update_history(since)
|
||||
except (ConnectionException, ValueError) as exc:
|
||||
raise RuntimeError(f"Cannot read the APT history of {self._node_name}: {exc}") from exc
|
||||
Reference in new issue
Block a user