mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Resolved issue with NetworkConfig parsing device configs with inconsistent indentation levels. (#51850)
This commit is contained in:
parent
07774b4ccf
commit
cfd869e898
1 changed files with 8 additions and 8 deletions
|
@ -214,8 +214,7 @@ class NetworkConfig(object):
|
|||
ancestors = list()
|
||||
config = list()
|
||||
|
||||
curlevel = 0
|
||||
prevlevel = 0
|
||||
indents = [0]
|
||||
|
||||
for linenum, line in enumerate(to_native(lines, errors='surrogate_or_strict').split('\n')):
|
||||
text = entry_reg.sub('', line).strip()
|
||||
|
@ -228,20 +227,21 @@ class NetworkConfig(object):
|
|||
# handle top level commands
|
||||
if toplevel.match(line):
|
||||
ancestors = [cfg]
|
||||
prevlevel = curlevel
|
||||
curlevel = 0
|
||||
indents = [0]
|
||||
|
||||
# handle sub level commands
|
||||
else:
|
||||
match = childline.match(line)
|
||||
line_indent = match.start(1)
|
||||
|
||||
prevlevel = curlevel
|
||||
curlevel = int(line_indent / self._indent)
|
||||
if line_indent < indents[-1]:
|
||||
while indents[-1] > line_indent:
|
||||
indents.pop()
|
||||
|
||||
if (curlevel - 1) > prevlevel:
|
||||
curlevel = prevlevel + 1
|
||||
if line_indent > indents[-1]:
|
||||
indents.append(line_indent)
|
||||
|
||||
curlevel = len(indents) - 1
|
||||
parent_level = curlevel - 1
|
||||
|
||||
cfg._parents = ancestors[:curlevel]
|
||||
|
|
Loading…
Reference in a new issue