Back to Browse

Python List Comprehension tutorial for Device interface status| Part 31|TEXTFSM output with NETMIKO

3.4K views
May 2, 2019
14:15

๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ: ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ: 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 formats

No download links available.

Python List Comprehension tutorial for Device interface status| Part 31|TEXTFSM output with NETMIKO | NatokHD