'With TTP parser, how capture data in a group with two lines starting with the same word

With TTP parser, how can I capture the prefix-limit in the following BGP config from Nokia device? I have two prefix-limit lines in the config, one for ipv4, the other for ipv6; I need to extract both.

                neighbor 192.168.102.41
                    description "blablabla"
                    authentication-key "hashed-key-here" hash2
                    prefix-limit ipv4 600 threshold 80
                    prefix-limit ipv6 601 threshold 81
                    import "policy-1" "policy-2" 
                    export "policy-3" "policy-4" 
                    graceful-restart
                        stale-routes-time 360
                        restart-time 120
                        enable-notification 
                    exit
                    peer-as 65510
                    bfd-enable
                exit

This is the TTP template I came up with,

            <group name="neighbor.{{ neighbor }}">
                neighbor {{ neighbor | _start_ }}
                    family {{ address_family | default("ipv4") }}
                    description {{ description | ORPHRASE | macro("remove_quot_marks") }}
                    authentication-key {{ auth_key | macro("remove_quot_marks") }} hash2
                    prefix-limit {{ family }} {{ prefix_limit }} threshold {{ threshold }}
                    peer-as {{ peer_AS_number }}
                    import {{ import_policy | ORPHRASE | macro("extract_import_export_policy") }}
                    export {{ export_policy | ORPHRASE | macro("extract_import_export_policy") }}
                    bfd-enable {{ bfd_enabled | set("enabled") }}
                exit {{ _end_ }}
            </group>

This only extracts the config for ipv4; the config for ipv6 is ignored. I tried to replace the prefix-limit line in the above template the following two lines,

                    prefix-limit ipv4 {{ ipv4_prefix_limit }} threshold {{ ipv4_threshold }}
                    prefix-limit ipv6 {{ ipv6_prefix_limit }} threshold {{ ipv6_threshold }}

This also only extracts the config for ipv4; the config for ipv6 is totally dismissed.

But if my TTP template has this one line only as shown below, then I can extact the config for both ipv4 and ipv6,

                        prefix-limit {{ family }} {{ prefix_limit }} threshold {{ threshold }}

the following is the parsed data with the above template,

[
{
    "family": "ipv4",
    "prefix_limit": "600",
    "threshold": "80"
},
{
    "family": "ipv6",
    "prefix_limit": "601",
    "threshold": "81"
}
]

How can I get this to work together with other configs, like in my first TTP template?

Thanks, Harry



Solution 1:[1]

Answer my own question, the following TTP template worked for the sample config in my question. (My mind must be somewhere else a moment ago)

            <group name="neighbor.{{ neighbor }}">
                neighbor {{ neighbor | _start_ }}
                    family {{ address_family | default("ipv4") }}
                    description {{ description | ORPHRASE | macro("remove_quot_marks") }}
                    authentication-key {{ auth_key | macro("remove_quot_marks") }} hash2

                    <group name="prefix_limit.{{family}}">
                    prefix-limit {{ family }} {{ prefix_limit }} threshold {{ threshold }}
                    </group>
                    
                    peer-as {{ peer_AS_number }}
                    import {{ import_policy | ORPHRASE | macro("extract_import_export_policy") }}
                    export {{ export_policy | ORPHRASE | macro("extract_import_export_policy") }}
                    bfd-enable {{ bfd_enabled | set("enabled") }}
                exit {{ _end_ }}
            </group>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 H.Sheng