Python List Comprehension tutorial for Device interface status| Part 31|TEXTFSM output with NETMIKO
๐๐ผ๐ฟ ๐๐ผ๐บ๐ฝ๐น๐ฒ๐๐ฒ ๐ฃ๐๐๐ต๐ผ๐ป ๐๐ผ๐ฟ ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ ๐๐ผ๐๐ฟ๐๐ฒ: ๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐ฏ๐ฒ๐น๐ผ๐ ๐จ๐ฑ๐ฒ๐บ๐ ๐๐น๐ฎ๐๐: ๐๐๐๐ ๐๐๐ซ๐ฌ๐ข๐จ๐ง ๐ซ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐๐๐๐ ๐ณ๐๐๐: https://www.udemy.com/course/python-for-network-engineers/?referralCode=35A75AAE1ACA94A15829 List comprehension tutorial, for creating the list esily from list of dictionaries in Python. Compare for loop and if logic with list comprehension. Explained list comprehension logic with example. How to list Cisco device interface status using Python, TEXTFSM, NETMIKO and list comprehension logic from netmiko import ConnectHandler from operator import itemgetter RTR_10 = { 'ip': '10.10.10.10', 'username': 'admin', 'password': 'admin', 'device_type': 'cisco_ios', } print ('Checking interface status..') net_connect = ConnectHandler(**RTR_10) output = net_connect.send_command('show ip int brie', use_textfsm=True) devlist = [] for i in output: if i['status'] == 'up': devlist.append(i['intf']) print(devlist) print([i for i in output if i['status'] == 'up']) print ([i['intf'] for i in output if i['status'] == 'up']) print('\n \n') print ('\nList of interfaces which are UP \n') statusup =[i['intf'] for i in output if i['status'] == 'up'] for ifaceup in statusup: print (ifaceup) print ('\nList of interfaces which are DOWN \n') statusother =[i for i in output if i['status'] != 'up'] for ifaceother in statusother: print (ifaceother['intf'] + ' ' + ifacesother['status'] )
Download
0 formatsNo download links available.