带有线程池的Netmiko SSH

时间:2019-06-30 11:02:11

标签: python ssh threadpool cisco

我有以下python代码部分: 从输入文件中读取IP地址列表,然后建立ssh连接,以使用Netmiko库发送CISCO IOS命令

with open(args.csv, 'r') as file:
    reader = csv.DictReader(file)
    for device_row in reader:
        try:
            ssh_session = ConnectHandler(device_type='cisco_ios',
                    ip=device_row['Host'],
                    username=ssh_username, password=ssh_password)
            print '********* {0} *********'.format(device_row['Host'
                    ])

        # Specify your commands here, you can add more commands just follow the same syntax
             print ssh_session.send_command('show running-config | i hostname')

        except paramiko.AuthenticationException:
    print ('{0}'.format(device_row['Host']),"Authenticaiton Problem!")
            pass

我想使用线程池对成千上万的设备使用它。.

1 个答案:

答案 0 :(得分:0)

看看Nornir,它具有内置的线程支持并具有支持Netmiko的插件。