0

I need to know if there are any tools that can take .yang file as an input and return all the XPaths that will be present. (I tried pyang, but I couldn't find any option to convert to XPath)

For example:
if .yang file is :
-------------------------------
grouping grouping-foo {
    leaf g-foo;
    leaf g-bar;
}
container foo {
    leaf bar;
    uses grouping-foo;
}
-------------------------------

Then output should be:
-------------------------------
/foo/bar
/foo/g-foo
/goo/g-bar
-------------------------------
  • This question could be a good start: https://stackoverflow.com/questions/51986376/yang-how-to-convert-yang-schema-to-xml – Siebe Jongebloed May 24 '22 at 10:10
  • It has been a while since I've gone through pyang code, but it should be fairly easy to write a plugin that does what you want (assuming you need all possible schema node paths or all possible data node paths). All you'd really need to do is to recurse through "expanded YANG nodes" of your validated module set. If I recall correctly, a pyang statement node has a member called `i_children` where those nodes are put. Start with module nodes (if a module defines a schema tree it will have said member/attribute set), then recurse. – predi May 24 '22 at 10:26
  • Take an existing plugin as a reference. For example, the one for [tree diagrams](https://github.com/mbj4668/pyang/blob/master/pyang/plugins/tree.py). – predi May 24 '22 at 10:28
  • Thanks, creating a new plugin seems like a good option. – Prajjwal Singh May 25 '22 at 04:30

1 Answers1

0

You need to use pyang and the plugin xpath.

I started by installing pyang then i downloaded the xpath plugin and put it in a directory $HOME/pyang-plugin/

Here an example that i used on Juniper yang model

nabil@DESKTOP-8ECTID4:~/yang/vendor/juniper/22.1/22.1R1/junos/conf$ pyang  --plugindir $HOME/pyang-plugin/ -f xpath
junos-conf-access-profile@2019-01-01.yang  -p ../../common/
junos-conf-access-profile@2019-01-01.yang:10: warning: imported module "junos-common-types" not used

>>> module: junos-conf-access-profile
>>>  augment /jc:configuration:
/access-profile
/access-profile/access-profile-name
>>>  augment /jc:configuration/jc:groups:
/access-profile
/access-profile/access-profile-name
Nabil
  • 1,130
  • 5
  • 11