Conditional assignment of default values in yang

社会主义新天地 提交于 2019-12-01 21:19:14

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.

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