cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
501
Views
0
Helpful
1
Replies

cisco OS upload with Python Script

davelittle260
Level 1
Level 1

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 Employee Connection Insite: 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()
1 Reply 1

@davelittle260 take a look at this thread https://community.cisco.com/t5/other-networking-subjects/automating-ios-upgrade-python-script-throws-error-quot-socket/td-p/4469377 and comment from @Claudia de Luna to this might help.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io