cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
794
Views
5
Helpful
1
Replies

Passing wildcards using RESTCONF to NSO

nitinkgoud
Cisco Employee
Cisco Employee

Hello,
One of my customer wants to performs a sync-from using restconf he can do the following.

ngoud@NGOUD-M-R15Y run % curl --noproxy "*" -u *****:***** "http://127.0.0.1:8080/restconf/operations/devices/device=m-nx/sync-from" -X POST -H "Content-Type: application/yang-data+json"
{
"tailf-ncs:output": {
"result": true
}
}
ngoud@NGOUD-M-R15Y run %

NSO SHELL:

admin@ncs> switch cli
admin@ncs#
System message at 2022-11-14 22:31:15...
Commit performed by admin via http using rest.
admin@ncs#

audit.log

<INFO> 14-Nov-2022::22:31:14.610 NGOUD-M-R15Y ncs[74354]: audit user: admin/0 local authentication succeeded via rest from 127.0.0.1:60417 with http, member of groups: admin
<INFO> 14-Nov-2022::22:31:14.610 NGOUD-M-R15Y ncs[74354]: audit user: admin/0 logged in via rest from 127.0.0.1:60417 with http using local authentication
<INFO> 14-Nov-2022::22:31:14.611 NGOUD-M-R15Y ncs[74354]: audit user: admin/133 assigned to groups: admin
<INFO> 14-Nov-2022::22:31:14.611 NGOUD-M-R15Y ncs[74354]: audit user: admin/133 created new session via rest from 127.0.0.1:60417 with http
<INFO> 14-Nov-2022::22:31:14.611 NGOUD-M-R15Y ncs[74354]: audit user: admin/133 RESTCONF: request with http: POST /restconf/operations/devices/device=m-nx/sync-from HTTP/1.1
<INFO> 14-Nov-2022::22:31:15.714 NGOUD-M-R15Y ncs[74354]: audit user: admin/133 terminated session (reason: normal)
<INFO> 14-Nov-2022::22:31:15.715 NGOUD-M-R15Y ncs[74354]: audit user: admin/133 RESTCONF: response with http: HTTP/1.1 /restconf/operations/devices/device=m-nx/sync-from 200 duration 1128707 ms

NSO generates 200 response.

Now the customer wants to do this for all the devices that have names stating with m, so if he uses m* it does not work.

ngoud@NGOUD-M-R15Y run % curl --noproxy "*" -u *****:***** "http://127.0.0.1:8080/restconf/operations/devices/device=m*/sync-from" -X POST -H "Content-Type: application/yang-data+json"
{
"ietf-restconf:errors": {
"error": [
{
"error-type": "application",
"error-tag": "invalid-value",
"error-message": "uri keypath not found"
}
]
}
}
ngoud@NGOUD-M-R15Y run %

audit.log

<INFO> 14-Nov-2022::22:59:40.867 NGOUD-M-R15Y ncs[74354]: audit user: admin/0 local authentication succeeded via rest from 127.0.0.1:62197 with http, member of groups: admin
<INFO> 14-Nov-2022::22:59:40.867 NGOUD-M-R15Y ncs[74354]: audit user: admin/0 logged in via rest from 127.0.0.1:62197 with http using local authentication
<INFO> 14-Nov-2022::22:59:40.868 NGOUD-M-R15Y ncs[74354]: audit user: admin/175 assigned to groups: admin
<INFO> 14-Nov-2022::22:59:40.868 NGOUD-M-R15Y ncs[74354]: audit user: admin/175 created new session via rest from 127.0.0.1:62197 with http
<INFO> 14-Nov-2022::22:59:40.868 NGOUD-M-R15Y ncs[74354]: audit user: admin/175 RESTCONF: request with http: POST /restconf/operations/devices/device=m*/sync-from HTTP/1.1
<INFO> 14-Nov-2022::22:59:40.875 NGOUD-M-R15Y ncs[74354]: audit user: admin/175 terminated session (reason: normal)
<INFO> 14-Nov-2022::22:59:40.875 NGOUD-M-R15Y ncs[74354]: audit user: admin/175 RESTCONF: response with http: HTTP/1.1 /restconf/operations/devices/device=m*/sync-from 404 duration 31869 ms

SO it looks like the query reaches NSO and get logged in audit.log but NSO generates a http 404 response code.

I have used few combinations like .* \* and \.\*

Is there is a way to accomplish passing wildcards using RESTCONF to NSO?

Thanks and regards,
Nitin

1 Reply 1

Nabsch
Spotlight
Spotlight

Hello, 

You cannot directly. Based on RFC 8040 , you are trying to execute a sync-from on device m* which doesn't exist that's why it fails.

 

You have to write an action that can perform the sync-from then send you the response. You shouldn't forget that you can have a device called m*

Here an example on how to get all device that start with N using python

for dev in  root.devices.device.filter('re-match(name,"N.*")') :
         print(f"Device name : {dev.name}")

An example of output 

 

Device name : N*
Device name : NETSIM0
Device name : NETSIM4-44
Device name : NETSIM44

 

You need to handle the exception if a sync-from fails for a device 

Best Regards,