Pulling Configs from Cisco NSO using curl and json2yaml.py

14 03 2019

We’re using Cisco NSO in our lab at the moment to provision L3VPNs across multi-vendor environments as part of a demo. Just noting down a few things here for future reference:

You can use the curl (command-line URL) utility to query NSO’s API and retrieve the configuration of a device it knows about. You probably know that NSO syncs a device’s config locally, so this will be a way to retrieve the device config that NSO knows about – if the device is out of sync, of course this won’t quite be the latest:

curl -u username:password -H "Accept: application/vnd.yang.data+json" http://192.168.8.172:8080/api/config/devices/device/CPE-3/config | json2yaml

I’ll break this down:

curl -u username:password – provides the username and password of your NSO installation

-H “Accept: application/vnd.yang.data+json” – specifies an HTTP header to send in the request. In this instance, we are saying that we are expecting a JSON response. Alternatively you could specify ‘vnd.yang.data+xml’ to receive an XML response.

http://192.168.8.172:8080/api/config/devices/device/CPE-3/config – this is the API request we are making. CPE-3 is the device we are requesting the configuration of.

| json2yaml – this pipes the JSON response through a python module to convert to YAML. On a Mac, you can install this using ‘pip install json2yaml’.

The output is basically a full Junos config presented in YAML format:

tailf-ncs:config:
tailf-ned-cisco-ios-xr:EXEC:
operations:
exec: /api/config/devices/device/CPE-3/config/cisco-ios-xr:EXEC/_operations/exec
junos:configuration:
version: 18.4R1.8
system:
host-name: NSO-VSRX1
root-authentication:
encrypted-password: $6$OjoDl6X88zIC48/
login:
user:
- name: axians
services: {}
syslog:
user:
- name: '*'
file:
- name: messages
- name: interactive-commands
license:
autoupdate: {}
interfaces:
interface:
- name: fxp0
- name: ge-0/0/0
routing-options:
static:
route:
- name: 192.168.0.0/16
- name: 172.16.0.0/12
autonomous-system: {}
protocols:
bgp:
group:
- name: GROUP1
policy-options:
policy-statement:
- name: REDIST-CONNECTED
security:
screen:
ids-option:
- name: untrust-screen
zones:
security-zone:
- name: trust
- name: untrust
forwarding-options:
family:
mpls:
mode: packet-based
tailf-ned-cisco-ios:EXEC:
operations:
default: /api/config/devices/device/CPE-3/config/ios:EXEC/_operations/default
exec: /api/config/devices/device/CPE-3/config/ios:EXEC/_operations/exec

Advertisements

Actions

Information

One response

18 03 2019
Pulling Configs from Cisco NSO using curl and json2yaml.py - Axians UK Blog

[…] The Data Plumber via Pulling Configs from Cisco NSO using curl and json2yaml.py […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: