google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.11k stars 171 forks source link

Parsing Cisco NXOS-style configuration using textfsm #108

Closed evgenoir closed 8 months ago

evgenoir commented 2 years ago

I am trying to use textfsm to parse the config like this:

vlan 3
  name TestVlan3

vrf context management
vrf context vrf1
  description vrf1
  rd 100:200
  address-family ipv4 unicast
    route-target import 100:11
    route-target import 100:200
    route-target export 100:12
    route-target export 100:200
vrf context vrf2
  rd 100:300
  address-family ipv4 unicast
    route-target import 100:21
    route-target import 100:300
    route-target export 100:22
    route-target export 100:300

interface Ethernet1/1

NOTE: Any indented line below "vrf context" may be missing!

I've parsed a lot of different kinds of configurations using textfsm, but this configuration has stumped me. The problem here that there is no separator beetween 'vrf context' parts of configuration and textfsm doesn't support state transition with Contrinue action. Is there a some way to overcome this limitation in textfsm?

byadair commented 1 year ago

What's you need is Filldown I think, like this: Value Filldown vrf (.+) Value address (.+)

Start ^\s*vrf context ${vrf} -> Record V

V ^\saddress-family ${address} ^\svrf context ${vrf} -> Record V

harro commented 8 months ago

Closing on the assumption the suggested fix resolved the issue - reopen if that's not the case?