feat(config): list, read and revert the firewall's config revisions
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 17s
driver / types (pull_request) Successful in 57s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / test (3.12) (pull_request) Successful in 1m10s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Successful in 2m25s
driver / publish (pull_request) Skipped

OPNsense has no API that takes an uploaded config.xml: the backup API
lists the history in /conf/backup, hands out a revision and reverts to
one that is already on the firewall. A full replace exists only on the
legacy page diag_backup.php. So an application restores a configuration
by reverting to the revision that holds it (NetOrk/netork#2511).

get_config_revisions() lists the history newest first: id, time in UTC
(time_iso is in the firewall's zone), description, user and size.
get_config_revision(id) returns one revision's config.xml.
revert_config_revision(id) calls revert_backup and refuses an id that is
not in the history now; an id that is no file name of the history never
reaches a request path. A revert only saves config.xml as a new newest
revision: no service is reloaded and the firewall does not reboot.

load_replace_candidate is None instead of NAPALM's stub that raised, so
a capability check sees that the driver replaces nothing. The helper
that finds the newest backup for rollback() moves to the new module,
which keeps opnsense.py under its recorded size.

Refs NetOrk/netork#2511
This commit is contained in:
Christian Manivong committed 2026-11-13 22:21:58 +01:00
1 parent 9d7cb64dac
commit 5a20023c54
7 files changed
+615 -17

No files matched your search

+2 -15
View File
@@ -62,6 +62,7 @@ from napalm_device_types.models import (
from requests.exceptions import RequestException
from napalm_opnsense.api_endpoint import ALIVE_TIMEOUT, api_endpoint
from napalm_opnsense.config_revisions import OPNsenseConfigRevisionsMixin
from napalm_opnsense.ha import config_sync, dhcp_ha
from napalm_opnsense.kea_reservations import (
lease_held,
@@ -99,6 +100,7 @@ def _opnsense_version(versions: Any) -> str:
class OPNsenseDriver(
OPNsenseConfigRevisionsMixin,
OPNsenseTimeSyncMixin,
OPNsenseScheduledJobsMixin,
OPNsenseSshSettingsMixin,
@@ -1091,21 +1093,6 @@ class OPNsenseDriver(
# Internal helpers (config management)
# ------------------------------------------------------------------
def _get_latest_backup_id(self) -> str | None:
"""Return the ID of the most recent server-side config backup, or ``None``.
Calls ``GET /api/core/backup/backups/this``. The response is sorted
newest-first by OPNsense. Returns ``None`` when no backups exist or
the request fails.
"""
try:
data = self._get("/api/core/backup/backups/this")
items = data.get("items", [])
return items[0]["id"] if items else None
except Exception as exc:
logger.debug("No backup snapshots found: %s", exc)
return None
def _fetch_current_routes(self) -> list[dict[str, Any]]:
"""Return the current static routes from the OPNsense API.