NetAuto Academy

NAPALM for Network Engineers

Committing, Discarding, and Rollback

Advanced13 min read

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
🎓 Teach This Lesson

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.

  1. load_merge_candidate() / load_replace_candidate()stage the change
  2. compare_config()review the diff -- Lesson 4
  3. commit_config() or discard_config()this lesson
  4. rollback()if something's already wrong
Quick checkConcept check
Why does this module always show compare_config() between loading a candidate and committing it?

commit_config() and discard_config()

real signatures, installed napalm 5.2.0
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.

real, verified execution
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.

output — real, verified
'+vlan 20\n+ name VOICE'
discarded
'+vlan 20\n+ name VOICE'
committed

Real, verified output from both paths, run in this authoring environment against NAPALM's own mock driver (Lesson 6 covers what that means in full).

Quick checkIdentify the correct code
A team reviews a diff from compare_config() and decides the change is wrong. Which call correctly abandons it without affecting the running configuration?

A real safety mechanism: commit_config(revert_in=...)

real, verified execution -- the commit-confirm pattern
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.

output — real, verified
pending before: False
pending after commit_config(revert_in=300): True
pending after confirm_commit(): False

Real, 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.

Quick checkScenario
A commit changes a device's management-interface configuration, and a mistake in that change would cut off remote access entirely. What does commit_config(revert_in=300) verified above protect against?

rollback()

rollback's real signature, installed napalm 5.2.0
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.

output — real, verified
rolled back, pending commit: False

Real, verified execution against NAPALM's mock driver -- confirms the call succeeds and clears any pending-commit state.

Quick checkPredict output
What's the real difference between discard_config() and rollback(), based on what this lesson verified?

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.