gnmic icon indicating copy to clipboard operation
gnmic copied to clipboard

in-line update using implicit type not working with YANG list

Open sanooprajan opened this issue 1 year ago • 8 comments

I am trying to do a "set" operation using in-line update and implicit type using both --update-path and --update-value flags as below for a path that is a yang list not a leaf. But it fails.

gnmic set --update-path --update-value

however if i do the update with a value from JSON using both--update-file flag for the value and --update-path for the path, it works. Looks like it is not able to parse a list in command line. is this a bug ?

sanooprajan avatar Oct 25 '24 13:10 sanooprajan

without logs it is impossible to tell you can use prototext or protojson output format to see the raw values sent to the target

hellt avatar Oct 25 '24 13:10 hellt

Also, what kind of error do you get back?

karimra avatar Oct 26 '24 07:10 karimra

gnmic --insecure set --update-path /interfaces/interface[name=et-0/0/4]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=11.11.11.1] --update-value 11.11.11.1 --log --format protojson

2024/10/28 14:54:30.290072 [gnmic] version=0.38.2, commit=7b315880, date=2024-07-26T00:31:56Z, gitURL=https://github.com/openconfig/gnmic, docs=https://gnmic.openconfig.net 2024/10/28 14:54:30.290109 [gnmic] using config file "" 2024/10/28 14:54:30.290307 [gnmic] adding target {"name":"10.92.70.138:9339","address":"10.92.70.138:9339","username":"root","password":"****","timeout":10000000000,"insecure":true,"skip-verify":false,"buffer-size":100,"retry-timer":10000000000,"log-tls-secret":false,"gzip":false,"token":""} 2024/10/28 14:54:30.290744 [gnmic] sending gNMI SetRequest: prefix='', delete='[]', replace='[]', update='[path:{elem:{name:"interfaces"} elem:{name:"interface" key:{key:"name" value:"et-0/0/4"}} elem:{name:"subinterfaces"} elem:{name:"subinterface" key:{key:"index" value:"0"}} elem:{name:"ipv4"} elem:{name:"addresses"} elem:{name:"address" key:{key:"ip" value:"11.11.11.1"}}} val:{json_val:""11.11.11.1""}]', extension='[]' to 10.92.70.138:9339 2024/10/28 14:54:30.291608 [gnmic] creating gRPC client for target "10.92.70.138:9339" 2024/10/28 14:54:30.592317 [gnmic] target "10.92.70.138:9339" set request failed: target "10.92.70.138:9339" SetRequest failed: rpc error: code = InvalidArgument desc = syntax error, expecting "@"; target "10.92.70.138:9339" set request failed: target "10.92.70.138:9339" SetRequest failed: rpc error: code = InvalidArgument desc = syntax error, expecting "@"; Error: one or more requests failed

sanooprajan avatar Oct 28 '24 15:10 sanooprajan

is this something that you requested for ? Let me know if you need something else.

sanooprajan avatar Oct 30 '24 11:10 sanooprajan

please format the code snippet with triple backticks

```
your output goes here
```

And I believe you're not providing the expected inline value, your path /interfaces/interface[name=et-0/0/4]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=11.11.11.1] points to a list element, not just a plain value. you should consider using json/yaml file and put your interface config there.

To see how to use gnmic with openconfig paths you can check this resource.

hellt avatar Nov 06 '24 09:11 hellt

gnmic --insecure set --update-path /interfaces/interface[name=et-0/0/4]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=11.11.11.1] --update-value 11.11.11.1 --log --format protojson

2024/10/28 14:54:30.290072 [gnmic] version=0.38.2, commit=7b315880, date=2024-07-26T00:31:56Z, gitURL=https://github.com/openconfig/gnmic, docs=https://gnmic.openconfig.net/ 2024/10/28 14:54:30.290109 [gnmic] using config file "" 2024/10/28 14:54:30.290307 [gnmic] adding target {"name":"10.92.70.138:9339","address":"10.92.70.138:9339","username":"root","password":"****","timeout":10000000000,"insecure":true,"skip-verify":false,"buffer-size":100,"retry-timer":10000000000,"log-tls-secret":false,"gzip":false,"token":""} 2024/10/28 14:54:30.290744 [gnmic] sending gNMI SetRequest: prefix='', delete='[]', replace='[]', update='[path:{elem:{name:"interfaces"} elem:{name:"interface" key:{key:"name" value:"et-0/0/4"}} elem:{name:"subinterfaces"} elem:{name:"subinterface" key:{key:"index" value:"0"}} elem:{name:"ipv4"} elem:{name:"addresses"} elem:{name:"address" key:{key:"ip" value:"11.11.11.1"}}} val:{json_val:""11.11.11.1""}]', extension='[]' to 10.92.70.138:9339 2024/10/28 14:54:30.291608 [gnmic] creating gRPC client for target "10.92.70.138:9339" 2024/10/28 14:54:30.592317 [gnmic] target "10.92.70.138:9339" set request failed: target "10.92.70.138:9339" SetRequest failed: rpc error: code = InvalidArgument desc = syntax error, expecting "@"; target "10.92.70.138:9339" set request failed: target "10.92.70.138:9339" SetRequest failed: rpc error: code = InvalidArgument desc = syntax error, expecting "@"; Error: one or more requests failed

@hellt It works if i use json, the problem is with in-line update. Are you saying with in-line update we cant have list values?

sanooprajan avatar Nov 06 '24 10:11 sanooprajan

you often can, but you will have to provide the json string inline, and escape all the characters that would otherwise mean an element delimiter, for instance.

inline values are good for changing a single value (bool, str, int), but not great for json objects

hellt avatar Nov 06 '24 10:11 hellt

@hellt Is it possible to have an enhancement and extend it to list value update also ? I was using the templated way of config push like below. gnmic set --request-file <template1> --request-file <template2> --request-vars <vars_file> Can it take json object as well?

sanooprajan avatar Nov 06 '24 14:11 sanooprajan