How to use the textfsm.clitable function in textfsm

To help you get started, we’ve selected a few textfsm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ktbyers / ansible_helpers / filter_plugins / net_textfsm_parse.py View on Github external
def get_structured_data(raw_output, platform, command):
    """Convert raw CLI output to structured data using TextFSM template."""
    template_dir = get_template_dir()
    index_file = os.path.join(template_dir, 'index')
    textfsm_obj = clitable.CliTable(index_file, template_dir)
    attrs = {'Command': command, 'Platform': platform}
    try:
        # Parse output through template
        textfsm_obj.ParseCmd(raw_output, attrs)
        return clitable_to_dict(textfsm_obj)
    except CliTableError:
        return raw_output