NAPALM for Network Engineers
Committing, Discarding, and Rollback
What you'll learn
- commit_config()'s and discard_config()'s real signatures and behavior
- rollback()'s real behavior
- commit_config()'s built-in revert_in safety mechanism, verified for real
- Why this module never demonstrates a commit without a diff first
Listen to a guided explanation of this lesson.
Spoken narration isn't supported in this browser.
Never without a diff first
The rule this lesson never breaks
Every example below follows the same order: load a candidate, call compare_config(), review the diff, then commit or discard. This module never shows load_merge_candidate() or load_replace_candidate() followed directly by commit_config() with no diff step in between.
- load_merge_candidate() / load_replace_candidate()stage the change
- compare_config()review the diff -- Lesson 4
- commit_config() or discard_config()this lesson
- rollback()if something's already wrong
commit_config() and discard_config()
def commit_config(self, message: str = "", revert_in: int | None = None) -> None: ...
def discard_config(self) -> None: ...Verified directly. commit_config() applies the staged candidate to the running configuration; discard_config() throws the staged candidate away, leaving the running configuration untouched.
driver.load_merge_candidate(config="vlan 20\n name VOICE\n")
print(driver.compare_config())
driver.discard_config()
print("discarded")
driver.load_replace_candidate(config="hostname SW1\n...")
print(driver.compare_config())
driver.commit_config(message="replace VLAN 20 name")
print("committed")Both paths verified for real: discard_config() after reviewing a diff you decide against; commit_config() after reviewing one you accept.
'+vlan 20\n+ name VOICE'
discarded
'+vlan 20\n+ name VOICE'
committedReal, verified output from both paths, run in this authoring environment against NAPALM's own mock driver (Lesson 6 covers what that means in full).
A real safety mechanism: commit_config(revert_in=...)
print("pending before:", driver.has_pending_commit())
driver.commit_config(message="replace VLAN 20 name", revert_in=300)
print("pending after commit_config(revert_in=300):", driver.has_pending_commit())
driver.confirm_commit()
print("pending after confirm_commit():", driver.has_pending_commit())revert_in is a real, built-in parameter -- commit now, but automatically revert in N seconds unless explicitly confirmed. A genuine safety net against a change that locks you out.
pending before: False
pending after commit_config(revert_in=300): True
pending after confirm_commit(): FalseReal, verified output. Between the two lines, the device would automatically revert to its pre-commit state if confirm_commit() were never called within 300 seconds.
rollback()
def rollback(self) -> None: ...Verified directly. Unlike discard_config() (abandoning a not-yet-committed candidate), rollback() addresses a commit that already happened -- restoring the device's prior configuration.
rolled back, pending commit: FalseReal, verified execution against NAPALM's mock driver -- confirms the call succeeds and clears any pending-commit state.
Real device boundary
No commit_config(), discard_config(), or rollback() call in this lesson was ever executed against a real network device -- every one ran against NAPALM's own mock driver, verified in full in Lesson 6. A real device was never available in this authoring environment, consistent with every module since Phase 2.6.
Key takeaways
- This lesson never shows a commit without compare_config() reviewed first -- a deliberate discipline, not a NAPALM requirement.
- commit_config() applies a staged candidate; discard_config() abandons one before it's ever applied -- both verified for real.
- commit_config(revert_in=300) is a real, built-in safety net: commit now, auto-revert in N seconds unless confirm_commit() is called -- verified directly via has_pending_commit().
- rollback() restores a prior configuration after a commit already took effect -- a different point in the workflow than discard_config().
- No commit/discard/rollback call here ran against a real device -- all verified against NAPALM's own mock driver (Lesson 6), consistent with this curriculum's real-device boundary throughout.