ttp icon indicating copy to clipboard operation
ttp copied to clipboard

How to escape the ending * (asterisk) in the value of template variables?

Open hsheng opened this issue 11 months ago • 0 comments

python 3.8 and ttp-0.9.2

The input:

    interfaces {
        ge-* {
            unit * {
                forwarding-class BE;
            }
        }
        xe-* {
            unit * {
                forwarding-class BE;
            }
        }
    }

The template:

    <group name="interfaces">
    interfaces { {{ _start_ }}

        <group name="interface-set.{{ interface-set}}">
        interface-set {{ interface-set | _start_ }} {
            excess-bandwidth-share {{ excess-bandwidth-share | _line_ }};
            output-traffic-control-profile {{ output-traffic-control-profile }};
        } {{ _end_ }}
        </group>

        <group name="interface.{{ interface }}">
        {{ interface | _start_ }} {
            apply-groups {{ apply-groups }};
            shaping-rate {{ shaping-rate}};
            output-traffic-control-profile {{ output-traffic-control-profile }};

            <group name="unit.{{ unit }}">
            unit {{ unit | _start_ }} {
                apply-groups {{ apply-groups }};
                output-traffic-control-profile {{ output-traffic-control-profile }};
                <group name="classifiers*">
                classifiers { {{ _start_ }}
                    {{ classifier | _line_ }};
                } {{ _end_ }}
                </group>
            } {{ _end_ }}
            </group>

        } {{ _end_ }}
        </group>

    } {{ _end_ }}
    </group>

The expected result:

{ 
    "interfaces": {
        "interface": {
            "ge-*": {
                "unit": {
                    "*": {
                        "forwarding-class": "BE"
                    }
                }
            },
            "xe-*": {
                "unit": {
                    "*": {
                        "forwarding-class": "BE"
                    }
                }
            },
        }
}

The actual result:

{
    'interfaces': {
        'interface': {
            'ge-': [
                {
                    'unit': {
                        '': []
                    }
                }
            ], 
            'xe-': [
               {
                   'unit': {
                       '': []
                   }
               }
            ],
        } 
    }
}

How to escape the ending * (asterisk) in the template attribute value?

hsheng avatar Mar 04 '25 17:03 hsheng