yang 中默认值的条件赋值
Conditional assignment of default values in yang
我在模型中有两个属性:
- 叶协议,
- 叶端口。
我想说明:
- if protocol = 'ssh' then default port value is 22,
- if protocol = 'http' then default port value is 80,
- 等等
这个用阳字怎么表达?
YANG 中没有条件 default
值 - 对于两个具有不同值的 defaults
,您需要两个 default
语句,而单个 leaf
可能只有一个default
子语句。不过,您可以解决这个问题。也许通过使用 presence container
而不是你的协议 leaf
:
module conditional-default {
namespace "http://example.com/conditional-default";
prefix "excd";
grouping common {
leaf port {
type int32;
}
}
container config {
container ssh {
presence "If this container is present, ssh is configured.";
uses common {
refine port {
default 22;
}
}
}
container http {
presence "If this container is present, http is configured.";
uses common {
refine port {
default 80;
}
}
}
}
}
来自 RFC6020,7.5.5.:
The "presence" statement assigns a meaning to the presence of a
container in the data tree. It takes as an argument a string that
contains a textual description of what the node's presence means.
我在模型中有两个属性:
- 叶协议,
- 叶端口。
我想说明:
- if protocol = 'ssh' then default port value is 22,
- if protocol = 'http' then default port value is 80,
- 等等
这个用阳字怎么表达?
YANG 中没有条件 default
值 - 对于两个具有不同值的 defaults
,您需要两个 default
语句,而单个 leaf
可能只有一个default
子语句。不过,您可以解决这个问题。也许通过使用 presence container
而不是你的协议 leaf
:
module conditional-default {
namespace "http://example.com/conditional-default";
prefix "excd";
grouping common {
leaf port {
type int32;
}
}
container config {
container ssh {
presence "If this container is present, ssh is configured.";
uses common {
refine port {
default 22;
}
}
}
container http {
presence "If this container is present, http is configured.";
uses common {
refine port {
default 80;
}
}
}
}
}
来自 RFC6020,7.5.5.:
The "presence" statement assigns a meaning to the presence of a container in the data tree. It takes as an argument a string that contains a textual description of what the node's presence means.