Skip to content

Instantly share code, notes, and snippets.

@tcuthbert
Created February 27, 2017 23:35
Show Gist options
  • Save tcuthbert/751d1a73d06241bae24ec21407d07f8a to your computer and use it in GitHub Desktop.
Save tcuthbert/751d1a73d06241bae24ec21407d07f8a to your computer and use it in GitHub Desktop.
def parse_template(self, results, device, commands=None):
"""
Generator function that processes unstructured CLI data and yields either
a TextFSM based object or generic raw output.
:param results:
The unstructured "raw" CLI data from device.
:type results:
str
:param device:
NetDevice object
:type device:
`~trigger.netdevices.NetDevice`
"""
device_type = device.os
ret = []
for idx, command in enumerate(commands):
if device_type:
try:
re_table = load_cmd_template(command, dev_type=device_type)
fsm = get_textfsm_object(re_table, results[idx])
self.append_parsed_results(device, self.map_parsed_results(command, fsm))
except:
log.msg("Unable to load TextFSM template, just updating with unstructured output")
ret.append(results[idx])
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment