I have been able to write a python script that parses IOS config files but I am getting an error.
Below is the script:
import glob, os
from ciscoconfparse import CiscoConfParse
os.chdir("T:/")
for cfgfile in glob.glob("*-confg"):
parse = CiscoConfParse("T:/" + cfgfile, factory=True, syntax='ios')
host = parse.find_objects_dna(r'Hostname')
interfaces_with_helpers = parse.find_parents_w_child( "^interf", "ip helper-address 10.194.35.201")
if interfaces_with_helpers:
print (host[0].hostname)
for interface in interfaces_with_helpers:
print (interface)
When I run the script it seems to be chugging away fine and then get the below error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Python34\lib\site-packages\ciscoconfparse-1.2.37-py3.4.egg\ciscoconfparse\ciscoconfparse.py", line 186, in __init__ CiscoConfParse=self)
File "C:\Python34\lib\site-packages\ciscoconfparse-1.2.37-py3.4.egg\ciscoconfparse\ciscoconfparse.py", line 2209, in __init__
self._list = self._bootstrap_obj_init(data)
File "C:\Python34\lib\site-packages\ciscoconfparse-1.2.37-py3.4.egg\ciscoconfparse\ciscoconfparse.py", line 2433, in _bootstrap_obj_init
syntax='ios')
File "C:\Python34\lib\site-packages\ciscoconfparse-1.2.37-py3.4.egg\ciscoconfparse\ciscoconfparse.py", line 2982, in ConfigLineFactory
comment_delimiter=comment_delimiter) # instance of the proper subclass
File "C:\Python34\lib\site-packages\ciscoconfparse-1.2.37-py3.4.egg\ciscoconfparse\models_cisco.py", line 1758, in __init__raise ValueError
ValueError
>>>