- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 05:37 AM
Hello all,
I'm trying to download a new IOSXE on a C9200 from FTP server with a NetMRI Python Script.
Unfortunately I'm running into a timout while the IOS is copied.
My copy line looks like that:
easy.send_command("copy ftp://{}{} flash:".format(server, newIOS))
The execution of the command is successfull, but the copy process is too long.
I tried to set my script to sleep for 6 minutes after the copy line with time.sleep(360).
Also I tried the send_async_command:
easy.send_async_command("copy ftp://{}{} flash:".format(server, newIOS), 360)
This got me a new error. The send_async_command needs a further argument.
The Script-Timeout is set to 3600.
Nothing of that fixed my problem.
Do you guys have an idea how to fix it?
Any help would be much appreciated!
Solved! Go to Solution.
Re: Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 08:22 AM
Can you post the entire script? Easier to troubleshoot
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 10:14 AM
Thanks for your reply.
This is my script until now.
# BEGIN-SCRIPT-BLOCK # Script-Timeout: 3600 # Script-Filter: # $Vendor eq "Cisco" and $sysDescr like /IOSXE/ #Script-Variables: # $serverPath string "Path" # $newIOS string "IOS" # $checkSize boolean # $fileSize string "file size" # $checkMD5 boolean # $md5 string "MD5" # END-SCRIPT-BLOCK from netmri_easy import NetMRIEasy import time import sys defaults = { "api_url": api_url, "http_username": http_username, "http_password": http_password, "job_id": job_id, "device_id": device_id, "batch_id": batch_id } with NetMRIEasy(**defaults) as easy: ver = easy.send_command("show version") if "C9200" in ver: flashContent = easy.send_command("dir | i {}".format(newIOS)) if newIOS in flashContent: if checkSize: if fileSize in flashContent: print("size okay") else: print('size not okay', file=sys.stderr) sys.exit() if checkMD5: verifyMD5 = easy.send_command("verify /md5 flash:{} {}".format(newIOS, md5)) if "Verified" in verifyMD5: print("md5 okay") else: print('md5 not okay', file=sys.stderr) sys.exit() easy.send_command("conf t") easy.send_command("no boot system") easy.send_command("boot system flash:{}".format(newIOS)) easy.send_command("end") easy.send_command("wr") else: easy.send_command("conf t") easy.send_command("file prompt quiet") easy.send_command("end") easy.send_command("copy ftp://{}{} flash:".format(serverPath, newIOS)) easy.send_command("conf t") easy.send_command("file prompt alert") easy.send_command("end") easy.send_command("wr") if checkSize: if fileSize in flashContent: print("size okay") else: print('size not okay', file=sys.stderr) sys.exit() if checkMD5: verifyMD5 = easy.send_command("verify /md5 flash:{} {}".format(newIOS, md5)) if "Verified" in verifyMD5: print("md5 okay") else: print('md5 not okay', file=sys.stderr) sys.exit() easy.send_command("conf t") easy.send_command("no boot system") easy.send_command("boot system flash:{}".format(newIOS)) easy.send_command("end") easy.send_command("wr") else: print('wrong switch model', file=sys.stderr) sys.exit()
Re: Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 12:49 PM
Your code seems to be fine, what version of NetMRI are you running?
I know we did this issue, I would open a support case for this and Ping me on our Slack Channel
Go here if you are not a member
https://github.com/infobloxopen/netmri-toolkit
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 10:24 PM
We are running NetMRI version 7.4.1.95749
Today I will update to 7.4.2.97106
I joined the Channel.
Re: Python Script abort while downloading file from FTP to Switch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 10:34 AM
Support told me to use the send_async_command and add a regex pattern to match the next prompt.
The command syntax is:
send_async_command(command, timeout, regex)
In my case:
send_async_command("copy ftp://{}{} flash:".format(server, newIOS), 360, ".*#")