# Get credentials from user if not already set
user, pw = ufn.getUserCredentials(user, pw)
# Store user credentials in creds class
creds = fn.setUserCredentials(user, pw)

# If emailList not predefined, ask user for filename.  Prepend with input directory
emailList = inputDirectory + ufn.userGetFileName(emailList, '')

# Store user credentials in 'authentication' variable
authenticiation = (creds.un, creds.pw)
# Start O365 session with credentials
m = o3.Message(auth=authenticiation)

# Import file contents
fileLines = fn.readFromFile(emailList)

# Count how many email addresses are in the import file
emailCount = fn.file_len(emailList)

# Get current time for later calculations on how long script took to run
startTime = fn.getCurrentTime()

# Counter for progress bar
i = 0
# Progress bar for each email address listed in file
fn.printProgress(i, emailCount, prefix='Progress:', suffix='Complete')

# For each line extracted from the file, loop
for line in fileLines:
    # Split each line on whitespace
switchFileName = 'switches.txt'							# File with a list of all corporate host device IP addresses
inputDirectory = 'textfiles/'							# File directory for any data files used by this script
### /Variables ###


# Get credentials from user if not already set
user, pw = ufn.getUserCredentials(user, pw)
# Store user credentials in creds class
creds = fn.setUserCredentials(user, pw)

# If switchFileName not predefined, ask user for filename.  Prepend with input directory
switchFileName = inputDirectory + ufn.userGetCorpSWFileName(switchFileName)

print "\n"
# Import file contents
fileLines = fn.readFromFile(switchFileName)

# Count how many switches are in the import file
switchCount = fn.file_len(switchFileName)

# Counter for progress bar
i = 0

# Progress bar for each switch listed in file
fn.printProgress(i, switchCount, prefix = 'Progress:', suffix = 'Complete')

# For each line extracted from the file, loop
for line in fileLines:
	# Split each line on whitespace
	line = line.split(',')
	# Set switch name and IP variables
示例#3
0
from lib.user_functions import userGetSwitchFileName


### Variables ###
# Script variables
devicesFileName = 'devices_full.txt'					# File with a list of all corporate host device IP addresses
inputDirectory = 'textfiles/'							# File directory for any data files used by this script
### /Variables ###


# If devicesFileName not predefined, ask user for filename.  Prepend with input directory
devicesFileName = inputDirectory + userGetSwitchFileName(devicesFileName)

print "\n"
# Import file contents
fileLines = fn.readFromFile(devicesFileName)

# Count how many switches are in the import file
switchCount = fn.file_len(devicesFileName)

# For each line extracted from the file, loop
for line in fileLines:
	# Split each line on whitespace
	line = line.split(',')
	# Set switch name and IP variables
	switchName = line[0]
	switchIP = line[1]
	# If 'line' is empty/all whitespace, this will fail
	try:
		# Attempts to lookup imported network device by name
		socket.gethostbyname(switchName)
inputDirectory = 'textfiles/'							# File directory for any data files used by this script
outputDirectory = 'configbackups/'						# File directory with files for logging output
### /Variables ###


# Get credentials from user if not already set
user, pw = ufn.getUserCredentials(user, pw)
# Store user credentials in creds class
creds = fn.setUserCredentials(user, pw)

# If inputFileName not predefined, ask user for filename.  Prepend with input directory
inputFileName = inputDirectory + ufn.userGetFileName(inputFileName, '')


# Import file contents
fileLines = fn.readFromFile(inputFileName)
# Count how many devices are in the import file
deviceCount = fn.file_len(inputFileName)
# Tell user we are working on each device as we go
print "\nRunning script on the %s imported devices:\n" % deviceCount
# Counter for progress bar
i = 0
# Progress bar for user on device count
fn.printProgress(i, deviceCount, prefix = 'Progress:', suffix = 'Complete')
# Get current time for later calculations on how long script took to run
startTime = fn.getCurrentTime()

# Get current time in format that can be appended to file name
currentDate = time.strftime("%m-%d-%Y")
currentTime = time.strftime("%H%M")
outputDirectory = "%s/%s" % (outputDirectory, currentDate)