如何使用Python TTP解析器在一个文件中处理此混合配置?
我正在使用Python TTP解析器上的诺基亚SR节点上的VPLS服务配置的解析器。以下是VPLS服务上EVPN配置的两个示例。我现在想关注 bgp 和 bgp-evpn 零件。
description "evpn-mpls-service with single-active multihoming"
bgp
bgp-evpn
evi 10
mpls
no shutdown
auto-bind-tunnel resolution any
spoke-sdp 2:1 create
exit
-
bgp
route-distinguisher 63.130.124.186:50050
route-target export target:4445:50050 import target:4445:50050
exit
bgp-evpn
mpls bgp 1
control-word
auto-bind-tunnel
resolution-filter
ldp
rsvp
sr-isis
sr-te
exit
resolution filter
exit
no shutdown
exit
exit
以下是第二个示例的我的 ttp 模板:
<group name="bgp">
bgp {{ _start_ }}
route-distinguisher {{ route_distinguisher }}
<group name="route_target**">
route-target export target:{{ export_target}} import target:{{ import_target }}
</group>
exit {{ _end_ }}
</group>
<group name="bgp_evpn">
bgp-evpn {{ _start_ }}
<group name="mpls">
mpls {{ reference | ORPHRASE }}
<group name="auto_bind_tunnel">
auto-bind-tunnel {{ _start_ }}
<group name="resolution_filters">
resolution-filter {{ _start_ }}
{{ resolution_filter | _line_ }}
exit {{ _end_ }}
</group>
resolution {{ resolution }}
exit {{ _end_ }}
</group>
no shutdown {{ state | set("enabled") | default("disabled") }}
exit {{ _end_ }}
</group>
exit {{ _end_ }}
</group>
由于两个配置格式都可能存在于单个配置文件中。我需要使用一个模板来涵盖这两种情况。可以可行吗?我应该如何调整模板?
I'm working on a parser for VPLS service config on Nokia SR node with python TTP parser. The following are two samples of evpn config on VPLS service. I want to focus on the bgp and bgp-evpn parts now.
description "evpn-mpls-service with single-active multihoming"
bgp
bgp-evpn
evi 10
mpls
no shutdown
auto-bind-tunnel resolution any
spoke-sdp 2:1 create
exit
--
bgp
route-distinguisher 63.130.124.186:50050
route-target export target:4445:50050 import target:4445:50050
exit
bgp-evpn
mpls bgp 1
control-word
auto-bind-tunnel
resolution-filter
ldp
rsvp
sr-isis
sr-te
exit
resolution filter
exit
no shutdown
exit
exit
The following is my TTP template for the second sample:
<group name="bgp">
bgp {{ _start_ }}
route-distinguisher {{ route_distinguisher }}
<group name="route_target**">
route-target export target:{{ export_target}} import target:{{ import_target }}
</group>
exit {{ _end_ }}
</group>
<group name="bgp_evpn">
bgp-evpn {{ _start_ }}
<group name="mpls">
mpls {{ reference | ORPHRASE }}
<group name="auto_bind_tunnel">
auto-bind-tunnel {{ _start_ }}
<group name="resolution_filters">
resolution-filter {{ _start_ }}
{{ resolution_filter | _line_ }}
exit {{ _end_ }}
</group>
resolution {{ resolution }}
exit {{ _end_ }}
</group>
no shutdown {{ state | set("enabled") | default("disabled") }}
exit {{ _end_ }}
</group>
exit {{ _end_ }}
</group>
Since both config format may exist in a single config file. I need to use one template to cover both cases. Is it doable? How should I adjust my template for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此模板:
给出此输出:
使用此沙箱进行了上述测试: htttps://textfsm.nornir.tech/
不确定这是否是您之所以追随的,但它可以解析格式并将它们结合在总体结果中,对于SRO,此回购可能是一个有用的示例来源: https://pypi.org/project/ttp-sros-parser/
this template:
Gives this output:
Tested above using this sandbox: https://textfsm.nornir.tech/
Not sure if this is what you after but it can parse both formats and combine them in overall results, also for sros this repo might be a useful source of examples: https://pypi.org/project/ttp-sros-parser/