Giter VIP home page Giter VIP logo

Comments (3)

wenovus avatar wenovus commented on August 24, 2024

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 #959 to track it.

from ygot.

achurak avatar achurak commented on August 24, 2024

@wenovus No worries, thank you for getting back to me! Correct, I queried /interfaces/interface.

  1. 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.
  2. Do I need to unmarshal it into a generic, wrap it and then unmarshal into the ygot struct?

from ygot.

wenovus avatar wenovus commented on August 24, 2024
  1. 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.
  2. You can 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.

from ygot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.