netmod-wg / yang-next

Feature requests for future versions of YANG
6 stars 0 forks source link

support 'dynamic default' #93

Open lllyfeng opened 5 years ago

lllyfeng commented 5 years ago

if a leaf node can not be defined a static default value, but it has a uncertain default value when it is created. For example: list foo { key name; leaf name {...} leaf type { type enumeration { enum foo1 {...} enum foo2 {...} enum foo3 {...} } } leaf value {...} leaf other {...} }

  If list 'foo' is created, if leaf named 'type''s value is foo1, the 

default value of leaf named 'value' is 10, if leaf named 'type''s value is foo2, the default value of leaf named 'value' is 20. Now YANG has no mechansim to resolve this issue. So we have to do not define default value for this leaf node, although this leaf node really has defalut value in running. It will cause some validatation is wrong, e.g. must condition:"other > value". I suggest the solution listed below:

  1. Add when statement as default's substatement.
  2. Leaf supports multi default statement.
  3. default statement's argument can be a XPATH expression.

    For example: leaf value { default 10 { when "../type = foo1"; } default 20 { when "../type = foo2"; } default "./other*2"{ when "../type = foo3"; } type int32; }

abierman commented 2 weeks ago

Strongly opposed to this change. Too much complexity. The defaults are OK to reference in other XPath. Multiple XPaths can be true. Competing conditional XPaths could cause interactions between leafs.

Dynamic defaults exist in implementations. That is a datastore metadata issue.

Close: complexity: high, bc: low, importance: low