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
798 stars 220 forks source link

[Bug]: ip_helper_addresses in models_nxos.py includes undeclared variable 'vrf' #301

Closed siguroot closed 2 months ago

siguroot commented 2 months ago

Contact Details

jason@caladan.ca

What happened?

the vrf variable in the ip_helper_addresses definition is undefined. i moved vrf = child.re_match_typed(r"vrf\s+member\s+(\S+)", default="") from line #1217 outside of the conditional to make it work but hoping to see a proper fix. If you think that suffices i can do a pull request.

CiscoConfParse Version

1.9.51

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.10

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

parse = CiscoConfParse('nxos-confg', syntax='nxos', factory=True)

svis = parse.find_objects_w_child(parentspec=r"^interface Vlan", childspec=r"no\sshutdown")

for svi in svis:
    print(svi.ip_helper_addresses)

Python tracebacks

Traceback (most recent call last):
  File "/home/blah/evpn/./get_svi_datacenters.py", line 17, in <module>
    print(svi.name, svi.description, svi.vrf, svi.ip, svi.ip_accessgroup_in, svi.ip_accessgroup_out, svi.ip_helper_addresses)
                                                                                                     ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/blah/.local/lib/python3.12/site-packages/ciscoconfparse/models_nxos.py", line 1227, in ip_helper_addresses
    retval.append({"addr": addr, "vrf": vrf, "global": bool(global_addr)})
                                        ^^^
UnboundLocalError: cannot access local variable 'vrf' where it is not associated with a value

Relevant log output

No response

Code of Conduct

mpenning commented 2 months ago

ciscoconfparse is end of life and you should use ciscoconfparse2 for the latest fixes including this one.