直接方法使用sysrepo设置包含LIST的yang模型
yang模型使用RFC7950中给的例子,container中包含LISTmodule example-a {yang-version 1.1;namespace urn:example:a;prefix a;container a {list b {key id;leaf id {type string;}notification down {leaf reason {
·
yang模型
- 使用RFC7950中给的例子,container中包含LIST
module example-a {
yang-version 1.1;
namespace urn:example:a;
prefix a;
container a {
list b {
key id;
leaf id {
type string;
}
notification down {
leaf reason {
type string;
}
}
action reset {
input {
leaf delay {
type uint32;
}
}
output {
leaf result {
type string;
}
}
}
}
}
notification failure {
leaf b-ref {
type leafref {
path "/a/b/id";
}
}
}
}
- 安装到sysrepo
root@bfa784c0263a:~/netconf_src/bak_sysrepo/build/examples# sysrepoctl -i example-a.yang
root@bfa784c0263a:~/netconf_src/bak_sysrepo/build/examples# sysrepoctl -l | grep example-a
example-a | | I | root:root | 600 | |
root@bfa784c0263a:~/netconf_src/bak_sysrepo/build/examples#
运行netopeer2
- 终端1首先运行netopeer2-server
root@bfa784c0263a:~/netconf_src/bak_sysrepo/build/examples# netopeer2-server -d -v2
- 另开一个终端2,创建一个xml的配置文件,向b这个list里写入两个实例
root@bfa784c0263a:~# cat config1.xml
<a xmlns="urn:example:a">
<b>
<id>1</id>
</b>
<b>
<id>2</id>
</b>
</a>
root@bfa784c0263a:~#
- 终端2启动netopeer2-cli,连接到server
root@bfa784c0263a:~# netopeer2-cli
> connect localhost
Interactive SSH Authentication
Type your password:
Password:
> edit-config --target running --config=./config1.xml
OK
>
- 终端2上使用config1.xml 来edit running config,默认是merge
> edit-config --target running --config=./config1.xml
OK
>
- 终端2上查看(指定xpath)
> get-config --source running --filter-xpath /a/b
DATA
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<a xmlns="urn:example:a">
<b>
<id>1</id>
</b>
<b>
<id>2</id>
</b>
</a>
</data>
- 终端3上创建一个config2.xml,只包含一个实例
root@bfa784c0263a:~# cat config2.xml
<a xmlns="urn:example:a">
<b>
<id>1</id>
</b>
</a>
root@bfa784c0263a:~#
- 终端2上用config2.xml来edit running config,op设置为replace
> edit-config --target running --config=./config2.xml --defop replace
OK
>
- 终端2上可以看到只剩"1"了
> get-config --source running --filter-xpath /a/b
DATA
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<a xmlns="urn:example:a">
<b>
<id>1</id>
</b>
</a>
</data>
>

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)