且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

YANG:如何在没有密钥的情况下为嵌套列表配置数据建模

更新时间:2022-11-03 14:17:05

RFC7950 ,7.8.2.列表的关键"声明

"key"语句,如果列表表示,则必须存在 配置,否则可以存在,将a作为参数 指定一个或多个叶子的以空格分隔的列表的字符串 此列表的标识符.叶标识符不得再出现 不止一次按键.每个这样的叶子标识符必须引用一个 列表的子叶.可以在以下位置直接定义叶子 列表的子陈述或列表中使用的分组.

The "key" statement, which MUST be present if the list represents configuration and MAY be present otherwise, takes as an argument a string that specifies a space-separated list of one or more leaf identifiers of this list. A leaf identifier MUST NOT appear more than once in the key. Each such leaf identifier MUST refer to a child leaf of the list. The leafs can be defined directly in substatements to the list or in groupings used in the list.

键中指定的所有叶子的组合值用于 唯一标识列表项.必须为所有关键叶子赋予值 创建列表条目时.因此,密钥中的任何默认值 叶子或其类型将被忽略.广告中的任何强制性"陈述 关键叶子将被忽略.

The combined values of all the leafs specified in the key are used to uniquely identify a list entry. All key leafs MUST be given values when a list entry is created. Thus, any default values in the key leafs or their types are ignored. Any "mandatory" statements in the key leafs are ignored.

列出建模配置数据(无论是否嵌套)必须具有键的列表.无法解决此问题,因为每个配置列表实例必须是唯一可识别的,以便像instance-identifiers这样的结构可以按预期工作.如果没有密钥,您将很难告诉设备修改(甚至只是获取)配置中的特定条目.因此,您建议做的事情是无法实现的-这不是YANG的方式.

Lists that model configuration data (whether nested or not) must have a key. There is no way around this, because each configuration list instance must be uniquely identifiable, so that constructs like instance-identifiers work as expected. You would have a hard time telling a device to modify (or even simply obtain) a specific entry in your configuration, if there were no keys. What you are proposing to do is therefore not achievable - it is not the YANG way of things.

只有状态数据(config false;)列表可能没有键,因为它们不必以标准方式进行修改-它们的实例化/修改/删除由设备的实现细节控制.

Only state data (config false;) lists may exist without keys because they do not have to be modified in a standard way - their instantiation/modification/removal is governed by implementation details of a device.

此外,您已经在示例中使用了键. "acl1"和"acl2"显然是"acl"列表的实例,其键名已编码为它们的名称.

Besides, you are already using keys in your example. The "acl1" and "acl2" are clearly instances of an "acl" list, which have their key encoded into their name.