Permalink
Browse files

DownloadRouterConfig.py 2.15 (2013-07-10)

DownloadRouterConfig.py 2.15 (2013-07-10)
-----------------------------------------
+ Updated the file open operation to specify opening the routers.lst
file
as read only.
+ Minor corrections to the IOError message.
  • Loading branch information...
aaronmelton committed Jul 10, 2013
1 parent d90ffb2 commit c66b7adfe49fd83a8eb128b56aefe8dd9879ac1d
Showing with 17 additions and 10 deletions.
  1. +6 −0 CHANGELOG
  2. +11 −10 DownloadRouterConfig.py
View
@@ -1,3 +1,9 @@
+DownloadRouterConfig.py 2.15 (2013-07-10)
+-----------------------------------------
++ Updated the file open operation to specify opening the routers.lst file
+ as read only.
++ Minor corrections to the IOError message.
+
DownloadRouterConfig.py 2.14 (2013-04-16)
-----------------------------------------
! Determined there was no bug with the queuing function; I was passing
View
@@ -31,20 +31,21 @@
from Exscript.util.report import status,summarize
logger = Logger() # Log stuff
-@log_to(logger) # Logging descriptor
-@autologin() # Exscript login descriptor
+@log_to(logger) # Logging descriptor
+@autologin() # Exscript login descriptor
def downloadRouterConfig(job, host, socket):
socket.execute('terminal length 0') # Disable user-prompt to page through config
# Exscript doesn't always recognize Cisco IOS
# for socket.autoinit() to work correctly
+
socket.execute('show run') # Show running config
configDirectory = ('configs_'+date+'/') # Define directory to hold config files
if not os.path.exists(configDirectory): os.mkdir(configDirectory) # Create config file directory if it doesn't exist
outputFileName = host.get_name()+'_Config_'+date+'.txt' # Define output filename based on hostname and date
- outputFile = file(configDirectory+outputFileName,'w') # Open output file (will overwrite contents)
+ outputFile = file(configDirectory+outputFileName, 'w') # Open output file (will overwrite contents)
outputFile.write(socket.response) # Write contents of running config to output file
outputFile.close() # Close output file
@@ -54,14 +55,14 @@ def downloadRouterConfig(job, host, socket):
# Determine OS in use and clear screen of previous output
os.system('cls' if os.name=='nt' else 'clear')
-print 'Download Router Configuration v2.14'
+print 'Download Router Configuration v2.15'
print '-----------------------------------'
print
-try: # Check for existance of 'routers.lst'; If exists, continue with program
- with open('routers.lst'): pass
+try:# Check for existance of 'routers.lst'; If exists, continue with program
+ with open('routers.lst', 'r'): pass
# Define 'date' variable for use in the output filename
- date = datetime.datetime.now() # Determine today's date
+ date = datetime.datetime.now() # Determine today's date
date = date.strftime('%Y%m%d') # Format date as YYYYMMDD
# Read hosts from specified file & remove duplicate entries, set protocol to SSH2
@@ -78,11 +79,11 @@ def downloadRouterConfig(job, host, socket):
print status(logger) # Print current % status of operation to screen
logFile = open('status_'+date+'.log', 'w') # Open 'status.log' file
- logFile.write(summarize(logger)) # Write results of program to file
- logFile.close() # Close 'status.log' file
+ logFile.write(summarize(logger)) # Write results of program to file
+ logFile.close() # Close 'status.log' file
except IOError: # If 'routers.lst' does not exist, provide error and quit
- print 'File routers.lst does not exist!'
+ print 'File \'routers.lst\' does not exist!'
print 'Please create a file named \'routers.lst\' and place it in the same directory'
print 'as the script. This file must contain a list, one per line, of hostnames or IP'
print 'addresses the application will then connect to download the running-config.'

0 comments on commit c66b7ad

Please sign in to comment.