Загрузка...

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'] )

Видео Python List Comprehension tutorial for Device interface status| Part 31|TEXTFSM output with NETMIKO канала NetworkEvolution
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять