02-06-2025 05:30 AM
I have a template generator built in PHP, VTL, and I have also tested Jinja. This setup works well for generating Cisco CLI templates offline with the exact configuration structure I need, doing this since years..
Currently, I apply these configurations (CLI Scripting) by either copying them directly to the devices or connecting via SSH to upload them to NSO and commit the changes.
I noticed that NSO provides an API, which allows to apply configurations via a PATCH request, but it requires the exact XML representation of the YANG model.
The challenge I’m facing is that integrating my existing templating system with the YANG structure for automation is quite complex. Instead of manually translating CLI configurations into YANG, I’m looking for a tool that can help convert Cisco CLI commands into YANG-compatible XML or JSON.
Current API Calls:
So far, I have successfully used the following REST API calls for both IOS-XE and IOS-XR:
For IOS XR:
/restconf/data/tailf-ncs:devices/device={DEVICE_XR}/config/tailf-ned-cisco-ios-xr:explicit-path?dry-run
/restconf/data/tailf-ncs:devices/device={DEVICE_XR}/config/tailf-ned-cisco-ios-xr:interface?dry-run
For IOS XE:
/restconf/data/tailf-ncs:devices/device={DEVICE_XE}/config/tailf-ned-cisco-ios:ip/explicit-path?dry-run
/restconf/data/tailf-ncs:devices/device={DEVICE_XE}/config/tailf-ned-cisco-ios:interface?dry-run
Questions:
CLI to YANG Conversion:
Is there any tool available that can convert Cisco CLI configurations into YANG-compatible XML or JSON? This would help automate the conversion and make it easier to push configurations via the API.
Optimizing the PATCH request:
Currently, I have to specify both tailf-ned-cisco-ios or tailf-ned-cisco-ios-xr and the specific module (e.g., interface, explicit-path) in each API call.
Is there a way to apply a PATCH request at a higher level so I can commit the entire configuration at once, without needing to specify each module separately?
I would really appreciate any guidance or best practices on these topics.
Neds i'm using:
cisco-ios-cli-6.100 6.100.8
cisco-iosxr-cli-7.52 7.52.2
Thanks!
02-07-2025 06:35 AM
You could try https://developer.cisco.com/yangsuite/ ive not used it but you also try this https://github.com/networktocode/yangify
02-17-2025 04:20 AM
As far as I know, there is no tool to convert from cli to XML or JSON yang representation. NSO itself can be use to get this representation using "| display", but I don't see a way to use it as a tool conversion.
NSO exposes configuration data and state using the RESTCONF protocol, which follow the YANG models NSO or the user defined. You have CRUD operations to work with it. I recommend you to check the RESTCONF documentation to get more familiar with it: https://cisco-tailf.gitbook.io/nso-docs/guides/development/core-concepts/northbound-apis/restconf-api
Regarding namespaces, from what I see are part of the RESTCONF standard. On this learning lab you can see how NSO use them https://developer.cisco.com/learning/labs/manage-nso-with-restconf/finding-the-data/
here is a RESTCONF example with other operations in case it helps you https://github.com/jillesca/nso-restconf-dns-example/tree/main and here you can find more examples from the BU https://github.com/NSO-developer/nso-examples/tree/main/northbound-interface
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