YANG List Statement Definition

300-435 By islever Editorial Last updated

Short answer

A The list statement defines a keyed list of entries in YANG, requiring a key to uniquely identify each item in the collection.

Question

In YANG, which statement defines a keyed list of entries?
  1. list Correct Answer
  2. leaf
  3. container
  4. leaf-list

Key Takeaways

In YANG data modeling, the list statement is used to define a keyed list of entries, allowing multiple instances to be uniquely identified. This distinguishes it from containers, which group nodes, and leaf-lists, which hold unkeyed scalars. Understanding this distinction is critical for constructing accurate network configuration models.

Expert Analysis

In the YANG data modeling language, the structural distinction between a single configuration instance and a collection of instances is defined by specific node types, with the 'list' statement serving as the exclusive mechanism for creating keyed collections. The correct answer is A because only the list statement inherently requires a key definition to uniquely identify each entry within a hierarchical tree, distinguishing it from containers that group nodes without identity constraints or leafs that hold atomic values. This architectural rule ensures that automated systems can reliably address individual entries in a table-like structure using RESTCONF or NETCONF operations, which depend on unique keys for CRUD (Create, Read, Update, Delete) semantics.

Keyed Identity Requirement in Data Structures

The decisive condition in this scenario is the explicit requirement for a "keyed" list, which immediately eliminates all options that do not support unique identification of multiple entries. In YANG, a 'list' statement defines a set of nodes where each node is uniquely identified by one or more key leaves specified within the list definition. This is fundamental to how network devices store configurations such as routing tables, interface lists, or ACL entries, where each row must be distinguishable. For example, if you are defining an IP access list, each entry needs a unique identifier or index; the 'list' construct allows the modeler to define a 'key' clause that specifies which leaf(s) serve as this unique identifier. Without this key, the device would not know how to reference a specific entry when performing updates or deletions via an automation protocol. The other options fail this basic structural test: a 'container' groups related nodes but does not create a repeatable set of identifiable entries, acting more like a folder than a table. A 'leaf' represents a single scalar value, such as a boolean or integer, and cannot contain multiple entries or keys. A 'leaf-list' allows multiple values for the same leaf name, but these values are unkeyed scalars; you cannot assign a secondary attribute or identifier to a specific item in a leaf-list, making it unsuitable for complex records that require multiple fields per entry. Therefore, the presence of the word "keyed" is the primary filter that isolates 'list' as the only valid choice.

Mechanism of Entry Creation and Addressing

The step in the mechanism where the chosen action takes effect occurs during the instantiation of the data tree, where the 'list' statement dictates how entries are addressed in management protocols. When a network operator or automation script creates an entry in a YANG list, the system allocates a new node under the parent container, indexed by the defined key values. This indexing is critical for protocols like NETCONF and RESTCONF, which use URI paths to target specific resources. For instance, in RESTCONF, a GET request might target /restconf/data/example:config/interface-list=eth0, where interface-list is the name of the list and eth0 is the key value. The 'list' statement in the YANG module maps directly to this addressable resource. If a 'container' were used instead, it would represent a single logical grouping, and there would be no mechanism to add a second, distinct entry with the same structure unless the entire container was replaced. If a 'leaf-list' were used, you could append values, but you could not retrieve or update a specific value based on a composite key; you could only replace the entire list or match by position, which is fragile and non-deterministic. The 'list' construct provides the necessary granularity for fine-grained configuration management, allowing automation tools to modify a single line item in a large configuration table without affecting the rest of the dataset. This precision is what makes YANG models robust for enterprise network automation, enabling safe and targeted changes.

Structural Limitations of Incorrect Options

What each remaining option costs or breaks inside this scenario includes the inability to manage multi-attribute records or address individual items uniquely. Option B, 'leaf', defines a single piece of data, such as an IP address or a hostname. It cannot hold a list of entries at all; it is an atomic value. Using a leaf for a collection would force the modeler to either duplicate the leaf name (which YANG forbids for simple leaves) or nest them in a way that loses the tabular nature of the data. Option C, 'container', groups nodes into a single logical unit. While it can contain lists, the container itself is singular. You cannot have two "default-gateway" containers in the same scope because a container does not have a key to differentiate instances. This limitation breaks the ability to model scenarios where multiple similar objects exist, such as multiple default routes or multiple VLAN definitions. Option D, 'leaf-list', allows multiple instances of a leaf, but these instances are unkeyed. This means you cannot distinguish between two identical values if they appear in the list, nor can you attach additional metadata to each entry. For example, if you need a list of users with usernames and passwords, a leaf-list of usernames fails because you cannot associate the password with the specific username instance uniquely without a key-based structure. The cost of choosing any of these incorrect options is a loss of modeling fidelity, leading to configurations that are either impossible to express correctly or extremely difficult to automate safely.

Alternative Scenario Conditions Not Met

The condition that would turn a named alternative into the right answer, specifically 'leaf-list', is if the requirement was simply to allow multiple values of the same type without needing to associate additional attributes or unique identifiers with each value. For instance, if the question asked for a way to store a list of allowed SNMP community strings where each string is independent and has no sub-fields, a 'leaf-list' would be appropriate. However, the prompt explicitly asks for a "keyed list," implying a structured record where each entry is identified by a key and likely contains other associated data. The condition for 'container' being correct would be if the goal was to group a single set of related configuration parameters without repetition, such as encapsulating all settings for a single loopback interface into a logical block. Since the scenario demands a collection of entries with unique identification, neither the unkeyed nature of leaf-list nor the singular nature of container satisfies the constraint. The specificity of the term "keyed" locks the answer to 'list', as it is the only construct designed to handle repeatable, identifiable records in the YANG information model.

Exam Strategy

When analyzing YANG model questions, focus on the keywords 'keyed', 'multiple', and 'single'. 'Keyed list' always points to 'list'. 'Multiple unkeyed values' points to 'leaf-list'. 'Single group of nodes' points to 'container'. Always check if the option supports unique addressing, which is a core requirement for network automation protocols like NETCONF and RESTCONF.

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