cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
110
Views
0
Helpful
1
Replies

Retrieving information with RESTCONF

Mitrixsen
Level 1
Level 1

Hello, everyone.

I am studying RESTCONF for my ENCOR Exam and I have a question about how the URL is formatted.

I have the following code here:

import requests
from rich import print as rprint

headers = {
    "Accept": "application/yang-data+json"
}

url = "https://192.168.170.200:443/restconf/data/Cisco-IOS-XE-native:native/hostname"

response = requests.get(url=url, headers=headers, auth=("admin", "cisco"), verify=False)
rprint(response.json())

The URL is my cisco router running in Cisco CML. This code will return the hostname of the device

{'Cisco-IOS-XE-native:hostname': 'R1'}

I have a question about how the URL is formatted. The Cisco-IOS-XE-native is a YANG model that is used to interact/retrieve the running configuration of the device.

Inside the Cisco-IOS-XE-native YANG model, everything is stored inside the native object/container.

1. My first question is, why can't I just use a URL like this to retrieve the running configuration?
https://192.168.170.200:443/restconf/data/Cisco-IOS-XE-native 

It only works if I do this:
https://192.168.170.200:443/restconf/data/Cisco-IOS-XE-native:native. 
Is it always necessary to add in the container that stores everything?

2. If I want to retrieve something more specific like the version, the URL looks the following: 
https://192.168.170.200:443/restconf/data/Cisco-IOS-XE-native:native/hostname

What's confusing me is what a double collon : and the forward slash achieve. Why is there a double collon with :native but a forward slash with /hostname? When is which one used?

Thank you.

David

1 Accepted Solution

Accepted Solutions

Hey @Mitrixsen the top level container is typically named after the module, or has a well known name like "native" here in XE. It fails does not work with Cisco-IOS-XE-native cos this is a module name (not a data node) restconf expects this to point to an actual data node (container, list, leaf etc…) you generally always need to specify the top level container after the module name.

The : separates the module name from the node name. Like you had native:native, this is when you need to qualify a node with its module namespace.

The / separates path components in the data hierarchy. So say native/hostname, this is inside the native container, and the leaf access of the host name. I recall this information this way: 

Use the : when you need to specify which module a node comes from and use / to navigate through the hierarchy of containers/lists/leaves.

Hope this helps! 

 

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

1 Reply 1

Hey @Mitrixsen the top level container is typically named after the module, or has a well known name like "native" here in XE. It fails does not work with Cisco-IOS-XE-native cos this is a module name (not a data node) restconf expects this to point to an actual data node (container, list, leaf etc…) you generally always need to specify the top level container after the module name.

The : separates the module name from the node name. Like you had native:native, this is when you need to qualify a node with its module namespace.

The / separates path components in the data hierarchy. So say native/hostname, this is inside the native container, and the leaf access of the host name. I recall this information this way: 

Use the : when you need to specify which module a node comes from and use / to navigate through the hierarchy of containers/lists/leaves.

Hope this helps! 

 

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io