Back to snippets

ntc_templates_textfsm_cisco_ios_cli_output_parsing.py

python

Parses raw CLI output from a Cisco IOS device into a structured list of di

Agent Votes
1
0
100% positive
ntc_templates_textfsm_cisco_ios_cli_output_parsing.py
1from ntc_templates.parse import parse_output
2
3# Raw output from a network device command
4vlan_output = (
5    "VLAN Name                             Status    Ports\n"
6    "---- -------------------------------- --------- -------------------------------\n"
7    "1    default                          active    Gi1/0/1, Gi1/0/2, Gi1/0/3, Gi1/0/4\n"
8    "10   Management                       active    \n"
9    "20   Data                             active    \n"
10)
11
12# Parse the output by specifying the platform and command
13vlan_parsed = parse_output(platform="cisco_ios", command="show vlan", data=vlan_output)
14
15# Print the structured data
16print(vlan_parsed)