cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
499
Views
10
Helpful
1
Replies

RESTCONF return formats

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yfherzog
Cisco Employee

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>&#13;
tailfned police cirmode&#13;
no service password-encryption&#13;
aaa accounting delay-start&#13;
no cable admission-control preempt priority-voice&#13;
no cable qos permission create&#13;
no cable qos permission update&#13;
no cable qos permission modems&#13;
ip source-route&#13;
no ip gratuitous-arps&#13;
no ip cef&#13;
ip finger&#13;
no ip http server&#13;
no ip http secure-server&#13;
no ip forward-protocol nd&#13;
no ipv6 cef&#13;
no dot11 syslog&#13;
interface Loopback0&#13;
 no shutdown&#13;
 ip address 127.0.0.1 255.0.0.0&#13;
exit&#13;
interface Ethernet0/0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet1/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet1/1&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0/1&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
sw-cisco-2900-0# </result>
</output>

View solution in original post

1 REPLY 1
yfherzog
Cisco Employee

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>&#13;
tailfned police cirmode&#13;
no service password-encryption&#13;
aaa accounting delay-start&#13;
no cable admission-control preempt priority-voice&#13;
no cable qos permission create&#13;
no cable qos permission update&#13;
no cable qos permission modems&#13;
ip source-route&#13;
no ip gratuitous-arps&#13;
no ip cef&#13;
ip finger&#13;
no ip http server&#13;
no ip http secure-server&#13;
no ip forward-protocol nd&#13;
no ipv6 cef&#13;
no dot11 syslog&#13;
interface Loopback0&#13;
 no shutdown&#13;
 ip address 127.0.0.1 255.0.0.0&#13;
exit&#13;
interface Ethernet0/0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet1/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface FastEthernet1/1&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0/0&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
interface GigabitEthernet0/1&#13;
 no shutdown&#13;
 no switchport&#13;
 no ip address&#13;
exit&#13;
sw-cisco-2900-0# </result>
</output>

View solution in original post