Comments (3)
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
- specify the list key
interfaces/interface[name=foo]
, and unmarshal into the list struct, or - query at
/interfaces
level, and unmarshal at that level. Note that this option is only available ifcompress=false
is used. Ifcompress=true
is used then you must wrap thejson_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 #959 to track it.
from ygot.
@wenovus No worries, thank you for getting back to me! Correct, I queried /interfaces/interface
.
- Do I understand correctly that the first way will only query a single interface instead of a list of all interfaces? I believe I've actually tried that and Cisco still returns an array but with a single interface/object inside it.
- Do I need to unmarshal it into a generic, wrap it and then unmarshal into the ygot struct?
from ygot.
- Looking more, I think what Cisco has might be reasonable (as this is ambiguous in the gNMI spec), since in general it's possible to specify wildcards in queries, so it would be confusing if in the case that all list attributes are specified, a JSON object is returned rather than a list. One way to work around this is to loop through each JSON list element, unmarshal separately, and then call
device.AppendInterface
to add them one at a time. - You can
json.Unmarshal
, wrap it inside amap[string]any
keyed by "interfaces" per the YANG container name, and thenjson.Marshal
again, and then unmarshal into the ygot struct. However I think 1. is much easier and less hacky.
from ygot.
Related Issues (20)
- Make sure CI runs `go mod tidy` and notices no diffs.
- ygot.diff seems slow
- ytypes.GetNode consumes more CPU & memory than the deprecated util.GetNode
- how to resolve the dependency for gribi HOT 2
- Diff api does generate deletes for leaf list values HOT 6
- Can enum preserve their defined values while converting yang to gostruct using openconfig/ygot\@v0.25.4/generator/generator.go ? HOT 3
- ygot.Diff don't respect presence containers HOT 9
- Mandatory module name in the generated struct names HOT 3
- Preserve YANG elements order when generating structs HOT 1
- Doesn't choice and case statement in YANG result in oneof fields in proto? HOT 2
- ygot Validate error, when yang leaf type is union
- When will ygot have support for bits datatype for yang to go conversion HOT 2
- Allow ytypes.SetNode on intermediate nodes in compressed mode
- Identity Support in Ygot HOT 1
- Union field has nil value after xml.Unmarshal HOT 6
- [Question] From ygot gostruct or emittedJSON to gNMI Set Update HOT 6
- ytypes.Unmarshal() treating 50 as a float64 even though I am converting 50 to string before unmarshalling HOT 7
- How to set LeafrefOptions IgnoreMissingData for UnmarshalSetRequest HOT 2
- Can't generate OC-YANG network-instance HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ygot.