dmulyalin / ttp

Template Text Parser
MIT License
351 stars 34 forks source link

TTP conditional fields #75

Closed pperesbr closed 2 years ago

pperesbr commented 2 years ago

I'm using TTP Template Text Parser to get information from a Huawei device.

In the output of the command I have this:

ipv4-family vpn-instance VPN1
  import-route static
  import-route direct route-policy TESTE
 #

See that the import route, I may or may not have applied the configuration of a route-policy.

What I want is to build a list where, if there is a route-policy applied, only a new attribute is inserted, like this:

import_routes: [
    {
        "protocol": "static"
    },
    {
        "protocol": "direct",
        "rp": "TESTE",
    }
 ]

I tried this and it didn't work:

 <group name="vpn_import_route*">
  import-route {{ protocol }}
  import-route {{ protocol }} route-policy {{ rp }} 
  </group>  

Tks,

Paulo

pperesbr commented 2 years ago

I don't know if it's the correct way, but I did like this and worked:

<group name="bgp_vpn*">
ipv4-family vpn-instance {{ name }}
<group name="import_routes*">
 import-route {{ protocol }} route-policy {{ rpl }}
</group>
<group name="import_routes*">
 import-route {{ protocol }}
</group>
</group>

Tks,

Paulo

dmulyalin commented 2 years ago

Yeah, you need to add multiple groups to follow text outpt hierarchy.

Try this:

<group name="bgp_vpn*">
ipv4-family vpn-instance {{ name }}
<group name="import_routes*">
 import-route {{ protocol | _start_ }} route-policy {{ rpl }} 
 import-route {{ protocol | _start_ }}
</group>
</group>

it should give same results as your template, but makes use of _start_ indicator.

dmulyalin commented 2 years ago

Closing this one, please reopen if any further help needed.