Infrastructure and Automation · Topic 7 of 8
Interpreting RESTCONF and NETCONF Results and YANG Models
Learn to read RESTCONF and NETCONF replies and basic YANG models, including containers, lists, leaves, keys, types, config false and the pyang tree view.
- 6 min
- Includes a diagram
- A RESTCONF reply is JSON or XML, and the top key holds the module name and container.
- A NETCONF reply is an
rpc-replywith adataelement, or anrpc-erroron failure. - A YANG
containergroups nodes, alistrepeats and has akey, and aleafholds one value.
What it is
A RESTCONF or NETCONF query returns structured data that follows a YANG model, and you must be able to read both the reply and the model.
The reply shows the real values on a device. The YANG model shows the shape of that data, with its names, types and which parts are configuration.
Once you can read the model, you can predict what a reply looks like, and the other way round.
How it works
Start with the model, then match the reply against it.
A RESTCONF reply
A GET on the interfaces path returns JSON like this.
{
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "GigabitEthernet1",
"description": "WAN link",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true,
"ietf-ip:ipv4": {
"address": [
{"ip": "192.0.2.1", "netmask": "255.255.255.0"}
]
}
}
]
}
}
Reading it:
- The top key is the module name, a colon, and the container name.
interfaceis a JSON list, with one entry per interface.- Each entry has leaves such as
name,enabledanddescription. - Keys with a prefix, such as
ietf-ip:ipv4, come from another module that adds to the model. - In Python the value is
data["ietf-interfaces:interfaces"]["interface"][0]["name"].
RESTCONF status codes
| Code | Meaning |
|---|---|
| 200 | The GET worked, and the body holds the data |
| 201 | A resource was created, after a POST or PUT |
| 204 | The change worked, with no body |
| 400 | The request or data is invalid |
| 401 | Authentication failed |
| 404 | The path does not exist, or the data is not found |
| 409 | A conflict, such as creating something that already exists |
A NETCONF reply
A NETCONF reply is XML. Because it is a tree of named elements, it can be pictured as an outline.
rpc-reply
data
interfaces
interface
name: GigabitEthernet1
description: WAN link
enabled: true
The reply is an rpc-reply element, and its data element holds the answer to a get or get-config request. The element names match the YANG names. The XML namespace tells you which module each element belongs to.
If the request works but returns no data, the reply holds an empty data element. A successful change has an ok element, and a failure has an rpc-error element.
| Part of an error | Meaning |
|---|---|
error-type | The layer where it failed, such as application or protocol |
error-tag | A short reason, such as invalid-value or data-exists |
error-message | Readable text |
In Python with ncclient, the reply object has an xml attribute with the text, and data_xml for the data part. Parse it with xmltodict or ElementTree.
A basic YANG module
module example-interfaces {
namespace "urn:example:interfaces";
prefix exif;
container interfaces {
list interface {
key "name";
leaf name {
type string;
}
leaf description {
type string;
}
leaf enabled {
type boolean;
default "true";
}
leaf mtu {
type uint16 {
range "68..9000";
}
}
leaf oper-status {
type string;
config false;
}
}
}
}
Reading the module
| Keyword | Meaning |
|---|---|
module | The top level name of the model |
namespace and prefix | A unique identifier and a short label for the module |
container | A grouping node with no value of its own |
list | A repeated set of entries, one per item |
key | The leaf that uniquely identifies each list entry |
leaf | A single value with a type |
leaf-list | A list of simple values |
type | The kind of value, such as string, boolean, uint16 or enumeration |
default | The value used if none is set |
config false | A read only state node, not configuration |
Anything that lacks config false can be configured. The range on mtu limits it to 68 to 9000, and the device refuses values outside it.
From this module you can predict the RESTCONF path to one entry, which is /restconf/data/example-interfaces:interfaces/interface=GigabitEthernet1, with the list key after an equals sign.
The pyang tree view
The pyang tool prints a compact tree of a module.
$ pyang -f tree example-interfaces.yang
module: example-interfaces
+--rw interfaces
+--rw interface* [name]
+--rw name string
+--rw description? string
+--rw enabled? boolean
+--rw mtu? uint16
+--ro oper-status? string
Here rw means read and write, and ro means read only. A star marks a list, and the key is in square brackets. A question mark marks an optional leaf.
Matching replies to models
If a reply lacks a leaf that the model marks optional, the value was not set. If a list key is missing from a request, the device cannot tell which entry you mean.
In the tree view, rw leaves are configuration and ro leaves are state. A star means a list, and the name in brackets is its key.
What to remember for the exam
Seven facts cover this topic.
- A RESTCONF reply is JSON or XML, and the top key holds the module name and container.
- A NETCONF reply is an
rpc-replywith adataelement, or anrpc-erroron failure. - A YANG
containergroups nodes, alistrepeats and has akey, and aleafholds one value. config falsemarks read only state data.- In
pyangtree output,rwis configurable,rois read only, and*marks a list. - A list entry in a RESTCONF path is selected with the key after an equals sign.
- A 204 means that a change succeeded with no body, and a 409 means a conflict.
Common mistakes
Four mistakes are typical.
Confusing container and list. A container is one grouping, while a list has many entries with a key.
Treating read only data as configuration. Nodes with config false cannot be set.
Ignoring the module prefix. In JSON, ietf-ip:ipv4 comes from a different module than its parent.
Expecting a body after a successful PUT or PATCH. A 204 reply has none.
Do not guess a key or value. Read the module, because a wrong value is rejected or, worse, accepted and misapplied.
Check yourself
Work through these three questions.
What does
rworromean in thepyangtree?rwis read and write configuration, androis read only state.What is the role of
keyin a YANG list?It names the leaf that uniquely identifies each entry in the list.
What does a NETCONF
rpc-errorelement tell you?The request failed, and it gives the error type, a tag with the reason and a message.
Topic 7 of 8 in Infrastructure and Automation
Test yourself on Infrastructure and Automation
The full Cisco CCNA 200-901 DEVASC question bank has 808 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.