使用Python脚本上载cisco OS

时间:2016-11-14 19:21:40

标签: python cisco

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

脚本运行得很好,只有小文件。试过100M以下的文件,它工作正常。但是我也有大约600M的NX-OS图像。在脚本运行且TFTP上传正在进行的某个时刻,当思科闪存盘上的文件达到大小时,上传停止: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()

0 个答案:

没有答案
相关问题