feat(config): list, read and revert the firewall's config revisions #48

Merged
christianmanivong merged 2 commits from feat/config-revisions into main 2026-11-13 22:10:02 +00:00
Owner

Driver part of NetOrk/netork#2511

OPNsense has no API that takes an uploaded config.xml, so a configuration is restored by reverting to the revision of the firewall's own history that holds it.

The contract is napalm-device-types' ConfigRevisionsMixin (NAPALM/napalm-device-types#117). This driver does the device communication only:

  • get_config_revisions(): /api/core/backup/backups/this, newest first, as ConfigRevisionDict (id, time in UTC, description, user, size).
  • get_config_revision(id): that revision's config.xml (download/this/<id>).
  • _revert_to_config_revision(id): revert_backup/<id>. The template around it refuses an id not in the history (UnknownConfigRevision) and checks afterwards that the newest revision holds the revision's configuration (ConfigRevertFailed).
  • config_revision_content(text): config.xml without the <revision> block and the indentation, canonical XML.
  • load_replace_candidate = None instead of NAPALM's raising stub.

A revert saves config.xml as a new newest revision and nothing else: no service reload, no reboot.

Needs napalm-device-types 4.38.0 on PyPI. The floor is raised to it, so CI cannot install the package until #117 is merged and 4.38.0 is released.

Tested: fixtures only (a fake backup API in the shape of OPNsense's BackupController, 24.7 to master), locally against the device-types branch.

Driver part of NetOrk/netork#2511 OPNsense has no API that takes an uploaded config.xml, so a configuration is restored by reverting to the revision of the firewall's own history that holds it. The contract is napalm-device-types' `ConfigRevisionsMixin` (NAPALM/napalm-device-types#117). This driver does the device communication only: - `get_config_revisions()`: `/api/core/backup/backups/this`, newest first, as `ConfigRevisionDict` (`id`, `time` in UTC, `description`, `user`, `size`). - `get_config_revision(id)`: that revision's config.xml (`download/this/<id>`). - `_revert_to_config_revision(id)`: `revert_backup/<id>`. The template around it refuses an id not in the history (`UnknownConfigRevision`) and checks afterwards that the newest revision holds the revision's configuration (`ConfigRevertFailed`). - `config_revision_content(text)`: config.xml without the `<revision>` block and the indentation, canonical XML. - `load_replace_candidate = None` instead of NAPALM's raising stub. A revert saves config.xml as a new newest revision and nothing else: no service reload, no reboot. **Needs napalm-device-types 4.38.0 on PyPI.** The floor is raised to it, so CI cannot install the package until #117 is merged and 4.38.0 is released. Tested: fixtures only (a fake backup API in the shape of OPNsense's BackupController, 24.7 to master), locally against the device-types branch.
christianmanivong added 1 commit 2026-11-13 21:22:10 +00:00
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
5a20023c54
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
christianmanivong added 1 commit 2026-11-13 21:33:58 +00:00
refactor(config): take the revision contract from napalm-device-types
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 35s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m1s
CI / driver (pull_request) Successful in 2m44s
driver / publish (pull_request) Skipped
a65a3ed6e3
napalm-device-types 4.38.0 declares ConfigRevisionsMixin: the listing,
the reading, ConfigRevisionDict and the exceptions, and the revert as a
template. The driver keeps the device communication: the three backup
API calls, the revert step, and config_revision_content(), which leaves
out the <revision> block every save writes into config.xml and the
indentation between elements.

The template reads the newest revision after the revert and checks that
it holds the revision's configuration. OPNsense answers "reverted" even
when restoreBackup() could not load the file and kept the previous one;
that now raises ConfigRevertFailed instead of passing. A refusal of the
firewall raises ConfigRevertFailed too. An id the history does not list
still never reaches a request path.

Refs NetOrk/netork#2511
christianmanivong merged commit 521f7c5d73 into main 2026-11-13 22:10:02 +00:00
christianmanivong deleted branch feat/config-revisions 2026-11-13 22:10:02 +00:00
Sign in to join this conversation.