以编程方式构造netconf edit-config请求[关闭]

问题描述 投票:-2回答:1

我正在尝试以编程方式为yang架构配置对象构建netconf edit-config请求。目前我手动构建这个xml字符串。有没有办法以编程方式执行此操作?我正在使用golang

例如,我正在尝试发送bgp配置元素的edit-config请求,如模式bgp-config.yang中所定义:

module bgp-config {
    namespace "http://exnet.com/bgp-config";
    prefix bgp-config;
    import ietf-inet-types { prefix inet; }
    import tailf-common { prefix tailf; }
    import ietf-yang-types { prefix yang; }
    import ietf-bgp-types { prefix bgp-types; }
    import ietf-bgp-multiprotocol { prefix bgp-mp; }
    import openconfig-routing-policy { prefix rpol; }
    import myietf-routing {prefix rt;}
    revision "2016-04-07" {
    description "Revisied on 2016-04-07.";
    }
    augment "/rt:router"
    {
 list bgp {
     //presence "Container for BGP protocol hierarchy";
     //tailf:cli-add-mode;
     tailf:info "Top-level configuration and state for the BGP router";
     tailf:cli-full-no;
     tailf:cli-suppress-list-no;
     key "local-as";
     max-elements 1;
     description
         "Top-level configuration and state for the BGP router";
     uses bgp_config;
     uses bgp-graceful-restart;
     uses bgp-mp:bgp-route-selection-options;
     //tailf:cli-suppress-no;
     container afi-safis {
         tailf:cli-drop-node-name;
         description
             "Address family specific configuration";
         uses bgp-mp:bgp-common-afi-safi-list;
     }

          }
}

我有这个代码片段来向netconf服务器发送bgp配置元素的edit-config请求:

var s *netconf.Session 
localas := 888 
xmlstr := `<edit-config>
        <target><candidate/></target>
         <config>
         <router xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">
         <bgp xmlns="http://exnet.com/bgp-config">
         <local-as>` + strconv.Itoa(localas) + `</local-as>
         </bgp>
      </router>
     </config>
    </edit-config>`
 NetConfSendRPC(s, xmlstr)
 xmlstr = "<commit/>"
 NetConfSendRPC(s, xmlstr)
 s.Close()

我的问题是如何以编程方式构造xml字符串以发送所有配置元素的edit-config。第一步是从yang模式生成xml标记的结构(这是我需要帮助/指针的地方)然后我可以使用xml marshal方法来构造请求。对第一步的任何建议都会有所帮助。谢谢。

xml go ietf-netmod-yang ietf-netconf
1个回答
2
投票
  1. 将XML文档映射到标记的结构。
  2. 创建一个表示所需配置的结构。
  3. 使用xml.MarshalIndent对结构进行元素化(参见示例)。

另见https://github.com/Juniper/go-netconf

© www.soinside.com 2019 - 2024. All rights reserved.