Add configuration management (Config/AsyncConfig)#383
Open
ggiesen wants to merge 1 commit into
Open
Conversation
1 task
ggiesen
force-pushed
the
config-management
branch
from
July 12, 2026 02:00
6cf9957 to
2641e29
Compare
Adds a pure binary-API configuration management layer, reachable via api.config(), for RouterOS 7.x. No SSH/terminal access is required. Config and AsyncConfig provide: - export(): read the running config (/export writes nothing directly over the API, so export to a temp file and read it back) - apply()/validate(): import or dry-run a .rsc script; errors surface as TrapError with line and column - compare(): unified diff of running vs candidate configuration - backup_save()/backup_load() - arm_rollback()/cancel_rollback()/rollback_pending(): a device-side /system/scheduler + backup dead man's switch (commit-confirm style) that survives a lost session or lock-out, with no safe-mode action limit - replace(): /system reset-configuration run-after-reset (wipe + reboot) RouterOS has no native non-reboot commit/rollback, so the rollback timer lives on the device rather than the client.
ggiesen
force-pushed
the
config-management
branch
from
July 12, 2026 03:02
2641e29 to
7db58b6
Compare
Owner
|
Hi Thx for PR. I will review it in few days. Please be patient. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a configuration management layer to librouteros, reachable via
api.config(),for RouterOS 7.x. It is implemented entirely over the binary API -- no SSH/terminal
access is required -- and adds no runtime dependencies (stdlib
difflibonly).Config(sync) andAsyncConfig(async) provide:export()-- read the running config./exportreturns nothing when run directlyover the API, so this exports to a temporary file and reads it back.
apply()/validate()--/importa.rscscript, or dry-run it (verbose+dry-run, RouterOS 7.16+). Errors surface asTrapErrorwith line and column.compare()-- unified diff of running vs candidate (informational; the module-levelcompare()diffs two strings directly).backup_save()/backup_load().arm_rollback()/cancel_rollback()/rollback_pending()-- a device-side/system/scheduler+ backup dead man's switch (commit-confirm style). Because thetimer lives on the device it survives a lost session or a lock-out, with no safe-mode
action limit.
replace()--/system reset-configuration run-after-reset(wipe + reboot into anew config).
Why
Configuration management on RouterOS has historically been considered impractical over
the API (no
config replace, no commit/rollback, safe mode is terminal-only). OnRouterOS 7.x the API is actually sufficient:
/export file=...followed by reading the/filecontentsretrieves a full export,/file/add+/importapplies a script(with errors reported), and a scheduler-based backup restore provides a rollback net
that survives a lock-out without needing safe mode.
Design notes
/importruns thescript's own actions).
compare()is a plain textual diff for humans, not anexecutable patch, so it cannot silently misapply.
device (a one-shot
/system/schedulerthat restores a backup), not on the client --it fires even if the client process dies.
replace()is destructive and has no automatic rollback (safe mode is ignored forresets, the run-after-reset script must finish within ~2 minutes); documented as such.
Testing
tests/unit/test_config.py): argument construction for every RouterOScommand, diff/normalization logic, orchestration + temp-file cleanup (mocked helpers),
and the query-builder helpers.
tests/integration/test_config.py): export round-trip, mergeapply, dry-run validation, compare, and the arm/pending/cancel rollback lifecycle,
both sync and async, gated to RouterOS 7.x.
replace()reboot.ruff check,ruff format --checkandmypyare clean.Sync/async parity is maintained throughout. Documentation added at
docs/config.rst.