问题
I have two properties in a model:
- leaf protocol,
- leaf port.
I want to specify that:
- if protocol = 'ssh' then default port value is 22,
- if protocol = 'http' then default port value is 80,
- etc.
How do I express this in yang ?
回答1:
There are no conditional default
values in YANG - you need two default
statements for two defaults
with different values, and a single leaf
may only have one default
substatement. You can work around this, however. Perhaps by using a presence container
instead of your protocol 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;
}
}
}
}
}
From 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.
来源:https://stackoverflow.com/questions/35907872/conditional-assignment-of-default-values-in-yang