Closed demakkar closed 4 years ago
I am trying to parse network statment is running config bgp .when textfsm fails to find any network statement it returns complete string of running conifg .when it find corrrect string ,it gives list of dictionaries.
code
net_connect = ConnectHandler(**ceos2) runningconfigoutput = net_connect.send_command('show running-config section bgp', use_textfsm=True) route_map_configparser(output,runningconfigoutput)
textfsm
`Value AGGNETWORK (\d+.\d+.\d+.\d+\/\d+) Value MATCHMAP (\S+) Value LOCALNETWORK (\d+.\d+.\d+.\d+\/\d+) Value ROUTEMAP (\S+)
Start ^\s+network\s${LOCALNETWORK}\sroute-map\s${ROUTEMAP} ^\s+aggregate-address\s${AGGNETWORK}\smatch-map\s${MATCHMAP} -> Record `
[{'aggnetwork': '20.0.0.0/8', 'localnetwork': '10.0.0.0/8', 'matchmap': 'def', 'routemap': 'abc'}, {'aggnetwork': '20.0.0.0/8', 'localnetwork': '', 'matchmap': 'ghi', 'routemap': ''}, {'aggnetwork': '', 'localnetwork': '10.224.14.26/31', 'matchmap': '', 'routemap': 'qui-hlb-snat'}]
('router bgp 64840\n' ' neighbor azure-msee-all peer-group\n' ' neighbor azure-msee-all maximum-routes 12000\n' ' !\n' ' vrf corp\n' ' router-id 1.1.1.1\n' ' neighbor 10.116.124.242 peer-group azure-msee-all\n' ' neighbor 10.116.124.242 remote-as 12076\n' ' neighbor 10.116.124.242 fall-over bfd\n' ' neighbor 10.116.124.242 description ' 'e5eb0185-52e7-42a9-a9aa-827fb8e4e918\n' ' neighbor 10.116.124.242 soft-reconfiguration inbound\n' ' neighbor 10.116.124.242 route-map e5eb0185-52e7-42a9-a9aa-827fb8e4e918 ' 'in\n' )
I think that is the expected behavior.
You could detect a string and raise an exception in the failed to parse case.
I am considering changing this, but that is what is currently expected.
I am trying to parse network statment is running config bgp .when textfsm fails to find any network statement it returns complete string of running conifg .when it find corrrect string ,it gives list of dictionaries.
code
net_connect = ConnectHandler(**ceos2) runningconfigoutput = net_connect.send_command('show running-config section bgp', use_textfsm=True) route_map_configparser(output,runningconfigoutput)
textfsm
`Value AGGNETWORK (\d+.\d+.\d+.\d+\/\d+) Value MATCHMAP (\S+) Value LOCALNETWORK (\d+.\d+.\d+.\d+\/\d+) Value ROUTEMAP (\S+)
Start ^\s+network\s${LOCALNETWORK}\sroute-map\s${ROUTEMAP} ^\s+aggregate-address\s${AGGNETWORK}\smatch-map\s${MATCHMAP} -> Record `
[{'aggnetwork': '20.0.0.0/8', 'localnetwork': '10.0.0.0/8', 'matchmap': 'def', 'routemap': 'abc'}, {'aggnetwork': '20.0.0.0/8', 'localnetwork': '', 'matchmap': 'ghi', 'routemap': ''}, {'aggnetwork': '', 'localnetwork': '10.224.14.26/31', 'matchmap': '', 'routemap': 'qui-hlb-snat'}]
('router bgp 64840\n' ' neighbor azure-msee-all peer-group\n' ' neighbor azure-msee-all maximum-routes 12000\n' ' !\n' ' vrf corp\n' ' router-id 1.1.1.1\n' ' neighbor 10.116.124.242 peer-group azure-msee-all\n' ' neighbor 10.116.124.242 remote-as 12076\n' ' neighbor 10.116.124.242 fall-over bfd\n' ' neighbor 10.116.124.242 description ' 'e5eb0185-52e7-42a9-a9aa-827fb8e4e918\n' ' neighbor 10.116.124.242 soft-reconfiguration inbound\n' ' neighbor 10.116.124.242 route-map e5eb0185-52e7-42a9-a9aa-827fb8e4e918 ' 'in\n' )