libyang icon indicating copy to clipboard operation
libyang copied to clipboard

YANG extension nodes paths

Open peckato1 opened this issue 2 years ago • 1 comments

Hello,

I was recently trying to work with YANG nodes defined in extension instance. I was looking at this libyang unit test and I don't understand the format of the path for the lyd_new_path call. Why can't I use absolute path to the z leaf, i.e., /ext:c/z? The return is then LY_EVALID with a log message Not found node "c" in path.

Also, documentation of lyd_new_path that * If creating data nodes defined inside an extension instance, use ::lyd_new_ext_path(). which is not entirely true according to this paragraph which states that only first node must be created using the lyd_new_ext_* functions.

peckato1 avatar Jul 26 '23 11:07 peckato1

Why can't I use absolute path to the z leaf, i.e., /ext:c/z?

What if the module ext also defined

container c {
  leaf z {
    type string;
  }
}

You would then get an ambiguity, hence the special functions. The exact extension instance is required because you may even have several extension instances with the same data nodes.

If creating data nodes defined inside an extension instance, use ::lyd_new_ext_path().

It does not say you must use the function for all the nodes but you can :)

michalvasko avatar Aug 07 '23 12:08 michalvasko