12-17-2018 07:45 AM - edited 03-01-2019 04:15 AM
is there a way to set how NSO responds to a restconf request
EG Json and raw device config
/restconf/data/devices/device=C6800
it returns the config in XML how can get NSO to return the same in json and raw device config
Thanks
Regards
Yale
Solved! Go to Solution.
12-17-2018 08:33 AM
You can control the returned content type by providing 'Accept' header. For example:
curl -i -k -u admin:admin https://localhost:8888/restconf/data/devices/device=sw-cisco-2900-0/config -X GET -H "Accept: application/yang-data+json"
But in any case, this GET call will always return the configs as they are represented in CDB, rather than device CLI or something of this sort.
For some device types, the NED implements live-status commands which allows you to run commands directly on the device and return the device's answer as-is, and this might be closer to a raw device configs, but it might not be very nice to look at though...
For example, in ios with json output:
curl -i -u admin:admin http://localhost:8080/restconf/operations/devices/device=sw-cisco-2900-0/live-status/tailf-ned-cisco-ios-stats:exec/any -X POST -H 'Accept: application/yang-data+json' -H 'Content-Type: application/yang-data+json' -d "{\"input\": {\"args\": \"show run\"}}"
HTTP/1.1 200 OK
Server:
Date: Mon, 17 Dec 2018 16:28:13 GMT
Cache-Control: private, no-cache, must-revalidate, proxy-revalidate
Content-Length: 1311
Content-Type: application/yang-data+json
Vary: Accept-Encoding
Pragma: no-cache
{
"tailf-ned-cisco-ios-stats:output": {
"result": "\r\ntailfned police cirmode\r\nno service password-encryption\r\naaa accounting delay-start\r\nno cable admission-control preempt priority-voice\r\nno cable qos permission create\r\nno cable qos permission update\r\nno cable qos permission modems\r\**bleep** source-route\r\nno ip gratuitous-arps\r\nno ip cef\r\**bleep** finger\r\nno ip http server\r\nno ip http secure-server\r\nno ip forward-protocol nd\r\nno ipv6 cef\r\nno dot11 syslog\r\ninterface Loopback0\r\n no shutdown\r\n ip address 127.0.0.1 255.0.0.0\r\nexit\r\ninterface Ethernet0/0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet1/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet1/1\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0/1\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\nsw-cisco-2900-0# "
}
}
with xml output:
curl -i -u admin:admin http://localhost:8080/restconf/operations/devices/device=sw-cisco-2900-0/live-status/tailf-ned-cisco-ios-stats:exec/any -X POST -H 'Accept: application/yang-data+xml' -H 'Content-Type: application/yang-data+json' -d "{\"input\": {\"args\": \"show run\"}}"
HTTP/1.1 200 OK
Server:
Date: Mon, 17 Dec 2018 16:28:30 GMT
Cache-Control: private, no-cache, must-revalidate, proxy-revalidate
Content-Length: 1429
Content-Type: application/yang-data+xml
Vary: Accept-Encoding
Pragma: no-cache
<output xmlns='urn:ios-stats'>
<result>
tailfned police cirmode
no service password-encryption
aaa accounting delay-start
no cable admission-control preempt priority-voice
no cable qos permission create
no cable qos permission update
no cable qos permission modems
ip source-route
no ip gratuitous-arps
no ip cef
ip finger
no ip http server
no ip http secure-server
no ip forward-protocol nd
no ipv6 cef
no dot11 syslog
interface Loopback0
no shutdown
ip address 127.0.0.1 255.0.0.0
exit
interface Ethernet0/0/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet0
no shutdown
no switchport
no ip address
exit
interface FastEthernet0/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet1/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet1/1
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0/0
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0/1
no shutdown
no switchport
no ip address
exit
sw-cisco-2900-0# </result>
</output>
12-17-2018 08:33 AM
You can control the returned content type by providing 'Accept' header. For example:
curl -i -k -u admin:admin https://localhost:8888/restconf/data/devices/device=sw-cisco-2900-0/config -X GET -H "Accept: application/yang-data+json"
But in any case, this GET call will always return the configs as they are represented in CDB, rather than device CLI or something of this sort.
For some device types, the NED implements live-status commands which allows you to run commands directly on the device and return the device's answer as-is, and this might be closer to a raw device configs, but it might not be very nice to look at though...
For example, in ios with json output:
curl -i -u admin:admin http://localhost:8080/restconf/operations/devices/device=sw-cisco-2900-0/live-status/tailf-ned-cisco-ios-stats:exec/any -X POST -H 'Accept: application/yang-data+json' -H 'Content-Type: application/yang-data+json' -d "{\"input\": {\"args\": \"show run\"}}"
HTTP/1.1 200 OK
Server:
Date: Mon, 17 Dec 2018 16:28:13 GMT
Cache-Control: private, no-cache, must-revalidate, proxy-revalidate
Content-Length: 1311
Content-Type: application/yang-data+json
Vary: Accept-Encoding
Pragma: no-cache
{
"tailf-ned-cisco-ios-stats:output": {
"result": "\r\ntailfned police cirmode\r\nno service password-encryption\r\naaa accounting delay-start\r\nno cable admission-control preempt priority-voice\r\nno cable qos permission create\r\nno cable qos permission update\r\nno cable qos permission modems\r\**bleep** source-route\r\nno ip gratuitous-arps\r\nno ip cef\r\**bleep** finger\r\nno ip http server\r\nno ip http secure-server\r\nno ip forward-protocol nd\r\nno ipv6 cef\r\nno dot11 syslog\r\ninterface Loopback0\r\n no shutdown\r\n ip address 127.0.0.1 255.0.0.0\r\nexit\r\ninterface Ethernet0/0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet1/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface FastEthernet1/1\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0/0\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\ninterface GigabitEthernet0/1\r\n no shutdown\r\n no switchport\r\n no ip address\r\nexit\r\nsw-cisco-2900-0# "
}
}
with xml output:
curl -i -u admin:admin http://localhost:8080/restconf/operations/devices/device=sw-cisco-2900-0/live-status/tailf-ned-cisco-ios-stats:exec/any -X POST -H 'Accept: application/yang-data+xml' -H 'Content-Type: application/yang-data+json' -d "{\"input\": {\"args\": \"show run\"}}"
HTTP/1.1 200 OK
Server:
Date: Mon, 17 Dec 2018 16:28:30 GMT
Cache-Control: private, no-cache, must-revalidate, proxy-revalidate
Content-Length: 1429
Content-Type: application/yang-data+xml
Vary: Accept-Encoding
Pragma: no-cache
<output xmlns='urn:ios-stats'>
<result>
tailfned police cirmode
no service password-encryption
aaa accounting delay-start
no cable admission-control preempt priority-voice
no cable qos permission create
no cable qos permission update
no cable qos permission modems
ip source-route
no ip gratuitous-arps
no ip cef
ip finger
no ip http server
no ip http secure-server
no ip forward-protocol nd
no ipv6 cef
no dot11 syslog
interface Loopback0
no shutdown
ip address 127.0.0.1 255.0.0.0
exit
interface Ethernet0/0/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet0
no shutdown
no switchport
no ip address
exit
interface FastEthernet0/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet1/0
no shutdown
no switchport
no ip address
exit
interface FastEthernet1/1
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0/0
no shutdown
no switchport
no ip address
exit
interface GigabitEthernet0/1
no shutdown
no switchport
no ip address
exit
sw-cisco-2900-0# </result>
</output>
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