<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic cisco OS upload with Python Script in DevNet General Discussions</title>
    <link>https://community.cisco.com/t5/devnet-general-discussions/cisco-os-upload-with-python-script/m-p/4544608#M1471</link>
    <description>&lt;P&gt;&lt;U&gt;I have developed the following python script to help me upload NX-OS images to the Cisco Nexus switches.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;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 &lt;A title="Employee Connection Insite" href="https://www.employeeconnection.one/" target="_self"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#333300"&gt;Employee Connection Insite&lt;/FONT&gt;&lt;/FONT&gt;&lt;/A&gt;: 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.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;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.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;I am posting only relevant parts of the script:&lt;/U&gt;&lt;/P&gt;&lt;PRE&gt;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()&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Feb 2022 08:19:41 GMT</pubDate>
    <dc:creator>davelittle260</dc:creator>
    <dc:date>2022-02-03T08:19:41Z</dc:date>
    <item>
      <title>cisco OS upload with Python Script</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/cisco-os-upload-with-python-script/m-p/4544608#M1471</link>
      <description>&lt;P&gt;&lt;U&gt;I have developed the following python script to help me upload NX-OS images to the Cisco Nexus switches.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;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 &lt;A title="Employee Connection Insite" href="https://www.employeeconnection.one/" target="_self"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#333300"&gt;Employee Connection Insite&lt;/FONT&gt;&lt;/FONT&gt;&lt;/A&gt;: 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.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;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.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;I am posting only relevant parts of the script:&lt;/U&gt;&lt;/P&gt;&lt;PRE&gt;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()&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Feb 2022 08:19:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/cisco-os-upload-with-python-script/m-p/4544608#M1471</guid>
      <dc:creator>davelittle260</dc:creator>
      <dc:date>2022-02-03T08:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: cisco OS upload with Python Script</title>
      <link>https://community.cisco.com/t5/devnet-general-discussions/cisco-os-upload-with-python-script/m-p/4544809#M1472</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1307262"&gt;@davelittle260&lt;/a&gt;&amp;nbsp;take a look at this thread&amp;nbsp;&lt;A href="https://community.cisco.com/t5/other-networking-subjects/automating-ios-upgrade-python-script-throws-error-quot-socket/td-p/4469377" target="_blank"&gt;https://community.cisco.com/t5/other-networking-subjects/automating-ios-upgrade-python-script-throws-error-quot-socket/td-p/4469377&lt;/A&gt;&amp;nbsp;and comment from&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/54916"&gt;@Claudia de Luna&lt;/a&gt;&amp;nbsp;to this might help.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 13:56:45 GMT</pubDate>
      <guid>https://community.cisco.com/t5/devnet-general-discussions/cisco-os-upload-with-python-script/m-p/4544809#M1472</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2022-02-03T13:56:45Z</dc:date>
    </item>
  </channel>
</rss>

