ConfD是tail-f推出的配置管理开发框架,提供多种工具,针对多种标准,其中也包括了对NETCONF/YANG的支持。Tail-f已经被思科收购,所以ConfD应该说是思科的ConfD了。

安装ConfD Basic

ConfD有两个版本:Basic和Premium。其中是Basic版本免费的。可以在confd-basic看到Basic和premium的比较。Basic默认没有支持服务,不过可以在公共论坛http://discuss.tail-f.com/提问。

ConfD无法在Windows运行。可以下载其Linux版本,比如confd-basic-6.7.linux.x86_64。解压以后里面包含执行文件、库、实例代码以及文档,应有尽有。对于快速应用ConfD,也可以参考ConfD_Kick_Start_Guide

将下载的压缩包解压到一个目录,比如/opt, 然后将/opt/confd-basic-6.7/bin加入PATH列表。

What is the difference between ConfD Basic and ConfD Premium?

netconf-console

netconf-console是ConfD自带的一个开源的NETCONF客户端,在Pypi上可以找到netconf-console的包。

需要注意的是,netconf-console有一些依赖,在Ubuntu上需要安装:

sudo apt install libxml2-utils
pip install paramiko

netconf-console 使用示例:

  • netconf-console --user=admin --password=admin --get-config,执行NETCONF “get-config"操作
  • netconf-console --user=admin --password=admin -i,可以交互式编辑NETCONF RPC,比如可以在命令行里面输入<get/>

NETCONF and the ncclient

confdc

confdc用来将YANG模块文件编程生成confd内部的格式fxs,confdc一次只能编译一个文件:

confdc -c ietf-ip.yang

为了使confdc可以编译多个文件,可以将所有YANG模块文件放到一个目录,然后:

find . -exec confdc -c "{}" \;

如果不这么做,就要通过--yangpath选项来指定参数。

其他例子:

  • confdc -c example.yang -o example.fxs,指定输出文件名
  • confdc --get-info,从fxs中获取信息

confd

confd的核心是一个同名程序,也叫做confd,可以使用下面的命令启动confd

confd -v --foreground --addloadpath modules

其中:

  • -v,打印更多信息
  • --foreground,在前端运行confd
  • --addloadpath modules,加载额外的编译后的yang模块,以fxs结尾的那些。

confd还支持分阶段启动:

$ confd --stop
... Install new versions of software and fxs files ...
$ confd --start-phase0
$ server_upgrade
$ confd --start-phase1
... Start other internal daemons ...
$ confd --start-phase2

在开发场景下比较有用。

confd的数据库是以.cdb结尾的,默认在confd-basic-6.7/var/confd/cdb目录中,会初始化下面几个数据库,A.cdb C.cdb O.cdb

confd_load

confd_load是一个用来操作CDB的实用工具,用法如下:

    confd_load [options] [filename]
    confd_load -l [options] [filename...]
    confd_load -C [-R] [filename...]

使用示例

  • confd_load -m -C xmlfile:以合并的方式从xmlfile中加载静态配置
  • confd_load -m -l xmlfile:以合并的方式从xmlfile中加载动态配置
  • confd_load -o -m -l xmlfile:如果xmlfile中包含又静态数据,那么需要加上-o来剔除
  • confd_load :打印动态配置

-F可以用来打印的时候进行格式化。

Selects the format of the configuration, must be set both when loading and saving. One of XML (x), pretty XML (p), JSON (o), curly braces J-style CLI (j), C-style CLI (c), or I-style CLI (i). Default is XML.

confd_load -F j -p /nacm/groups的输出:

nacm {
    groups {
        group admin {
            user-name [ admin private ];
        }
        group oper {
            user-name [ oper public ];
        }
    }
}

confd_load -F c -p /nacm/groups的输出

nacm groups group admin
 user-name [ admin private ]
!
nacm groups group oper
 user-name [ oper public ]
!

默认情况下,confd_load一次只能加载一个命名空间下的配置,如果需要同时加载多个,需要将他们包裹在<config>标签中:

<config xmlns="http://tail-f.com/ns/config/1.0>
...
</config>

通过confd_load -F p打印出来的配置也会包含<config>标签。

confd_load还带有一个选项--ignore-initial-validation可以用来跳过初始验证:

confd_load -i -m -l init.xml

配置文件

ConfD的配置文件坐落在etc/confd/confd.conf

如果出现类似Uses CDB Operational, but CDB Operational is not enabled的错误,则需要在配置文件中将:

    <operational>
      <enabled>true</enabled>
    </operational>

如果要Confd记录服务端的NETCONF日志,需要开启以下配置:

<logs>
  <netconfLog>
    <file>
      <enabled>true</enabled>
    </file>
  </netconfLog>
</logs>
<logs> <netconfTraceLog> <enabled>

修改完后别忘了执行confd --reload重新加载配置。

yanger

除pyang外,confd中带了另一个YANG模块解析器:yanger. yanger是使用erlang编写的,也在GitHub上开源。yanger的执行速度比pyang要快,但是适配的格式比较少。

yanger示例:

yanger -t expand -f swagger example.yang -o example.json

maapi

confd中带的另一个实用工具是maapi,功能和confd_load类似,不过操作CDB更直接。

Diff between Database API and MAAPI

其他参考

(完)

2020-07-04更新

最新的ConfD-basic-7.3中,对confd_load移除了-C选项,可以用-l -m -O来替代。

对于operational的数据可以存到CDB中,并且使用talif:cdb-oper来开启持久化选项。 What is the difference between config false node without tailf:cdb-oper and config false node with tailf:cdb-oper?

值得注意的是confd_load的时候,可能需要分阶段加载configuration和operational数据,避免依赖关系出错。下面是一个错误的例子(直接执行confd_load -l -m -O data.xml):

confd_load: 618: maapi_load_config(sock, tid, flags, abspath(argv[0])) failed: external error (19): Error on line 9: missing element: client-info in /connection['AD788']/client-info

解决办法是先执行confd_load -l -m -o data.xml来加载非operational数据,然后再执行confd_load -l -m -O data.xml。或者合并执行confd_load -l -m -o -O data.xml

有些错误是因为上级节点不存在,所以需要先创建上级节点,然后再创建次级节点。 要注意XML元素是否带有空格,从而导致验证失败。

感觉对ConfD的几个命令行的具体作用尚不明晰:

  • 通过confd_cmd -h commands可以列举confd_cmd所支持的命令
  • maapi不是一个能直接使用的命令,需要指定CONFD_MAPPI_USID环境变量
  • confdc 可以指定-datastore operational来把数据强制存储到CDB的operational部分。

(更新完)

2020-07-08更新

如果遇到以下错误:

confd_load: 618: maapi_load_config(sock, tid, flags, abspath(argv[0])) failed: Error in a configuration (36): syntax error on line 2: 

有可能是因为格式不对,confd_load要求unix换行格式。

(更新完)

2021-05-20更新

YumaWorks的SDK也提供免费的基本版了: YumaProSDK Basic

尝试了以下,感觉YumaWorks使用C语言比较多,而且用了很多模板注入技术来提高C语言的表达能力。可能会有更小的内存踪迹,更适合嵌入式系统。

Looking for a NETCONF/YANG Solution?提到还有另外一个商业版的套件:NuDesign’s ndConf

(更新完)

2021-06-07更新

在Ubuntu 20.04上Confd安装的时候如果提示

REQUIRED LIBRARIES NOT FOUND

ConfD requires a version of the libcrypto.so library that could not
be found on your system:

        libcrypto.so.1.0.0 => not found

一种解决办法是自己安装libssl1.0.0 (参考https://unix.stackexchange.com/questions/283607/libraries-libcrypto-so-1-0-0-cannot-open-shared-object-file-no-such-file-or-d):

另外Ubuntu 20.04即便安装了Python,默认也没有名为python的可执行文件。一个解决办法是安装python-is-python3,参考https://askubuntu.com/questions/1272870/how-can-i-change-the-default-python-on-my-ubuntu-20-04-to-python3-8。

如果需要python2,可以安装python-is-python3。但是Python2默认不带pip,所以需要自行安装(参考https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/ ):

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py

如果是在WSL上安装,又嫌输入sudo次数多太麻烦,可以参考https://www.sindastra.de/p/679/no-sudo-password-in-wsl/。

(更新完)