Octet

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)

Output
$ 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 by name.
  • description? is optional config. type has no ?, so it is mandatory when you create an interface.
  • {if-mib}? means the node exists only if the server supports the if-mib feature.
  • x marks a deprecated node: interfaces-state was replaced by the ro nodes inside interfaces.

Turning it into paths

UsePath
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.

Traps

  • Writing to a ro node. State data cannot be configured, and the device will reject it.
  • Forgetting to URL-encode a key with a slash. GigabitEthernet1/0/1 must be GigabitEthernet1%2F0%2F1 in a RESTCONF URI.
How did you do?