YANG leaf-list vs list structural differences

300-435 By islever Editorial Last updated

Short answer

A A leaf-list consists of unkeyed scalars, whereas a list contains keyed entries that allow for unique identification and structured data grouping.

Question

YANG leaf-list vs list difference?
  1. leaf-list=unkeyed scalars; list=keyed entries Correct Answer
  2. Same
  3. leaf-list has keys
  4. list has no keys

Key Takeaways

The core concept distinguishes between YANG leaf-lists and lists based on key presence. Option A is correct because leaf-lists hold unkeyed scalar values, while lists contain keyed entries. This distinction dictates how data is addressed and structured in network automation models.

Expert Analysis

The decisive factor in this scenario is the structural definition of YANG data nodes, where the distinction between a leaf-list and a list rests entirely on whether the entries contain key attributes or are merely unkeyed scalar values. Option A correctly identifies that a leaf-list consists of unkeyed scalars while a list comprises keyed entries, which is the fundamental architectural difference mandated by RFC 7950. This classification determines how instances are addressed, indexed, and manipulated within the configuration datastore, making it critical for constructing valid automation payloads and interpreting model trees.

Unkeyed Scalars Define the Leaf-List Structure

A leaf-list is defined as a list of leaves with the same name, type, and config attribute. It is essentially an ordered array of scalar values. Because each entry is a leaf, it cannot have sub-elements or child nodes. Crucially, these entries do not possess keys. You access a specific item in a leaf-list either by its position in the array (index) or by iterating through all items, but you cannot address a specific value by a unique identifier embedded within the value itself. For example, if a device supports multiple DNS servers, and the model defines them as a leaf-list named 'dns-server', each entry might simply be an IP address string. There is no 'name' or 'id' field attached to that IP address within the structure; it is just one of many strings in the list. This makes leaf-lists ideal for simple collections of homogeneous data where order matters but individual identification via a key does not.

Keyed Entries Enable Unique Identification in Lists

In contrast, a list is a structured node that contains one or more keys. These keys form a unique identifier for every instance of the list. When you define a list, you must specify at least one key, and often additional non-key leaves exist within that list instance. This allows you to address a specific entry directly using the key's value in the URI path. For instance, if you have a list of VLANs, the list might be named 'vlan', and the key would be 'id'. To access VLAN 10, you query '/vlans/vlan[id=10]'. Each entry in the list can contain multiple leaves (e.g., 'name', 'status'), providing a richer structure than a leaf-list. The presence of keys transforms the collection from a simple array into a map-like structure where individual records are uniquely addressable and can hold complex, multi-attribute data.

Conflating Structure with Collection Semantics

Candidates often confuse leaf-lists and lists because both represent collections of data. The boundary lies in the presence of keys. A leaf-list is a collection of scalars without keys; a list is a collection of structured entries with keys. If a model requires you to store a set of interface names, a leaf-list suffices. If it requires storing detailed configuration for each interface (including speed, duplex, and status), a list is required because you need to group those attributes under a common identifier (the interface name). Mistaking one for the other leads to invalid YANG module definitions and failed automation scripts that cannot properly address or modify the target data nodes.

Rule for Automation Payload Construction

When constructing JSON or XML payloads based on YANG models, always check if the node is a list or a leaf-list. If it is a list, ensure your payload includes the key fields to uniquely identify each instance. If it is a leaf-list, provide an array of values without any key wrappers. This rule applies universally across NETCONF, RESTCONF, and native API interactions. Understanding this distinction prevents errors in Day 0 provisioning and configuration management, ensuring that automation tools interact with the device's data model accurately and efficiently.

Official Reference

https://datatracker.ietf.org/doc/html/rfc7950

This link opens the official vendor documentation in a new tab.

Practice All 300-435 Questions

Access 150 questions with complete answers and detailed explanations.

View Full 300-435 Practice Test →

← Back to 300-435 Study Guide