RESTCONF basics (not on blueprint)
Constructing RESTCONF URIs
https:// <ADDRESS> / <ROOT> / <DATA STORE> / <[YANG MODULE:]CONTAINER> / <LEAF>[?<OPTIONS>]
- <ADDRESS> = …of the RESTCONF agent
- <ROOT> = The main entry point for RESTCONF requests
- <DATA STORE> = The data store being queried
- <[YANG MODULE:]CONTAINER> = The base model container being used. Providing the module name is optional.
- <LEAF> = An individual element from within the container
- [?<OPTIONS>] = Optional parameters that impact returned data
Main RESTCONF datastores:
- Configuration: /restconf/data/
- Operations: /restconf/operations/
HTTP headers
General information on “RESTCONF HTTP headers”:
- Two headers need to be specified when using RESTCONF:
- Accept: Specifies the type of data being requested by the client from the device
- Content-Type: Specifies the type of data being sent from the client to the device
- Two valid RESTCONF MIME types available:
- application/yang-data+json: Data is sent/received as valid JSON
- application/yang-data+xml: Data is sent/received as valid XML
- The MIME type can be specified for each way and can be different
Sample code for “RESTCONF HTTP headers”:
headers = {
'Accept': 'application/yang-data+json',
'Content-Type': 'application/yang-data+json'
}
Data serialization
General information on “RESTCONF Data serialization”:
- Serialization = Converting a data structure into a valid JSON object
- When assigning a JSON data construct to a variable in Python, it needs to be serialized before it is sent to the device
- Data serialization requires two things:
- The JSON module must be imported
- The variable/data construct must be converted
Sample code for “RESTCONF Data serialization”:
import json
payload_raw = {
"ietf-interfaces:interface": {
"name": "Loopback1337",
"description": "Configured by RESTCONF",
"type": "iana-if-type:softwareLoopback",
"enabled": True,
"ietf-ip:ipv4": {
"address": [
{
"ip": "1.3.3.8",
"netmask": "255.255.255.255"
}
]
}
}
}
payload_json = json.dumps(payload_raw, indent=4)