Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] From ygot gostruct or emittedJSON to gNMI Set Update #962

Closed
pedroaston opened this issue Apr 1, 2024 · 6 comments
Closed

[Question] From ygot gostruct or emittedJSON to gNMI Set Update #962

pedroaston opened this issue Apr 1, 2024 · 6 comments

Comments

@pedroaston
Copy link

Hey there! I've been exploring the ygot package and played with generated code from the Cisco interfaces yang models. I manage to create manually (for now) with the code below, a perfect replica of the json model inside the router.

Code used to manually assemble:
image

Resulting JSON:
image

From the examples and docs it seems the package currently does not transform a goStruct generated from the Yang into a gNMI SetRequest Update correct? Is there another openconfig package to tackle this issue?

Thanks 😄

@robshakir
Copy link
Contributor

There isn't a standard package here because there are different ways that one might need to apply the config. For example, maybe you want to update the config vs. replace it -- or include other parameters.

You can just take the JSON that is output by ygot and provide it to the device as a json_ietf_val in the gNMI TypedValue message.

The ygnmi library has some helpers around using gNMI, particularly with OpenConfig schemas, and would also provide some primitives around update and replace.

@wenovus
Copy link
Collaborator

wenovus commented Apr 1, 2024

Agreed with Rob. ygnmi is very useful if you're interested in a lot of interactions with a gNMI server.

@ejbrever
Copy link

ejbrever commented Apr 1, 2024

FYI, I know it's not the question you asked, but because I was looking at the similar Cisco schema recently, just wanted to share that you might want to use the helper funcs ygot supports, which really help with readability. I think roughly your code above would be the following (no long struct names, no initializing vars, you can work down the hierarchy of the model, and if you get autocomplete working on the generated structs, this just takes a few minutes to type out).

i := device.GetOrCreateInterfaces().GetOrCreateInterface("Loopback666")
i.Description = ygot.String("test_gnmi_ygot_pipeline")

ipv4 := i.GetOrCreateIpv4().GetOrCreateAddresses().GetOrCreateAddress()
ipv4.Address = ygot.String("1.1.1.1")
ipv4.Netmask = ygot.String("255.255.255.255")

ipv6 := i.GetOrCreateIpv6().GetOrCreateAddresses().GetOrCreateIpv6Address("9000::1")
ipv6.PrefixLength = ygot.Uint8(128)
ipv6.Zone = ygot.String("0")

You might just need to add the necessary flags for ygot to generate this. (i.e. -generate_append -generate_getters)

@pedroaston
Copy link
Author

Hey! Thank you all for the feedback 👍

I followed @robshakir's hint and placed the interface yang leaf in as a TypedValue. The below snippet configures a loopback interface on a router successfully.
image
Still need to manually assemble the yang leaf path.

@wenovus I saw on another issue that you were looking into developing path struct generation without compressed paths. Have you abandoned it?

I haven't properly checked ygnmi helpers. I may give it a better look in the future.

PS: For question/discussion-related topics is there an openconfig slack or forum like space?

@wenovus
Copy link
Collaborator

wenovus commented Apr 3, 2024

Do you have a link to the issue? I probably need to update it if it's still an open issue.

ygnmi already supports uncompressed structs as of this commit: openconfig/ygnmi@5559c6e

The path struct generation in ygot is deprecated. It is planned to be deleted prior to v1 release (work which is currently on-pause).

Per the OpenConfig website GitHub issues are the preferred channel: https://openconfig.net/about/contribute/. There is a also a public forum linked there but it's lower volume than the GitHub repos.

@pedroaston
Copy link
Author

Hey! It was issue #888. However, now that I've read it again, you did mention that path struct generation was implemented in ygnmi in that issue. I will check the path struct generation there.

Closing this one. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants