如果模板中有 ORPHRASE 且输入文本中有连续空格,python ttp 解析器会忽略行

发布于 2025-01-18 08:08:19 字数 2570 浏览 0 评论 0原文

让人:Windows 10,Python:3.9,TTP:0.8.4

我在TTP​​模板中遇到 orphrase 的问题,以及是否连续存在空白空间字符字符串应该拾取模板。

输入文本:

    vprn 5000122 customer 99999 create
        description "LastMod: Jan 28, 2022 2:33:11 AM"
        vrf-import "VPRN-5000122-IMPORT"
        vrf-export "VPRN-5000122-EXPORT"
        router-id 95.95.95.95
        autonomous-system 5555
        route-distinguisher 4444:8888888
        auto-bind-tunnel
            resolution-filter
                ldp
            exit
            resolution filter
        exit
        interface "*dummy-1* L3 interface"  create
            description "*** single blank-space description ***"
            address 199.199.199.199/32
        exit
        interface "*dummy-2* L3 interface"  create
            description "***  double blank-space description ***"
            address 201.201.201.201/32
        exit
        service-name "dumy-vprn-service"
        no shutdown
    exit

TTP模板:

<group name="service">
<group name="vprn.{{ service_id }}**">
    vprn {{service_id | _start_ }} customer {{customer_id}} create
        description "{{ description | ORPHRASE | default("")}}"
        vrf-import "{{ vrf_import }}"
        vrf-export "{{ vrf_export }}"
        autonomous-system {{ autonous_system }}
        route-distinguisher {{ route_distinguisher }}
    <group name="interface.{{interface_id}}**">
        interface "{{ interface_id | ORPHRASE | _start_ }}" create
            description "{{ description | ORPHRASE }}"
            address {{ ipv4_address }}
            ip-mtu {{ ip_mtu }}
        exit {{ _end_ }}
    </group>
        service-name "{{ service_name }}"
        no shutdown {{ state | set("enabled") | default("disabled") }}
    exit {{ _end_ }}
</group>

解析输出:

{
"5000122": {
    "route_distinguisher": "4444:8888888",
    "autonous_system": "5555",
    "vrf_export": "VPRN-5000122-EXPORT",
    "vrf_import": "VPRN-5000122-IMPORT",
    "description": "LastMod: Jan 28, 2022 2:33:11 AM",
    "customer_id": "99999",
    "state": "enabled",
    "interface": {
        "*dummy-1* L3 interface": {
            "ipv4_address": "199.199.199.199/32",
            "description": "*** single blank-space description ***"
        },
        "*dummy-2* L3 interface": {
            "ipv4_address": "201.201.201.201/32"
        }
    },
    "service_name": "dumy-vprn-service"
}

}

问题: 第二个接口中的描述行未被解析器拾取,因为字符串中的连续空格字符

Envorionment: windows 10, python: 3.9, ttp: 0.8.4

I'm having a problem with ORPHRASE in the TTP template, and if there's consecutive blank-space characters in the string the template is supposed to pick up.

Input text:

    vprn 5000122 customer 99999 create
        description "LastMod: Jan 28, 2022 2:33:11 AM"
        vrf-import "VPRN-5000122-IMPORT"
        vrf-export "VPRN-5000122-EXPORT"
        router-id 95.95.95.95
        autonomous-system 5555
        route-distinguisher 4444:8888888
        auto-bind-tunnel
            resolution-filter
                ldp
            exit
            resolution filter
        exit
        interface "*dummy-1* L3 interface"  create
            description "*** single blank-space description ***"
            address 199.199.199.199/32
        exit
        interface "*dummy-2* L3 interface"  create
            description "***  double blank-space description ***"
            address 201.201.201.201/32
        exit
        service-name "dumy-vprn-service"
        no shutdown
    exit

TTP template:

<group name="service">
<group name="vprn.{{ service_id }}**">
    vprn {{service_id | _start_ }} customer {{customer_id}} create
        description "{{ description | ORPHRASE | default("")}}"
        vrf-import "{{ vrf_import }}"
        vrf-export "{{ vrf_export }}"
        autonomous-system {{ autonous_system }}
        route-distinguisher {{ route_distinguisher }}
    <group name="interface.{{interface_id}}**">
        interface "{{ interface_id | ORPHRASE | _start_ }}" create
            description "{{ description | ORPHRASE }}"
            address {{ ipv4_address }}
            ip-mtu {{ ip_mtu }}
        exit {{ _end_ }}
    </group>
        service-name "{{ service_name }}"
        no shutdown {{ state | set("enabled") | default("disabled") }}
    exit {{ _end_ }}
</group>

parsed output:

{
"5000122": {
    "route_distinguisher": "4444:8888888",
    "autonous_system": "5555",
    "vrf_export": "VPRN-5000122-EXPORT",
    "vrf_import": "VPRN-5000122-IMPORT",
    "description": "LastMod: Jan 28, 2022 2:33:11 AM",
    "customer_id": "99999",
    "state": "enabled",
    "interface": {
        "*dummy-1* L3 interface": {
            "ipv4_address": "199.199.199.199/32",
            "description": "*** single blank-space description ***"
        },
        "*dummy-2* L3 interface": {
            "ipv4_address": "201.201.201.201/32"
        }
    },
    "service_name": "dumy-vprn-service"
}

}

Problem:
The description line in the second interface is not picked up by the parser, because the consecutive blank-space characters in the string

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2025-01-25 08:08:19

您可以使用line代替ORPHRASE(在开头和结尾都带有下划线的行)

you can use line instead of ORPHRASE (line with underscore both at the start and end)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文