Conditional assignment of default values in yang

后端 未结 1 1595
难免孤独
难免孤独 2021-01-20 23:34

I have two properties in a model:

  • leaf protocol,
  • leaf port.

I want to specify that:

  • if protocol = \'ssh\' then default port
相关标签:
1条回答
  • 2021-01-21 00:29

    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.

    0 讨论(0)
提交回复
热议问题