05-16-2022 08:51 AM - edited 05-16-2022 08:53 AM
Hi Team,
I wondered with there was some sort of "standard" to achieve a get request from NSO API ?
As you might notice i am quite new to APIs, Restconf, whatever...and wondered if we could easily browse NSO CDB using restconf get requests without a documentation.
I spent a couple of minutes to build a correct request and finally remembered that NSO could do it for me thanks to CLI
Here was the request :
http://jeysrv03:82/restconf/data/tailf-ncs:devices/device=jeycisco01/config/tailf-ned-cisco-ios:hostname
This request aimed to retrieve the hostname of my router.
and the command i passed to NSO CLI to retrieve the correct path to be put in my request :
admin@ncs# show running-config devices device jeycisco01 config hostname | display restconf /restconf/data/tailf-ncs:devices/device=jeycisco01/config/tailf-ned-cisco-ios:hostname Jeycisco01
I was wondering how & why this path was built, espacially this part,
/restconf/data/tailf-ncs:devices/device=jeycisco01/config/tailf-ned-cisco-ios:hostname
Can someone explain the relationship between this path in my request and the CDB tree and tell me why there is no exact match between the URL i have to provide and the path i can see from Postman.
When browsing the datas through Postman i can not see any reference to tailf-ncs in the Yang tree as well as tailf-ned-cisco-ios, which lead me to form bad request.
Thanks in advance for your help !
Jerems
Solved! Go to Solution.
05-16-2022 10:36 AM
That identifies the name of the yang module where that node is defined.
From the restconf API docs:
This is how RESTCONF handle namespaces, where the prefix is the YANG module name and the namespace is as defined by the namespace statement in the YANG module.
If multiple path segments come from the same module, you only need prefix the first one.
You can find the core NSO yang models in the src/ncs/yang subdirectory of your NSO installation directory, but with includes and all, it can take some effort to trace around and figure out which module defines the specific node you're trying to access. That's what makes " | display restconf" so handy.
By the way, another good thing to understand about how the restconf paths get constructed is that the second path segment in your URL ("data") is what you use to retrieve configuration data from CDB. If you want to invoke an rpc via restconf, you would change that path segment from "data" to "operations". For example: http://myserver:8080/restconf/operations/tailf-ncs:devices/device=JUNIPER1/rpc/rpc-ping/ping
05-16-2022 11:36 AM
Hello Jerems,
I hope this link might help you . In order to access to data the URL is something like /restconf/data/module-name:identifier.
pyang -f tree tailf-ned-cisco-ios.yang --tree-path /hostname --ignore-errors module: tailf-ned-cisco-ios +--rw hostname? string
In your example you want to access to the leaf hostname that is part of the module tailf-ned-cisco-ios
If you check the cdb . You can find the prefix
admin@ncs# show running-config devices device NETSIM0 config hostname | display prefixes ncs:devices ncs:device NETSIM0 ncs:config ios:hostname TEST ! !
Here yang file that refers to the prefix
module tailf-ned-cisco-ios {
namespace "urn:ios";
prefix ios;
05-16-2022 10:36 AM
That identifies the name of the yang module where that node is defined.
From the restconf API docs:
This is how RESTCONF handle namespaces, where the prefix is the YANG module name and the namespace is as defined by the namespace statement in the YANG module.
If multiple path segments come from the same module, you only need prefix the first one.
You can find the core NSO yang models in the src/ncs/yang subdirectory of your NSO installation directory, but with includes and all, it can take some effort to trace around and figure out which module defines the specific node you're trying to access. That's what makes " | display restconf" so handy.
By the way, another good thing to understand about how the restconf paths get constructed is that the second path segment in your URL ("data") is what you use to retrieve configuration data from CDB. If you want to invoke an rpc via restconf, you would change that path segment from "data" to "operations". For example: http://myserver:8080/restconf/operations/tailf-ncs:devices/device=JUNIPER1/rpc/rpc-ping/ping
05-16-2022 11:36 AM
Hello Jerems,
I hope this link might help you . In order to access to data the URL is something like /restconf/data/module-name:identifier.
pyang -f tree tailf-ned-cisco-ios.yang --tree-path /hostname --ignore-errors module: tailf-ned-cisco-ios +--rw hostname? string
In your example you want to access to the leaf hostname that is part of the module tailf-ned-cisco-ios
If you check the cdb . You can find the prefix
admin@ncs# show running-config devices device NETSIM0 config hostname | display prefixes ncs:devices ncs:device NETSIM0 ncs:config ios:hostname TEST ! !
Here yang file that refers to the prefix
module tailf-ned-cisco-ios {
namespace "urn:ios";
prefix ios;
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide