直接方法使用sysrepo设置包含LIST的yang模型

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>

> 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值