3

I have developed the following python script to help me upload NX-OS images to the Cisco Nexus switches.

The script is running just fine with small files. Tried with files under 100M and it's working fine. However I have also NX-OS images which are about 600M . At some point while script is running and the TFTP upload in in progress the upload stops when the file on the Cisco flashdisk reach size: 205987840. The programs freezes and when I type show users in the cisco console I can see that the user used for upload is already disconnected.

I am thinking that maybe is something related to the ssh session timed out ? Or maybe something wrong in my script? I am new with python.

I am posting only relevant parts of the script:

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()
nyhctrip
  • 31
  • 3

1 Answers1

0

My experience is:

  • don't use TFTP ...it's incredibly slow for large files ...it doesn't work well with some firewalls ...it depends on the server implementation to handle large files => i'd guess, your script would just run fine using a different TFTP-server-software...

Rather than troubleshooting TFTP I'd suggest to

  • go with SCP ...it requires an open SSH-Port at your Nexus-Device ...if SSH is possible through your firewall, SCP is, too - no extra rule required +++ you can "push" the images from your laptop to your device without having to login into your device

for example - use "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:

This copies, in parallel!, the nxos- and the kickstart-image to a device. ...easy to loop over several devices to add more parallel transfers

btw. some "IOS"-based devices require additonal flags:

pscp -2 -scp ...
superron
  • 34
  • 3