mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
794 stars 220 forks source link

IOSIntfLine: ip_helper_addresses doesn't handle 'global' helpers #141

Closed noziwatele closed 5 years ago

noziwatele commented 5 years ago

Hi Mike, et al,

Thanks for a very handy tool!

We have some SVIs in Cisco routers with the following config:

... ip helper-address global 172.20.1.1 ...

After parsing with CiscoConfParse and the find_interface_objects method, the returned IOSIntfLine object contains the ip_helper_addresses list, but they look like: ['global', 'global'] (for as many helper-addresses that are configured).

It looks like this could be fixed by a minor re-jig of the regex on line 1121 of ciscoconfparse/ciscoconfparse/models_cisco.py.

Cheers, Mike.

noziwatele commented 5 years ago

As soon as I submitted the above issue, I found another, slightly different case...

ip helper-address vrf VRF-NAME 172.20.1.1

So it would be good to take this into account for any solution.

Cheers!

mpenning commented 5 years ago

This has been implemented in version 1.4.2...

Specifically, the code returns a list of dictionaries for the helpers on an interface...

Assume you have this code:

from ciscoconfparse import CiscoConfParse

CONFIG = """!
interface GigabitEthernet0/1
 ip address 172.16.30.1 255.255.255.0
 ip helper-address global 10.1.1.1
 ip helper-address 10.1.1.2
 ip helper-address vrf FOO 10.1.1.3
"""
parse = CiscoConfParse(CONFIG.splitlines(), syntax='ios, factory=True)
for obj in parse.find_objects('^interface'):
    for helper in obj.ip_helper_addresses:
        print helper

The output when you run it looks like this:

~ python helper_addr_example.py
{'global': True, 'addr': '10.1.1.1', 'vrf': ''}
{'global': False, 'addr': '10.1.1.2', 'vrf': ''}
{'global': False, 'addr': '10.1.1.3', 'vrf': 'FOO'}
~

The new object property is going to break old code, but there is not much of a way to avoid the problem; there is too much information to pack into each helper-address.