Use this when preventing concurrent NETCONF edits.
Locking
NETCONF locking (lock and unlock operations) gives one session exclusive access to a datastore while it makes changes, preventing other sessions or users from editing at the same time.
1. Lock datastores during changes to prevent conflicts.
2. Always unlock (finally).
3. Handle lock-denied (someone else editing).
4. Short lock duration.
5. Kill stale sessions carefully.
lock → edit → commit → unlock
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as capability mismatch, namespace drift, wrong datastore, lock contention, partial edit semantics and assuming <ok/> shows final device behavior, choosing the cases most relevant to NETCONF lock/unlock ownership, datastore scope, lock-denied errors, session loss and preventing concurrent writers from assuming transaction safety.
Step 2 Common mistakes Narrow the fault
- Forgetting to unlock after an error.
- Not locking when other tools may edit at the same time.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- lock gives one session exclusive access to a datastore.
- Always unlock, even after errors.
- Lock fails if another session holds it.
- <lock target=candidate/running> — exclusive access
- <unlock> in finally — release
- Lock-denied handling — retry/wait
ReferenceWhy it matters1 section · depth on demand
What it is
<lock> gives one session exclusive access to a datastore during a multi-step change; <unlock> releases it.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Locking prevents other sessions — people on the CLI or other automation — from changing a datastore while a NETCONF change is in progress. Without it, two sources can interleave changes and produce a configuration neither intended.
with m.locked(target="running"):
m.edit_config(target="running", config=cfg)
A lock fails if another session holds it or if the datastore has uncommitted changes; the error identifies the session ID. Locks are released when the session ends, so a crashed script does not lock the device forever. Keep locks short and never hold them while waiting for human input.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in NETCONF > Locking. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc6241 · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For NETCONF lock/unlock ownership, datastore scope, lock-denied errors, session loss and preventing concurrent writers from assuming transaction safety, prefer typed fields and stable IDs over human presentation text.