Skip to content

Instantly share code, notes, and snippets.

@lamoni
Last active September 30, 2021 11:21
Show Gist options
  • Save lamoni/73120ee1d9d3d3e9dbfb5f969e256862 to your computer and use it in GitHub Desktop.
Save lamoni/73120ee1d9d3d3e9dbfb5f969e256862 to your computer and use it in GitHub Desktop.
Convert Cisco or Arista config format to a pseudo-set format
# Quick POC #1, obviously want to get rid of the "terminal" assumption
def convert_from_arista_to_pseudo_set_format(contents: str):
final = []
contents = 'terminal' + contents.split('terminal', 1)[1]
contents = contents.split('\n!\n')
for block in contents:
split = block.split('\n')
main = f'set {split[0]}'
for index, _ in enumerate(split):
if split[index].strip() == '!':
continue
counter = split[index].count(' ')
if counter > 0:
mid = ''
for c in range(counter):
mid = f'{split[index-c].strip()} {mid.strip()} '
final.append(f'{main} {mid}')
else:
final.append(f"set {split[index]}")
return '\n'.join(final)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment