TobiEiss/go-textfsm

Parsing Of Value Stored As Variable

Closed this issue · 1 comments

I am unsure if this is currently supported or not but I am trying to figure out the best way to create a template that can leverage A Record of the value as the item to search for. I guess the best example I can give is something like the following:

router bgp
local-asn 1299
neighbor 1.1.1.1 remote-asn 1987

address-family ipv4 unicast
neighbor 1.1.1.1 route-policy allow-all in
neighbor 1.1.1.1 route-policy allow-all out
exit-context

What I am trying to do is basically have the following template:

Value Filldown ProcessASN (\d+)
Value Neighbor (\S+)
Value Filldown AddressFamily (ipv\d)
Value RPInbound (\S+)
Value RPEgress (\S+)

Start
  ^.*router bgp
  ^.*local-asn ${ProcessASN} -> AddressFamily

AddressFamily
  ^.*address-family ${AddressFamily} unicast -> BGP

BGP
  ^.*neighbor ${Neighbor} -> Continue
  ^.*neighbor ${Neighbor} route-policy ${RoutePolicyIn} in -> Continue
  ^.*neighbor ${Neighbor} route-policy ${RoutePolicyOut} out -> Continue Record
  ^.*exit-context -> AFI

The above would produce:

["1299","ipv4","1.1.1.1","allow-all","allow-all"]

I am wondering if it is possible to lookup the actual BGP neighbor when transitioning the state to BGP, so the output would look more like:

["1299","1.1.1.1","1897","ipv4","allow-all","allow-all"]

This has to be handled from within the application itself by joining on the key of interest. There is not a clean way to do this without moving away from TextFSM's principles.