cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1290
Views
5
Helpful
5
Replies
Beginner

RESTCONF run action with input args

I am working on a creating an action that returns some output for a certain show command. I can successfully run the command via the rest api but was wondering if it is possible to do the same via restconf and if their are any advantagaes to doing so. 

 

Also what is the correct way to find a URI path for restconf?

 

REST api curl:

 

curl -X POST \
http://localhost:8080/api/running/NDOS:action/_operations/ShowCommands \
-H 'Authorization: Basic dAAAAAAAAAAAAAA==' \
-H 'Content-Type: application/vnd.yang.operation+xml' \
-H 'Postman-Token: AAAAAAAAAAAAAAAAAAAAAAA' \
-H 'cache-control: no-cache' \
-d '<input>
<deviceName>CQ5LAB9K</deviceName>
<showCMD>show l2vpn bridge-domain brief</showCMD>
</input>
'

Which outputs the results of the custom command and its parser.

 

<output xmlns='http://example.com/NDOS'>
<result>{'CISCO_TAC': ['TEST_TAC'], 'EVPN_DHN': ['EVPN_2001'], 'Eng': ['LTE_LAB_1', 'LTE_LAB_2']}</result>
</output>

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Cisco Employee

Re: RESTCONF run action with input args

Hello,

 

Here is a comparison of REST vs RESTCONF for the same action call - notice the difference in the Content Type, as well as the URI path:

 

REST
 
curl -X POST -v -T l2lagCreate.json -H'Content-Type: application/vnd.yang.operation+json' -u admin:admin http://127.0.0.1:8080/api/operational/l2lag-api/_operations/l2lag-create-bundle
 
RESTCONF
 
curl -X POST -v -T l2lagCreate.json -H'Content-Type: application/yang-data+json' -u admin:admin http://127.0.0.1:8080/restconf/operations/l2lag-api/l2lag-create-bundle
 
ncs-l2lag-4.7.3$ cat l2lagCreate.json
{
    "input": [
      {
        "lag-id": "lag-1",
        "customer-id": "Cust-1",
        "description": "Lag-1 for Customer 1",
        "dev": [
          {
            "device": "j0",
            "interface": [
              {
                "name": "xe-1/1/1"
              }
            ]
          }
        ]
      }
    ]
}
 
-Larry

View solution in original post

5 REPLIES 5
Highlighted

Re: RESTCONF run action with input args

Hi here is an example using restconf

POST

https://<user>:<pass>@<nso-host>:8888/restconf/operations/devices/device=<nexus device>/live-status/tailf-ned-cisco-nx-stats:exec/any

Headers

Accept application/yang-data+xml

Content-Type application/yang-data+json

Body

{"input":{"args": "show run"}}

 

Thanks

Regards

Yale

Highlighted
Beginner

Re: RESTCONF run action with input args

I was able to get this working after reading the rfc and realizing that it just follows the yang model you create with the action. Also I was sending the input in XML and needed to be JSON in my case.

 

curl -X POST \
http://localhost:8080/restconf/operations/NDOS:action/ShowCommands \
-H 'Authorization: Basic dAAAAAAAAAAAAAA==' \
-H 'Content-Type: application/vnd.yang.operation+xml' \
-H 'Postman-Token: AAAAAAAAAAAAAAAAAAAAAAA' \
-H 'cache-control: no-cache' \
 -d '{
"input": {
"deviceName": "CQ5CORPLBA41",
"deviceType": "cisco-ios-xr",
"showCMD": "show l2vpn bridge-domain brief"
}
}'

Highlighted

Re: RESTCONF run action with input args

the example you have posted is using RESTAPI not RESTCONF

Highlighted
Beginner

Re: RESTCONF run action with input args

Updated. Pasted over the wrong one. The edited command works.

Highlighted
Cisco Employee

Re: RESTCONF run action with input args

Hello,

 

Here is a comparison of REST vs RESTCONF for the same action call - notice the difference in the Content Type, as well as the URI path:

 

REST
 
curl -X POST -v -T l2lagCreate.json -H'Content-Type: application/vnd.yang.operation+json' -u admin:admin http://127.0.0.1:8080/api/operational/l2lag-api/_operations/l2lag-create-bundle
 
RESTCONF
 
curl -X POST -v -T l2lagCreate.json -H'Content-Type: application/yang-data+json' -u admin:admin http://127.0.0.1:8080/restconf/operations/l2lag-api/l2lag-create-bundle
 
ncs-l2lag-4.7.3$ cat l2lagCreate.json
{
    "input": [
      {
        "lag-id": "lag-1",
        "customer-id": "Cust-1",
        "description": "Lag-1 for Customer 1",
        "dev": [
          {
            "device": "j0",
            "interface": [
              {
                "name": "xe-1/1/1"
              }
            ]
          }
        ]
      }
    ]
}
 
-Larry

View solution in original post