如何处理这个混合配置在一个文件与python ttp解析器?



我正在为诺基亚SR节点上的VPLS服务配置使用python TTP解析器。下面是VPLS服务上的两个evpn配置示例。我想把重点放在bgpbgp-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>

由于两种配置格式可能存在于单个配置文件中。我需要使用一个模板来涵盖这两种情况。这可行吗?我应该如何调整我的模板?

this template:

<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="evi">
evi {{ reference }}
<group name="mpls_params**">
mpls {{ _start_ }}
no shutdown {{ state | set("enabled") | default("disabled") }}
auto-bind-tunnel resolution {{ resolution }}
</group>
</group>        

<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>

给出如下输出:

[
{
"bgp": {
"route_distinguisher": "63.130.124.186:50050",
"route_target": {
"export_target": "4445:50050",
"import_target": "4445:50050"
}
},
"bgp_evpn": [
{
"evi": {
"mpls_params": {
"resolution": "any",
"state": "enabled"
},
"reference": "10"
}
},
{
"mpls": {
"auto_bind_tunnel": {
"resolution": "filter",
"resolution_filters": {
"resolution_filter": "ldpnrsvpnsr-isisnsr-te"
}
},
"reference": "bgp 1",
"state": "enabled"
}
}
]
}
]

使用此沙箱进行测试:https://textfsm.nornir.tech/

不确定这是否是你想要的,但它可以解析两种格式并将它们组合在一起,也为sros这个repo可能是一个有用的示例来源:https://pypi.org/project/ttp-sros-parser/

相关内容

  • 没有找到相关文章

最新更新