Open achurak opened 8 months ago
Hi achurak, apologies for the delayed response.
I believe you queried /interfaces/interface
from the device, which correctly returns a JSON list.
However, ygot doesn't support unmarshalling directly at the list level -- you must either
1) specify the list key interfaces/interface[name=foo]
, and unmarshal into the list struct, or
2) query at /interfaces
level, and unmarshal at that level. Note that this option is only available if compress=false
is used. If compress=true
is used then you must wrap the json_val
yourself with another JSON object, and unmarshal into the struct one-level higher, which in this case is root-level struct. This is highly inconvenient, and I've opened https://github.com/openconfig/ygot/issues/959 to track it.
@wenovus No worries, thank you for getting back to me! Correct, I queried /interfaces/interface
.
device.AppendInterface
to add them one at a time.json.Unmarshal
, wrap it inside a map[string]any
keyed by "interfaces" per the YANG container name, and then json.Marshal
again, and then unmarshal into the ygot struct. However I think 1. is much easier and less hacky.
I apologize in advance if it's something obvious and I'm missing it but I'm trying to do what I think is as basic as can be, simply pull information about interfaces from a cisco device using gnmi client, however I just can't unmarshal it correctly no matter what I try. It looks like the json that the cisco device returns is an array, something like this:
but the generated model expects it to be a map keyed by the interface name.
I can even remove the
[]
from the string and the unmarshaling works after that (though it doesn't recognizeethernetCsmacd
as a correct value for interface type but it's a different problem), but I feel like it's a super hacky workaround and there's gotta be a better/correct way of handling this.