cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3221
Views
20
Helpful
4
Replies

Exec CLI from NSO REST API for CISCO IOS-XE

santpati
Cisco Employee
Cisco Employee

I am trying to use REST API on NSO - to execute exec CLIs like reload or image copy etc.

I am using Cisco Catalyst Switch with IOS-XE OS and using IOS-XE netconf NED on NSO.

 

I am not able to find appropriate REST API call to execute this from NSO NB interface.

 

I tried to execute this using NSO CLI - which works fine :

Entering configuration mode terminal
admin@ncs(config)# devices device cat9200-sthana
admin@ncs(config-device-cat9200-sthana)# rpc rpc-license license smart { register { idtoken test-token } }

but on REST API side : what path should i use to execute this RPC ? 

 

http://127.0.0.1:8080/api/running/devices/device/cat9200-sthana/rpc/_operations
and how do i form my JSON object for this ?

 

 

1 Accepted Solution

Accepted Solutions

And using RESTCONF, here an example of a show command action (alu NED). For a NETCONF RPC is not different. Just search the path to the RPC definition and then draft your "input" parameters.

 

One tricky thing on RESTCONF that I always miss is that you do not use the prefix of a module but the module name.
 

curl -X POST \

  -H 'Authorization: Basic YWRtaW46YWRtaW4='\
  -H 'Content-Type: application/yang-data+json' \
  -H 'Postman-Token: 5ffb3be3-5556-416e-a10a-1e59e3d82cf4' \
  -H 'cache-control: no-cache' \
  -H 'password: admin' \
  -H 'username: admin' \
  -d '{ "input": { "args":"version"} }’

 

Regards,
Roque
 

View solution in original post

4 Replies 4

santpati
Cisco Employee
Cisco Employee

I tried this from REST API , but does not work.

 

 

Screen Shot 2019-02-08 at 5.28.20 PM.png

First of all, I would really recommend that you switch from the old and no longer developing proprietary REST interface to the standard RESTCONF. There are really few reasons to develop code for the non-standard REST interface these days. If you switch, you can also get help, find tools, specifications (RFC 8040) and examples a lot easier. 

 

The path you are using is wrong. Look up the rpc you are looking for in the NED you are using. A trick you can use to find out is to look in the NED's src/ncsc-out/modules/yang and see the complete path there.

 

And using RESTCONF, here an example of a show command action (alu NED). For a NETCONF RPC is not different. Just search the path to the RPC definition and then draft your "input" parameters.

 

One tricky thing on RESTCONF that I always miss is that you do not use the prefix of a module but the module name.
 

curl -X POST \

  -H 'Authorization: Basic YWRtaW46YWRtaW4='\
  -H 'Content-Type: application/yang-data+json' \
  -H 'Postman-Token: 5ffb3be3-5556-416e-a10a-1e59e3d82cf4' \
  -H 'cache-control: no-cache' \
  -H 'password: admin' \
  -H 'username: admin' \
  -d '{ "input": { "args":"version"} }’

 

Regards,
Roque
 

hello that works really we’ll just one question

 

im using iOS xr and I would like to run the following command: run ls -la /

I have tried using this d '{ "input": { "args":"run ls -la /"} }’

but no luck, I get an error

 

can you guys help me with this?