• 7 December 2024

Structured data with in Netmiko

Netmiko is very powerfull Python package. There are a lot of contributions. It cannot to be considered that it cannot support structured data. Sometimes manual parsing enough. Also when we get the command results as XML or JSON format, we have more possibilities.

But what if we couldn’t get the the result as XML or JSON format. At this point ntc-templates is running to help. So, first we need it to be installed.

pip install ntc-templates  

On the Netmiko side, there is one additional parameter like as below:

net_connect.send_command("show ip int brief", use_textfsm=True)

As you can see, our ConnectionHandler object takes an argument of use_textfsm. Now, we have structured data

[
{‘intf’: ‘FastEthernet0/0’, ‘ipaddr’: ‘unassigned’, ‘status’: ‘administratively down’, ‘proto’: ‘down’},
{‘intf’: ‘FastEthernet0/1’, ‘ipaddr’:’unassigned’, ‘status’: ‘administratively down’, ‘proto’: ‘down’},
{‘intf’: ‘FastEthernet1/0’, ‘ipaddr’: ‘unassigned’, ‘status’: ‘up’, ‘proto’:’up’},
{‘intf’: ‘FastEthernet1/1’, ‘ipaddr’: ‘unassigned’, ‘status’: ‘up’, ‘proto’: ‘up’},

]