【问题标题】:cisco OS upload with Python Script使用 Python 脚本上传 cisco OS
【发布时间】:2017-03-28 12:49:35
【问题描述】:

我开发了以下 python 脚本来帮助我将 NX-OS 映像上传到 Cisco Nexus 交换机。

脚本在处理小文件时运行良好。尝试使用 100M 以下的文件,它工作正常。但是我也有大约 600M 的 NX-OS 图像。在脚本运行和 TFTP 上传正在进行的某个时刻,当 Cisco 闪存盘上的文件达到大小:205987840 时,上传停止。程序冻结,当我在 cisco 控制台中键入 show users 时,我可以看到用户用于上传已经断开。

我在想这可能与 ssh 会话超时有关吗?或者我的脚本可能有问题?我是 python 新手。

我只发布脚本的相关部分:

def ssh_connect_no_shell(command):
    global output
    ssh_no_shell = paramiko.SSHClient()
    ssh_no_shell.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_no_shell.connect(device, port=22, username=myuser, password=mypass)
    ssh_no_shell.exec_command('terminal length 0\n')
    stdin, stdout, stder = ssh_no_shell.exec_command(command)
    output = stdout.readlines()
    ssh_no_shell.close()

def upload_file():
    cmd_1 = "copy tftp:" + "//" + tftp_server + "/" + image + " " + "bootflash:" + " vrf " + my_vrf
    ssh_connect_no_shell(cmd_1)
    print '\n##### Device Output Start #####'
    print '\n'.join(output)
    print '\n##### Device Output End #####'

def main():
    print 'Program starting...\n'
    time.sleep(1)
    variables1()
    check_if_file_present()
    check_if_enough_space()
    upload_file()
    check_file_md5sum()
    are_you_sure(perform_upgrade)
    perform_upgrade_and_reboot()

if __name__ == '__main__':
    clear_screen()
    main()

【问题讨论】:

    标签: python cisco


    【解决方案1】:

    我的经验是:

    • 不要使用 TFTP ...对于大文件来说速度非常慢 ...它不适用于某些防火墙 ...它取决于服务器实现来处理大文件 => 我猜,你的脚本使用不同的 TFTP-server-software 就可以正常运行...

    我建议不要对 TFTP 进行故障排除

    • 与SCP一起去 ...它需要在您的 Nexus 设备上打开 SSH 端口 ...如果 SSH 可以通过您的防火墙,那么 SCP 也可以 - 不需要额外的规则 +++ 您可以将图像从笔记本电脑“推送”到您的设备,而无需登录您的设备

    例如 - 使用“putty scp” => pscp.exe

    //pscp @ Windows-Client
    cd d:\DOWNLOADS
    start pscp n7000-s1-kickstart.6.2.12.bin admin@10.10.10.11:bootflash:
    start pscp n7000-s1-dk9.6.2.12.bin admin@10.10.10.11:bootflash:
    

    这会并行地将 nxos- 和 kickstart-image 复制到设备上。 ...轻松循环多个设备以添加更多并行传输

    顺便说一句。一些基于“IOS”的设备需要附加标志:

    pscp -2 -scp ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      相关资源
      最近更新 更多