【问题标题】:Default string values for union types in Yang SchemaYang Schema 中联合类型的默认字符串值
【发布时间】:2021-12-17 20:31:16
【问题描述】:

为什么不能在以下架构中为叶子 wibble 分配默认值 "-"(cmets 不在架构中,为清楚起见添加到帖子中)

module type
{
    namespace "example.com";
    prefix "foo";
    
    typedef optional-value {
        type  union {
            type uint8 {
                range "0 .. 99";
            }
            
            type string {
                pattern "^-$";
            }
        }
    }
    
    container bar {
        leaf wibble {
            type optional-value;
            default "-"; ### NOT OKAY
        }
        
        leaf wobble {
            type optional-value;
            default 42;  ### OKAY
        }
    }
}

yanglint(版本 0.16.105)不验证上述架构并返回错误消息:

err : Invalid value "-" in "wibble" element. (/type:wibble)
err : Module "type" parsing failed.

做了更多的实验,似乎无法为带有模式的字符串分配默认值

module tmp
{
    namespace "example.com";
    prefix "foo";
    
    container bar {
        leaf wibble {
            type string {
                pattern "^x$";
            }
            default "x";    ### NOT OKAY
        }
        
        leaf wobble {
            type string;
            default "y";    ### OKAY
        }
    }
}

yanglint 输出:

err : Value "x" does not satisfy the constraint "^x$" (range, length, or pattern). (/tmp:wibble)
err : Module "tmp" parsing failed.

【问题讨论】:

    标签: schema ietf-netmod-yang yang


    【解决方案1】:

    在 YANG 中,使用来自 XML Schema 的正则表达式风格不需要 ^$ 来锚定表达式,以便它们计算整个值。所有 XSD 表达式都是隐式锚定的。您可以尝试从模式中删除这些字符,然后再试一次。

    【讨论】:

    • 您的意思是,YANG 模式开头的 ^ 字符或 YANG 模式末尾的 $ 不会像其他正则表达式那样被解释为锚点口味。相反,它们被逐字解释,使得 "^x$" 成为 OP 示例中叶 wibble 唯一可能的有效值。
    猜你喜欢
    • 1970-01-01
    • 2020-06-07
    • 2021-10-27
    • 2021-04-06
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 2020-11-22
    • 2012-12-29
    相关资源
    最近更新 更多