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

Error parsing syntax=junos #78

Closed psyc0 closed 6 years ago

psyc0 commented 7 years ago

Hi,

im trying to use confparse to parse a juniper config but I immediately run in to the following error as soon as I try to create the object (the conf is 3000+ lines long). Im running 1.2.47 currently.

parse2 = CiscoConfParse('config.junos', syntax='junos', debug=True, comment='#')

[ciscoconfparse __init__] [DEBUG] 17:36:11 parsing from 'config.junos' with junos syntax
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in ()
----> 1 parse2 = CiscoConfParse('config.junos', syntax='junos', debug=True, comment='#')

scripts/identify_service/ciscoconfparse/ciscoconfparse/ciscoconfparse.py in __init__(self, config, comment, debug, factory, linesplit_rgx, ignore_blank_lines, syntax)
    261                     rgx = re.compile(linesplit_rgx)
    262 
--> 263                     config = self.convert_braces_to_ios(rgx.split(text))
    264                     ## FIXME I am shamelessly abusing the IOSConfigList for now...
    265                     self.ConfigObjs = IOSConfigList(

scripts/identify_service/ciscoconfparse/ciscoconfparse/ciscoconfparse.py in convert_braces_to_ios(self, input_list, stop_width)
    387         STOP_WIDTH = stop_width
    388         for tmp in input_list:
--> 389             line, line_offset = line_level(tmp.strip())
    390             if line:
    391                 lines.append(" " * STOP_WIDTH * offset + line)

scripts/identify_service/ciscoconfparse/ciscoconfparse/ciscoconfparse.py in line_level(input)
    381                 return input, 0
    382             else:
--> 383                 raise ValueError("Could not parse: '{0}'".format(input))
    384 
    385         lines = list()

ValueError: Could not parse: '#'
mpenning commented 7 years ago

Please post a sanitized version of your juniper configuration inside this issue so I can reproduce the problem

wilmington commented 6 years ago

Came here to track the same issue, I was trying to use ciscoconfparse on juniper files retrieved by RANCID. The problem appears to be caused by a "#" character on an otherwise bare-line

Removing that # + bare-line or adding another character appears to solve the issue.

# RANCID-CONTENT-TYPE: juniper
#       CB 0 ACBC                      OK
#
# asdjajsdlasd> show configuration
## Last commit: 2017-09-24 18:57:09 AEST by bob
version 13.3R5.9;
groups {
        }
mpenning commented 6 years ago

I'm not sure when this was fixed, but it's definitely working with the config @wilmington posted... tested in version 1.2.53 and had no issues...