08-01-2017 05:28 AM - last edited on 03-25-2019 01:10 PM by ciscomoderator
How to replace(override) old value(s) in a leaf-list with new value(s) during every update?
Tried below,
leaf-list <leaf-name>
{
----
tailf:cli-replace-all;
------}
But this is working only with cli, but not with REST call. With REST call, new values are getting appended to old values instead of overriding. Please suggest how to achieve this through REST.
08-01-2017 06:00 AM
Is this YANG part of a device YANG model? Assuming so, which NED?
Are you interested to replace all values in a single go because the device requires this behavior for proper operation? If so, it is up to the NED to do this correctly. There is no way to control this behavior from the NB side (e.g. REST/RESTCONF client), and there shouldn't be.
08-01-2017 06:10 AM
I need this for service yang model.
NED(cisco-ios 5.4) is having this constraint already. i.e., able to override the old values with new, if we verify in NED directly.
But as service model is appending the new values with old values, it is passing all the values(old and new) to the NED.
08-01-2017 06:19 AM
Are you using PUT, POST or PATCH?
http - What is the difference between PUT, POST and PATCH? - Stack Overflow
It seems like PUT is what you need.
-Don
08-01-2017 06:28 AM
I am using PATCH, not very sure if I can use PUT in our context. I will check on this.
08-01-2017 06:36 AM
It is not allowed to use PUT. It might be as with PUT, we have to provide all the details again, not just only the parameter that we intended to update.
Got following response:
HTTP/1.1 405 Method Not Allowed
Server:
Allow: DELETE, GET, HEAD, PATCH
Allow: GET, POST, OPTIONS, HEAD
Content-Length: 0
Content-Type: text/html
08-01-2017 07:06 AM
I was able to make PUT work with NSO – see my example below – attaching my Yang model for reference.
Vlans is a leaf-list.
curl -i -u admin:admin \
http://localhost:8080/api/running/aws/Sheraton/site/Lake_Shore_Drive/vlans \
-X PUT \
-H "Content-Type: application/vnd.yang.data+json" \
-d '{
"aws:vlans": ["99"]
}'
08-01-2017 06:36 AM
If you have a complex RESTCONF payload with some things being added/updated, others removed etc, you may need to use the YANG Patch media type: https://tools.ietf.org/html/rfc8072 That will allow you to replace the contents of the service model leaf-list, for example, while doing other things to other content.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide