cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3303
Views
0
Helpful
4
Replies

how to get configurations which NSO send to device.

haofan
Level 4
Level 4

Hi expert,

     I use once rest api request to config static route, interface and so on. I use xml as rest payload. I want to get device cli configurations that NSO send to device. I know can use show command to get device cli command configurations, but sometime this method need take much  more time, so my question is that whether NSO could expose rest API that could get configurations whitch NSO send to device for every REST request ?

1 Accepted Solution

Accepted Solutions

here is a case using XR device (netsim)

(equivalent of NSO "set devices device xr0 config: "

I used this command w/ different settings (native/cli/xml)

curl -i -u admin:admin \

http://localhost:8080/api/running/devices/device/xr0/config/\

cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=native \

-X PUT \

-H "Content-Type: application/vnd.yang.data+json" \

-d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

netsim: (original device config)

--------------

xr0# show running-config interface GigabitEthernet 0/0/0/2

interface GigabitEthernet 0/0/0/2

ipv4 address 10.2.2.2 1.1.1.1/30

exit

xr0#

Now... using REST... and "native"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin \

> http://localhost:8080/api/running/devices/device/xr0/config/\

> cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=native \

> -X PUT \

> -H "Content-Type: application/vnd.yang.data+json" \

> -d '

> {

>   "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

> }'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:10:20 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 194

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"native": {

"device": [

{"name":"xr0"

,"data":"\ninterface GigabitEthernet 0/0/0/2\n no ipv4 address 10.2.2.2 1.1.1.1/30\n ipv4 address 10.4.4.4 1.1.1.1/30\nexit\n"}

]

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Now... using REST... and "cli"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin http://localhost:8080/api/running/devices/device/xr0/config/cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=cli -X PUT -H "Content-Type: application/vnd.yang.data+json" -d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:10:50 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 458

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"cli": {

"local-node": {

"data":" devices {\n     device xr0 {\n         config {\n             cisco-ios-xr:interface {\n                 GigabitEthernet 0/0/0/2 {\n                     ipv4 {\n                         address {\n-                            ip 10.2.2.2;\n+                            ip 10.4.4.4;\n                         }\n                     }\n                 }\n             }\n         }\n     }\n }\n"}

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Now... using REST... and "xml"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin http://localhost:8080/api/running/devices/device/xr0/config/cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=xml -X PUT -H "Content-Type: application/vnd.yang.data+json" -d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:11:04 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 341

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"result-xml": {

"local-node": {

"data":"<devices xmlns=\"http://tail-f.com/ns/ncs\"><device><name>xr0</name><config><interface xmlns=\"http://tail-f.com/ned/cisco-ios-xr\"><GigabitEthernet><id>0/0/0/2</id><ipv4><address><ip>10.4.4.4</ip></address></ipv4></GigabitEthernet></interface></config></device></devices>"}

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Hope that helps...

Cheers

gregg

View solution in original post

4 Replies 4

gschudel
Cisco Employee
Cisco Employee

From reading the question, I assume you're trying to create a service-instance via REST, but would like to invoke "commit dry-run" and then select the outformat?

If this is the case, and assuming you can make the service-create REST call (with data in-line, from a file, XML or JSON -- makes no difference), just add the dryrun...

Here is an example REST call (XML from file), with dryrun=native


  curl -s -u admin:admin -X POST -T srvcExm1.xml http://127.0.0.1:8080/api/running/services?dryrun=native


you should be able to select native, cli or xml


you can find details at:

./nso-4.5.1.1/src/ncs/yang

tailf-ncs-services.yang

hope this helps

gregg

Hi gschudel,

     Thanks  for your replying, I doesn't use service rest api. I use device level rest api,  it looks like could use the same methods to get configurations. Example as below.

admin@ncs(config-fiber-node)# commit dry-run outformat native

native {

    device {

        name e8ba21ae-a0c8-344e-af08-32ec1dc79be8

        data ! Generated offline

             cable fiber-node 2

              downstream Downstream-Cable 7/0/0

              downstream sg-channel 0 15 downstream-Cable 7/0/0 rf-channel 0 15

              service-group managed md 0 Cable 7/0/0

              service-group profile tfchan_SG

    }

}

here is a case using XR device (netsim)

(equivalent of NSO "set devices device xr0 config: "

I used this command w/ different settings (native/cli/xml)

curl -i -u admin:admin \

http://localhost:8080/api/running/devices/device/xr0/config/\

cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=native \

-X PUT \

-H "Content-Type: application/vnd.yang.data+json" \

-d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

netsim: (original device config)

--------------

xr0# show running-config interface GigabitEthernet 0/0/0/2

interface GigabitEthernet 0/0/0/2

ipv4 address 10.2.2.2 1.1.1.1/30

exit

xr0#

Now... using REST... and "native"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin \

> http://localhost:8080/api/running/devices/device/xr0/config/\

> cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=native \

> -X PUT \

> -H "Content-Type: application/vnd.yang.data+json" \

> -d '

> {

>   "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

> }'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:10:20 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 194

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"native": {

"device": [

{"name":"xr0"

,"data":"\ninterface GigabitEthernet 0/0/0/2\n no ipv4 address 10.2.2.2 1.1.1.1/30\n ipv4 address 10.4.4.4 1.1.1.1/30\nexit\n"}

]

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Now... using REST... and "cli"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin http://localhost:8080/api/running/devices/device/xr0/config/cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=cli -X PUT -H "Content-Type: application/vnd.yang.data+json" -d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:10:50 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 458

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"cli": {

"local-node": {

"data":" devices {\n     device xr0 {\n         config {\n             cisco-ios-xr:interface {\n                 GigabitEthernet 0/0/0/2 {\n                     ipv4 {\n                         address {\n-                            ip 10.2.2.2;\n+                            ip 10.4.4.4;\n                         }\n                     }\n                 }\n             }\n         }\n     }\n }\n"}

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Now... using REST... and "xml"

GSCHUDEL-M-61C2:LabDir45 gschudel$ curl -i -u admin:admin http://localhost:8080/api/running/devices/device/xr0/config/cisco-ios-xr:interface/GigabitEthernet/0%2f0%2f0%2f2/ipv4/address/ip?dryrun=xml -X PUT -H "Content-Type: application/vnd.yang.data+json" -d '

{

  "tailf-ned-cisco-ios-xr:ip": "10.4.4.4"

}'

HTTP/1.1 200 OK

Server:

Date: Mon, 11 Dec 2017 20:11:04 GMT

Last-Modified: Mon, 11 Dec 2017 20:09:39 GMT

Cache-Control: private, no-cache, must-revalidate, proxy-revalidate

Etag: 1513-22979-621847

Content-Length: 341

Content-Type: text/json

Vary: Accept-Encoding

Pragma: no-cache

{"dryrun-result": {

"result-xml": {

"local-node": {

"data":"<devices xmlns=\"http://tail-f.com/ns/ncs\"><device><name>xr0</name><config><interface xmlns=\"http://tail-f.com/ned/cisco-ios-xr\"><GigabitEthernet><id>0/0/0/2</id><ipv4><address><ip>10.4.4.4</ip></address></ipv4></GigabitEthernet></interface></config></device></devices>"}

}

}

}

GSCHUDEL-M-61C2:LabDir45 gschudel$

Hope that helps...

Cheers

gregg

Thanks.  Got it.