Conditional assignment of default values in yang

▼魔方 西西 提交于 2019-12-31 02:01:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!