In the last lesson, you saw that a device API returns structured data.
Your script and the router must agree on this structure.YANG is a language that describes the data of a device.
A YANG data model gives the names, the types, and the structure of this data.
Figure 1 - The Script and the Router Follow the Same Model
Your script works with a data model, not with CLI commands.
This is called model-driven programmability.In this lesson, you use the model ietf-interfaces.
It describes the interfaces of a device.Answer the question below
Which language describes the data of a device?
A YANG model is written in a file called a module.
Here is a short version of the ietf-interfaces module:module ietf-interfaces { container interfaces { list interface { key "name"; leaf name { type string; } leaf description { type string; } leaf enabled { type boolean; } leaf oper-status { type enumeration; config false; } } } }Read the module with four keywords:
module gives the name of the model.
container groups related data.
list holds several entries of the same kind.
leaf holds one value, with its type.
The key identifies each entry of the list.
Here, the key is name.
Two interfaces cannot have the same name.The statement config false marks state data that you can only read.
Answer the question below
Which keyword holds one value?
A real module can have thousands of lines.
A tool called pyang prints a module as a short tree:module: ietf-interfaces +--rw interfaces +--rw interface* [name] +--rw name string +--rw description? string +--rw enabled? boolean +--ro oper-status enumerationEach line of the tree uses a few symbols.
![One line of a YANG tree in parts: rw means read and write, interface is the name, the star marks a list, and [name] is the key of the list](https://dphfzu3i54bzu.cloudfront.net/media/10356/yang-tree-line-symbols.png)
Figure 2 - The Symbols of a Tree Line
rw marks configuration data that you can read and write.
ro marks state data that you can only read, such as the link status.
* marks a list.
[name] is the key of the list.
? marks an optional leaf.
In the next lesson, you will see where the models come from and how the data is written.
Answer the question below
In a YANG tree, which two letters mark data that you can change?