for 循环迭代和 netmiko 只做第一个设备

for loop iteration and netmiko just doing the first device

我一直在做一些网络自动化,现在我正在使用 for lops 一次不仅可以做一个,所以当我 运行 下面的代码我看到第一个路由器时它是成功的但第二个出现错误netmiko.ssh_exception.NetmikoTimeoutException:读取通道超时,数据不可用。

所以我正在测试 3 个路由器,第一个运行良好,但第二个无法正常工作。

from netmiko import Netmiko
from getpass import getpass
import re

router1 = {
    "host": "10.0.0.248",
    "username": "cisco",
    "password": "cisco",
    "device_type": "cisco_ios",
}

router2 = {
    "host": "10.0.0.247",
    "username": "cisco",
    "password": "cisco",
    "device_type": "cisco_ios",
}

router3 = {
    "host": "10.0.0.246",
    "username": "cisco",
    "password": "cisco",
    "device_type": "cisco_ios",
}

routers = [router1, router2, router3]

interface_shut = list()

for router in routers:
    net_connect = Netmiko(**router)
    print(net_connect.find_prompt())
    output = net_connect.send_command("show ip int br")
    print(output)
    find_interfaces = re.findall("GigabitEthernet\d.\d", output)
    print(find_interfaces)
    for int in find_interfaces:
        interface_shut.append("Interface " + int)
        interface_shut.append("no shut")
        output2 = net_connect.send_config_set(interface_shut)
        print(output2)
        interface_shut = list() # I am doing this so the list doesnt have to have more than 3 items for each device
        print(interface_shut)
    net_connect.disconnect()    

那是我的错。代码工作正常。我只是忘了在其他 2 个路由器中添加 priv 15。