如果模板中有 ORPHRASE 且输入文本中有连续空格,python ttp 解析器会忽略行
让人: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用line代替ORPHRASE(在开头和结尾都带有下划线的行)
you can use line instead of ORPHRASE (line with underscore both at the start and end)