Use this when YANG groups related nodes.
Containers
A YANG container groups related nodes under one name, such as an interfaces container holding all interface entries, without holding a value itself.
1. Containers group related nodes (no value themselves).
2. Presence containers mean something by existing.
3. Map to JSON objects / XML elements.
4. Nested hierarchy.
5. Follow model paths.
container → child nodes
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 primary procedure is: Inspect the module/revision and container schema, read the exact subtree from a supporting server, apply one valid and one constraint-violating fixture, and compare protocol errors/read-back. Exercise failure-oriented cases such as wrong module revision, confusing presence container with organizational node, creating empty containers with unintended meaning, ignoring must/when constraints and ambiguous namespace prefixes so the test covers failure cases, not only the happy path.
Step 2 Common mistakes Narrow the fault
- Confusing containers with lists.
Step 3 Where it fails Narrow the fault
Tests should include edge cases such as wrong module revision, confusing presence container with organizational node, creating empty containers with unintended meaning, ignoring must/when constraints and ambiguous namespace prefixes. Recovery should capture schema/module revision and protocol error-path/error-tag, fix the schema path/value or client encoding, then reread the exact subtree from the target datastore.
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.
- Containers group related child nodes.
- They hold no value themselves.
- Presence containers mean something by existing.
pyang -f tree <module>.yang | grep '+--rw'— containers- Presence containers — meaning
- JSON/XML representation — payload
ReferenceWhy it matters1 section · depth on demand
In depth
A YANG container is a node that groups related child nodes without a value of its own, like a folder. A presence container additionally means something just by existing (e.g. enabling a feature).
container ntp {
presence "NTP enabled";
leaf-list server { type inet:host; }
}
| Container type | Meaning |
|---|---|
| Non-presence | Pure grouping; exists if it has children |
| Presence | Its existence carries meaning |
In RESTCONF URLs and JSON payloads, containers appear as nested objects ("ntp": {"server": [...]}).
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Containers in YANG is owned at runtime by the YANG schema defining an interior container node and the server implementation instantiating that schema in configuration/operational datastores. The durable intent is module/revision with container definition, child nodes, presence semantics, constraints and namespace. Reliable automation must carry stable identity across the path: module name/revision/namespace plus schema path and list keys beneath the container where applicable. The consumer-visible target is the modeled data-tree subtree, not an arbitrary JSON/XML object that happens to have the same label. The key invariants are presence versus non-presence container semantics are respected, child constraints/types are validated, namespace/revision is explicit and clients do not infer instance existence from schema existence.
ReferenceConfiguration & state1 section · depth on demand
Lifecycle
Store and review module/revision with container definition, child nodes, presence semantics, constraints and namespace; pin or at least record implementation/model versions and keep environment-specific identity outside reusable logic where possible. The stable identity contract is module name/revision/namespace plus schema path and list keys beneath the container where applicable.
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 YANG > Containers. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/info/rfc7950/ · confidence 94%Quick lookup tables
YANG → Containers · operational reference
Context-specific ownership, verification, output and failure-boundary lookup for YANG → Containers.
| Layer | YANG → Containers operational reference |
|---|---|
| Runtime/ownership | YANG 1.1 data modeling · the YANG schema defining an interior container node and the server implementation instantiating that schema in configuration/operational datastores |
| Persistent intent | module/revision with container definition, child nodes, presence semantics, constraints and namespace |
| Verification | Inspect the module/revision and container schema, read the exact subtree from a supporting server, apply one valid and one constraint-violating fixture, and compare protocol errors/read-back. |
| Expected interpretation | The client addresses the correct module/schema path, presence semantics and child constraints behave as modeled, invalid data is rejected explicitly, and valid data reads back under the expected container. |
| Recovery boundary | capture schema/module revision and protocol error-path/error-tag, fix the schema path/value or client encoding, then reread the exact subtree from the target datastore |
Deep reference
Healthy vs suspicious evidence
Output interpretation
At minimum retain server/device, module/revision/namespace, schema path, presence semantics, child node values, RPC/request ID, error-tag/path for invalid data and datastore read-back. The useful output makes ambiguity visible, links to the target identity from module name/revision/namespace plus schema path and list keys beneath the container where applicable, and provides enough context to safely decide whether a retry is permitted.