Yang Data Model, Netconf, Restconf
Yang Data Model


Restconf

RESTCONF according to RFC 8040 section 4:
GET: Retrieve existing configuration
POST: Create new configuration
PATCH: Merge configuration
PUT: Replace existing configuration
DELETE: Remove configuration
For PUT and PATCH operations, the last URL path segment (the string after the very last slash) must match to the top-level item key.
For POST operations, the last URL path segment (the string after the very last slash) must correspond to the parent of the top-level item.
For example, if you want to retrieve the configuration of interfaces in a Cisco device using a simple HTTP GET request, the request will be performed with a GET request on the following URI:
If you want to modify an interface configuration, the request will be performed with a PATCH request:
Using Restconf with python
NETCONF
Defined by the original RFC 6241
The key features of NETCONF are the following:
Transactional Configuration: Ensures that configuration changes are atomic (all or nothing) and rollback is possible if something goes wrong.
Retrieve and Set Configurations: Can retrieve and modify configuration data from devices using a standard structure.
Extensibility with YANG Models: NETCONF operates alongside YANG, a data modeling language, to describe device configurations and state data.
Secure Communication: Operates over SSH, ensuring encrypted communication with devices.
The NETCONF protocol operates on four distinct layers. In the most common cases, all four layers are present in every session.
Layer 1, Transport: provides a communication path between the client (your automation platform) and server (the network device). For Cisco devices this is always - an SSH connection on TCP port 830
Layer 2, Message: An XML document with an element of the type , , or .
Layer 3, Operations: One or more XML elements that specifies the desired operation like , or
Layer 4, Content: The configuration or operational data expressed as XML. Examples could be a new IP address to be configured or the interface byte counters to be - read. For each vendor and device type there are different data models to chose from. These are called YANG models, and describes the available configuration features for the specific platform.
Using Python ncclient module
To modify configuration
Pyang
Some commands
pyang -f tree $path-to-yang-file
pyang -f tree $path-to-yang-file $path-to-yang-file
pyang -f sampleyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml 'ietf-inerfaces.yang' 'ietf-ip.yang': build payload with xml format, save output to output.xml
How to get the path for restconf request
Checking Yang model for IETF interface
pyang -f tree yang-main/vendor/cisco/xe/16121/ietf-interfaces.yang
Checking interface
According to above model, the url is: - https://10.10.10.10/restconf/data/ietf-interfaces:interfaces
Response:
Specific interface: https://10.10.10.10/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet0
Response:
Get address only: https://10.10.10.10/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet0/ietf-ip:ipv4/address
Response:
Checking interfaces-state
https://10.10.10.10/restconf/data/ietf-interfaces:interfaces-state
https://10.10.10.10/restconf/data/ietf-interfaces:interfaces-state/interface=GigabitEthernet0 (Yang model: +--ro interface* [name])
https://10.10.10.10/restconf/data/ietf-interfaces:interfaces-state/interface=GigabitEthernet0/admin-status
Checking Yang Model for Native interface
pyang -f tree yang-main/vendor/cisco/xe/16121/Cisco-IOS-XE-interfaces-oper.yang
Checking specific interface
https://10.10.10.10/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet
Response:
Checking IETF Routing Model
pyang -f tree yang-main/vendor/cisco/xe/16121/ietf-routing.yang
Some URL
https://10.10.10.10/restconf/data/ietf-routing:routing
https://10.10.10.10/restconf/data/ietf-routing:routing/routing-instance=Mgmt-intf
https://10.10.10.10/restconf/data/ietf-routing:routing/routing-instance=Mgmt-intf/routing-protocols
https://10.10.10.10/restconf/data/ietf-routing:routing/routing-instance=Mgmt-intf/routing-protocols/routing-protocol
https://10.10.10.10/restconf/data/ietf-routing:routing/routing-instance=default
https://10.10.10.10/restconf/data/ietf-routing:routing-state/routing-instance=default/routing-protocols/routing-protocol
Response
https://10.10.10.10/restconf/data/ietf-routing:routing-state/routing-instance=default/routing-protocols/routing-protocol=ietf-routing:static,0
Response
https://10.10.10.10/restconf/data/ietf-routing:routing-state/routing-instance=default/ribs
Response:
Yangsuite
pip install yangsuite[core]
yangsuite: run to serve at http://localhost:8480
Configuration
Build Device Profiles
Create Yang Module Repository: Setup > Repository
Define protocol
Define device
Then Get Schema list, Then select modules and download
Create Yang Set: Setup > Yang set
Select Yang model to use
May need to add dependent modules
Reference
https://www.pluralsight.com/courses/managing-cisco-networks-infrastructure-as-code
https://developer.cisco.com/learning/modules/intro-device-level-interfaces/
IOSXE on CSR Recommended Code: https://devnetsandbox.cisco.com/RM/Diagram/Index/27d9747a-db48-4565-8d44-df318fce37ad?diagramType=Topology
Deploying a Telemetry Collector on-box: https://developer.cisco.com/learning/labs/03-iosxr-05-telemetry-onbox/enabling-model-driven-telemetry-on-the-router/
gRPC grpc.io
GitHub YANG repository: https://github.com/YangModels/yang
Openconfig: https://github.com/openconfig/public
Pyang: https://github.com/mbj4668/pyang
https://www.youtube.com/playlist?list=PLOocymQm7YWaJX5l5SgfkAvHQYUS-Xr1Q
Understanding RESTCONF: https://lihaifeng.net/?p=922#Enabling_RESTCONF_on_IOS-XE
https://community.cisco.com/t5/networking-blogs/getting-started-with-netconf-yang-part-1/ba-p/3661241
https://community.cisco.com/t5/networking-blogs/getting-started-with-netconf-yang-part-2/ba-p/3660522
https://developer.cisco.com/video/net-prog-basics/02-network_device_apis
NPB 3.2 - Goodbye SNMP hello NETCONF: https://www.youtube.com/watch?v=oywCLkoKI-k
NPB 3.3 - Learn to CRUD with GET, POST and DELETE using RESTCONF: https://www.youtube.com/watch?v=EPy4F6R9el8
NPB 3.4 - NX-API Part 1: Get started with the Native Nexus API: https://www.youtube.com/watch?v=orJ0zE7KWY0
NPB 3.5 - NX-API Part 2: Dive into the Nexus Object Model: https://www.youtube.com/watch?v=TEke1l0XhGI
Dear Hank… Help Me with RESTCONF URL Creation (cisco.com): https://blogs.cisco.com/developer/restconf-url-creation
RESTCONF operations (devnetexperttraining.com): https://www.devnetexperttraining.com/articles/restconf-operations
RESTCONF with Python - Technology Blog Wim (wimwauters.com): https://blog.wimwauters.com/networkprogrammability/2020-04-04_restconf_python/
Security Comparison Between NETCONF, RESTCONF, and SNMP - Cisco Community: https://community.cisco.com/t5/security-knowledge-base/security-comparison-between-netconf-restconf-and-snmp/ta-p/4805483
Code:
The OpenConfig Models supported by Open NX-OS can be downloaded from Cisco DevHub: https://devhub.cisco.com/ui/native/open-nxos-agents/
https://github.com/DevNetSandbox/sbx_iosxe/tree/master/yang
https://github.com/CiscoDevNet/yang-explorer
https://github.com/wiwa1978/blog-hugo-netlify-code/blob/main/RestConf_Python/change_interfaces_cisco.py
Lab on Cisco:
Code: https://github.com/CiscoDevNet/nxos-code
https://github.com/CiscoDevNet/netprog_basics
https://developer.cisco.com/learning/labs/yang_devnet-format_part1/introduction/
https://developer.cisco.com/learning/labs/yang_devnet-format_part2/introduction/
https://developer.cisco.com/learning/labs/yang_devnet-format_part3/introduction/
Last updated