ygot
ygot copied to clipboard
Does ygot support widlcard in a path ?
I would like to know if ygot supports wildcard in a path when it retrieves a node from the config tree?
It looks there is a PR already merged for that but I am wondering why it doesn't work for us?
For example:
gnmi_cli -address localhost:10161 -get \
-proto "path: <elem: <name: 'system'> elem: <name: 'openflow'> elem: <name: '*'>>" \
-timeout 5s -alsologtostderr \
-client_crt $ONOS_SIMULATORS_ROOT/pkg/certs/client1.crt \
-client_key $ONOS_SIMULATORS_ROOT/pkg/certs/client1.key \
-ca_crt $ONOS_SIMULATORS_ROOT/pkg/certs/onfca.crt;;
It's difficult to debug this with insight into your code, but you may want to check that you're using the right options. Handling wildcards is an option handed to GetNodes: https://github.com/openconfig/ygot/blob/master/ytypes/node.go#L333
Thanks for your response. I didn't know about that. I will take a look.
@robshakir I got the latest release and go.mod file is updated accordingly but it looks like it still cannot find that prototype:
have (*yang.Entry, ygot.ValidatedGoStruct, *gnmi.Path, ytypes.GetNodeOpt)
want (*yang.Entry, ygot.GoStruct, *gnmi.Path)
I think it was because I was trying to use the experimental version.
@robshakir
We are using this function in our code:
node, stat := ygotutils.GetNode(s.model.schemaTreeRoot, s.config, &path)
I tried to use the one in the ytypes but it looks like that is not compatible with this one in terms of type casting. I mean the return values are different. For example, after changing our code to use the new one, the following line doesn't work:
nodeStruct, _ := node.(ygot.GoStruct)
Please advise if those changes are possible at all.
There is no intention to make the experimental and non-experimental versions of this code compatible with each other. The return type from the public API version is a TreeNode - which has the interface{} type in its return value. This is documented in the GoDoc and the comments in the ytypes/node.go file -- please take a look there, it should be relatively trivial to refactor here.
Thanks. I will try it.
@robshakir It was a long time ago that I asked this question and I couldn't find time to do refactoring. I started to do some refactoring and I changed the code this way:
opts := make([]ytypes.GetNodeOpt, 1)
opts[0] = &ytypes.GetHandleWildcards{}
var err error
node, err := ytypes.GetNode(s.model.schemaTreeRoot, s.config, fullPath, opts[0])
if isNil(node) || err != nil {
return nil, err
}
but when I run the above example, I am getting this error:
E1011 19:06:14.449135 45324 gnmi_cli.go:180] target returned RPC error for Get("path:<elem:<name:\"system\" > elem:<name:\"openflow\" > elem:<name:\"*\" > > "): rpc error: code = InvalidArgument desc = no match found in *gostruct.OpenconfigSystem_System_Openflow, for path elem:<name:"*" >
I don't see any test case for wildcard. Have you tested it before?
Thanks, Adib
If my understanding is correct, for the above case this function is called: https://github.com/openconfig/ygot/blob/master/ytypes/node.go#L92 which does not handle wildcard. I am wondering what types of wildcard path you support in ygot?
Thanks, Adib
Hi guys. Any update on this? I'm unable to make it work.
Currently, I believe our support for wildcards is just for wildcards in the key of a list, rather than for path elements. Such support could be added, but I don't think we've had significant demand for it. I'd be happy to help with a contribution to add it to the code base :-)