How do you read a YANG model and find the path you need for a change?
Show the answer
Say this first
I turn the module into a tree with pyang -f tree, find the node, and read its flags: rw is config,
ro is state, * marks a list or leaf-list, ? an optional node, and the list key is in brackets.
To see real data I pull the device's config through NETCONF or RESTCONF and match it to the tree. Cisco
YANG Suite or similar tools do the same in a GUI.
Go deeper
Tree output for ietf-interfaces (trimmed)
$ pyang -f tree ietf-interfaces.yang
module: ietf-interfaces
+--rw interfaces
| +--rw interface* [name]
| +--rw name string
| +--rw description? string
| +--rw type identityref
| +--rw enabled? boolean
| +--rw link-up-down-trap-enable? enumeration {if-mib}?
| +--ro admin-status enumeration {if-mib}?
| +--ro oper-status enumeration
| +--ro last-change? yang:date-and-time
| +--ro if-index int32 {if-mib}?
| +--ro phys-address? yang:phys-address
| +--ro speed? yang:gauge64
| +--ro statistics
| +--ro discontinuity-time yang:date-and-time
| +--ro in-octets? yang:counter64
...
x--ro interfaces-state
...How to read it
interface* [name]is a list keyed byname.description?is optional config.typehas no?, so it is mandatory when you create an interface.{if-mib}?means the node exists only if the server supports theif-mibfeature.xmarks a deprecated node:interfaces-statewas replaced by theronodes insideinterfaces.
Turning it into paths
| Use | Path |
|---|---|
| RESTCONF | /restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1/description |
| XPath (NETCONF filter, telemetry) | /interfaces/interface[name='GigabitEthernet1']/description |
| gNMI | /interfaces/interface[name=GigabitEthernet1]/description |
Where models come from
The device itself (NETCONF get-schema, RFC 6022), the vendor's published model set for that release,
and the public YangModels collection that holds IETF, OpenConfig and vendor models by release.
They will ask next
How do you find which model holds a feature you only know by its CLI?
Configure it on a lab device by CLI, then pull the config through NETCONF or RESTCONF and see where it appears. On Junos,
show configuration ... | display xmlshows the XML path directly. Then confirm the node and its type in the tree.
Traps
- Writing to a
ronode. State data cannot be configured, and the device will reject it. - Forgetting to URL-encode a key with a slash.
GigabitEthernet1/0/1must beGigabitEthernet1%2F0%2F1in a RESTCONF URI.