【问题标题】:How to convert Yang to XPath?如何将杨转换为 XPath?
【发布时间】:2022-07-31 01:01:19
【问题描述】:

我需要知道是否有任何工具可以将 .yang 文件作为输入并返回所有将出现的 XPath。 (我试过 pyang,但找不到任何转换为​​ 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
-------------------------------

【问题讨论】:

  • 这个问题可能是一个好的开始:stackoverflow.com/questions/51986376/…
  • 自从我完成 pyang 代码以来已经有一段时间了,但是编写一个可以满足您需求的插件应该相当容易(假设您需要所有可能的模式节点路径或所有可能的数据节点路径)。您真正需要做的就是通过已验证模块集的“扩展 YANG 节点”进行递归。如果我没记错的话,一个 pyang 语句节点有一个名为 i_children 的成员,这些节点被放置在其中。从模块节点开始(如果模块定义了模式树,它将具有所述成员/属性集),然后递归。
  • 以现有插件为参考。例如,tree diagrams 的那个。
  • 谢谢,创建一个新插件似乎是个不错的选择。

标签: xml xpath ietf-netmod-yang yang


【解决方案1】:

您需要使用pyang 和插件xpath

我从安装 pyang 开始,然后我下载了 xpath 插件并将其放在目录 $HOME/pyang-plugin/

这是我在 Juniper yang 模型上使用的示例

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

【讨论】:

    猜你喜欢
    • 2019-01-29
    • 1970-01-01
    • 2013-03-21
    • 2012-11-27
    • 2017-07-23
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 2015-03-11
    相关资源
    最近更新 更多