Esempio n. 1
0
def printConnectionsToScreen(dictionaryOfConnections):

    try:
        f = open("TopologyGenerated.txt", "w+")

        logging.info("\n> The topology in text format is: ")
        f.write("\n> The topology in text format is: \n")

        for i in range(0, len(dictionaryOfConnections)):
            output = dictionaryOfConnections[i][
                'neighbor'] + '\t(' + dictionaryOfConnections[i][
                    'neighbor-port'] + ')' + '\t--------------------' + '\t(' + dictionaryOfConnections[
                        i]['port'] + ')' + dictionaryOfConnections[i][
                            'myDevice']
            f.write(output)
            f.write('\n')
            logging.info(output)

        f.write('\n \n ---Script Generated by topoGen.py SWAT Tool----\n')
        f.close()

    except IOError:
        logging.info(
            "[ERROR]: Permission Denied for generating files in this directory. Please fix it to proceed..."
        )
        abort("* Finished!")

    logging.info(
        "\n ---------------------------------------------------------------------------------------------------------------------- \n "
    )
Esempio n. 2
0
def mainFunc(username, poolname, filePath, graphrequired, intfInfo, excludeDuts, includeIxiaPorts, consolidateInterfaces):

	#The below part is used to handle cases of username and/or filePathation provided
	if not username and not filePath:
		logging.info("\n \n ----------------------------------------------------------------------------------------------------------------------  \n")
		logging.info(('[MESSAGE]: Username has not been provided. Using file for Topology generation'))
		filePath = os.path.expanduser('~/setup.txt') #Default File location
		logging.info(('[MESSAGE]: Default file at ~/setup.txt is used since custom file locaton as not been provided using -f flag'))
		finalListOfDuts= fileDutList(username, filePath)

	elif not username and filePath:
		logging.info("\n \n ----------------------------------------------------------------------------------------------------------------------  \n")
		logging.info(('[MESSAGE]: Username has not been provided. Using file for Topology generation'))
		finalListOfDuts= fileDutList(username, filePath)
	
	else:
		if filePath:
			logging.info("\n \n ----------------------------------------------------------------------------------------------------------------------  \n")
			logging.info(('[WARNING]: You have provided both a DUTS list file as well as username. Username has higher priority for Topology generation and will be considered. Ignoring the DUT file info...'))

		finalListOfDuts= userDutList(username, poolname) #login to us128 and grab the list of DUTs owned by current user and return a list containing the DUTs


	#This is used to remove the excludeDuts DUTs from the topology generation
	if excludeDuts:
		finalListOfDuts=excludedFromList(finalListOfDuts,excludeDuts)	

	warningMessage() #Will warn users about the list of reasons why the script could fail
	  	
	finalConnectionDetails= lldpInfo(finalListOfDuts) #does the work of grabbing lldp info from all the DUTs, and removing duplicates 

  	#This is used to include Ixia Connections as well based on user flag for ixia
	if not includeIxiaPorts:
		finalConnectionDetails=finalConnectionDetails	
	else:
		listOfIxiaConnections= ixiaConnectionDetailGrabber(finalListOfDuts, finalConnectionDetails) 
		finalConnectionDetails=finalConnectionDetails+listOfIxiaConnections

	#This is used to consolidate the links between same two devices
	if consolidateInterfaces:
		finalConnectionDetails=connectionConsolidator(finalConnectionDetails)		

	printConnectionsToScreen(finalConnectionDetails)

	if not graphrequired:
		logging.info('[MESSAGE]: Graph not generated due to user choice')
		logging.info("* Text file named 'TopologyGenerated.txt' has been created on the same directory containing LLDP info")
		abort('* Script Complete!')
	else:
		while True:
			userchoice = raw_input("Do you have a preference of Leaf-Spine for the DUTs (yes/no)? Type 'no' if you have no clue it means:  ")
			if userchoice=='n' or userchoice=='no' or userchoice=='N':
				automaticGraphGenerator(finalConnectionDetails, intfInfo) #generates a graphical representation with random location of DUTs
				break
			elif userchoice=='y' or userchoice=='yes' or userchoice=='Y':
				graphGeneratorwithLeafSpine(finalConnectionDetails, intfInfo) #generates a graphical representation with location levels chosen by user
				break
			else:
				print ("Please choose one of the above Choices")
Esempio n. 3
0
def fileDutList(username,filePath):
	try:

		listofdutsasperfile=[]
		temp=[]

		file = open(filePath)
		listofdutsasperfile = file.readlines()

		for i,data in enumerate(listofdutsasperfile):
			if '#' in data[0] or '\n' in data[0]:
				listofdutsasperfile[i]=None

		for i,data in enumerate(listofdutsasperfile):
			if data!=None:
				temp.append(data.strip())

		logging.info("\n > List of DUTS as per the file provided is:")
		logging.info("\t * "+str(temp))
		return temp
	except IOError:
		logging.info("\n[ERROR]: File does not exist in "+filePath+" . Please ensure correct file location to proceed \n")
		abort()
Esempio n. 4
0
def graphGeneratorwithLeafSpine(dictionaryOfConnections,intfInfo):

	# This part below checks the number of DUTs and connections and based on it, it creates containers for the graphviz code
	if len(dictionaryOfConnections)>20:
		graph_string='''
		digraph finite_state_machine {	
		node [shape = box];
		rankdir="LR"
		'''

	if len(dictionaryOfConnections)<=20:
		graph_string='''
		digraph finite_state_machine {	
		node [shape = box];
		'''

	nooflevels=raw_input("Please enter the number of levels in your topology. Eg) Leaf-Spine is 2 levels and Leaf-Spine-Superspine is 3 levels. (Enter a integer:) ")

	alreadyadded=[]
	dictoflevels={}

	#The below block is used for getting the levels of DUTs (.ie. whether leaf/spine/super-spine/...) from user
	for i in xrange(1,(int(nooflevels)+1)):
		dictoflevels[i]=[]
	try:
		for i in xrange(0,len(dictionaryOfConnections)):
			if dictionaryOfConnections[i]['neighbor']==dictionaryOfConnections[i]['myDevice']:
				if dictionaryOfConnections[i]['neighbor'] not in alreadyadded:
					alreadyadded.append(dictionaryOfConnections[i]['neighbor'])
					value=raw_input ("Enter the level/hierarchy in range of 1 to "+nooflevels+" (with 1 being lowest) of "+dictionaryOfConnections[i]['neighbor'] +": ")
					dictoflevels[int(value)].append(dictionaryOfConnections[i]['neighbor'])
			else:
				if dictionaryOfConnections[i]['neighbor'] not in alreadyadded:
					alreadyadded.append(dictionaryOfConnections[i]['neighbor'])
					value=raw_input ("Enter the level/hierarchy in range of 1 to "+nooflevels+" (with 1 being lowest) of "+dictionaryOfConnections[i]['neighbor'] +": ")
					dictoflevels[int(value)].append(dictionaryOfConnections[i]['neighbor'])
				if dictionaryOfConnections[i]['myDevice'] not in alreadyadded:
					alreadyadded.append(dictionaryOfConnections[i]['myDevice'])
					value=raw_input ("Enter the level/hierarchy in range of 1 to "+nooflevels+" (with 1 being lowest) of "+dictionaryOfConnections[i]['myDevice'] +": ")
					dictoflevels[int(value)].append(dictionaryOfConnections[i]['myDevice'])		
	except KeyError as e:
		logging.info('[ERROR] The entered value is outside the range of total levels. Please rerun again...')
		abort('* Script Complete')
		

	#The below block is for handling '-' and '.' being present in DUT name since it causes error in graphviz
	for i in xrange(0,len(dictionaryOfConnections)):
		if '-' in dictionaryOfConnections[i]['neighbor'] or '-' in dictionaryOfConnections[i]['myDevice'] or '.' in dictionaryOfConnections[i]['neighbor'] or '.' in dictionaryOfConnections[i]['myDevice']:
			if '-' in dictionaryOfConnections[i]['neighbor'] or '.' in dictionaryOfConnections[i]['neighbor']:
				if '-' in dictionaryOfConnections[i]['neighbor']:
					new_str=string.replace(dictionaryOfConnections[i]['neighbor'], '-', '_')
				if '.' in dictionaryOfConnections[i]['neighbor']:
					new_str=string.replace(dictionaryOfConnections[i]['neighbor'], '.', '_')
				dictionaryOfConnections[i]['neighbor']=new_str
			if '-' in dictionaryOfConnections[i]['myDevice'] or '.' in dictionaryOfConnections[i]['myDevice']:
				if '-' in dictionaryOfConnections[i]['myDevice']:
					new_str=string.replace(dictionaryOfConnections[i]['myDevice'], '-', '_')
				if '.' in dictionaryOfConnections[i]['myDevice']:
					new_str=string.replace(dictionaryOfConnections[i]['myDevice'], '.', '_')
				dictionaryOfConnections[i]['myDevice']=new_str


	#Creating container blocks
	graph_string=graph_string+"\n\ncompound=True;"

	if (int(nooflevels))==2:
		graph_string=graph_string+"\n\nsubgraph level_master {"

		#j=1 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave1 {"
		graph_string=graph_string+'''
		rank=max;
		node[style=filled, shape=box,color=green, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[1])):   #j=1 so dictoflevels[1]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[1][k] or '.' in dictoflevels[1][k]: 
				if '-' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '-', '_')
					dictoflevels[1][k]=new_str
				if '.' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '.', '_')
					dictoflevels[1][k]=new_str

			graph_string=graph_string+dictoflevels[1][k]+";\n"
		graph_string=graph_string+"}" #closing slave1

		#j=2 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave2 {"
		graph_string=graph_string+'''
		rank=min;
		node[style=filled, shape=box,color=red, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[2])):   #j=2 so dictoflevels[2]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[2][k] or '.' in dictoflevels[2][k]: 
				if '-' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '-', '_')
					dictoflevels[2][k]=new_str
				if '.' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '.', '_')
					dictoflevels[2][k]=new_str

			graph_string=graph_string+dictoflevels[2][k]+";\n"
		graph_string=graph_string+"}" #Closing slave2

		graph_string=graph_string+"}" #Closing master

	if (int(nooflevels))==3:
		graph_string=graph_string+"\n\nsubgraph level_master {"

		graph_string=graph_string+"\n\nsubgraph level_topmaster {"
		graph_string=graph_string+'''
		rank=min;
		'''

		graph_string=graph_string+"\n\nsubgraph level_submaster2 {"
		graph_string=graph_string+'''
		rank=min;
		node[style=filled, shape=box,color=red, fontsize=8];

		'''			
		for k in xrange(0,len(dictoflevels[3])):   #j=3 so dictoflevels[3]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[3][k] or '.' in dictoflevels[3][k]: 
				if '-' in dictoflevels[3][k]:
					new_str=string.replace(dictoflevels[3][k], '-', '_')
					dictoflevels[3][k]=new_str
				if '.' in dictoflevels[3][k]:
					new_str=string.replace(dictoflevels[3][k], '.', '_')
					dictoflevels[3][k]=new_str

			graph_string=graph_string+dictoflevels[3][k]+";\n"
		graph_string=graph_string+"}" #closing submaster2		

		graph_string=graph_string+"}" #Closing topmaster


		graph_string=graph_string+"\n\nsubgraph level_middlemaster {"
		graph_string=graph_string+'''
		rank=max;
		'''

		#j=1 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave1 {"
		graph_string=graph_string+'''
		rank=max;
		node[style=filled, shape=box,color=green, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[1])):   #j=1 so dictoflevels[1]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[1][k] or '.' in dictoflevels[1][k]: 
				if '-' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '-', '_')
					dictoflevels[1][k]=new_str
				if '.' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '.', '_')
					dictoflevels[1][k]=new_str

			graph_string=graph_string+dictoflevels[1][k]+";\n"
		graph_string=graph_string+"}" #closing slave1

		#j=2 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave2 {"
		graph_string=graph_string+'''
		rank=min;
		node[style=filled, shape=box,color=yellow, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[2])):   #j=2 so dictoflevels[2]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[2][k] or '.' in dictoflevels[2][k]: 
				if '-' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '-', '_')
					dictoflevels[2][k]=new_str
				if '.' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '.', '_')
					dictoflevels[2][k]=new_str

			graph_string=graph_string+dictoflevels[2][k]+";\n"
		graph_string=graph_string+"}" #Closing slave2

		graph_string=graph_string+"}" #Closing middlemaster
		graph_string=graph_string+"}" #Closing master

	if (int(nooflevels))==4:
		graph_string=graph_string+"\n\nsubgraph level_master {"

		graph_string=graph_string+"\n\nsubgraph level_topmaster {"
		graph_string=graph_string+'''
		rank=min;
		'''

		graph_string=graph_string+"\n\nsubgraph level_submaster1 {"
		graph_string=graph_string+'''
		rank=min;
		node[style=filled, shape=box,color=blue, fontsize=8];

		'''			
		for k in xrange(0,len(dictoflevels[4])):   #j=4 so dictoflevels[4]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[4][k] or '.' in dictoflevels[4][k]: 
				if '-' in dictoflevels[4][k]:
					new_str=string.replace(dictoflevels[4][k], '-', '_')
					dictoflevels[4][k]=new_str
				if '.' in dictoflevels[4][k]:
					new_str=string.replace(dictoflevels[4][k], '.', '_')
					dictoflevels[4][k]=new_str

			graph_string=graph_string+dictoflevels[4][k]+";\n"
		graph_string=graph_string+"}" #closing submaster1

		graph_string=graph_string+"\n\nsubgraph level_submaster2 {"
		graph_string=graph_string+'''
		rank=max;
		node[style=filled, shape=box,color=red, fontsize=8];

		'''			
		for k in xrange(0,len(dictoflevels[3])):   #j=3 so dictoflevels[3]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[3][k] or '.' in dictoflevels[3][k]: 
				if '-' in dictoflevels[3][k]:
					new_str=string.replace(dictoflevels[3][k], '-', '_')
					dictoflevels[3][k]=new_str
				if '.' in dictoflevels[3][k]:
					new_str=string.replace(dictoflevels[3][k], '.', '_')
					dictoflevels[3][k]=new_str

			graph_string=graph_string+dictoflevels[3][k]+";\n"
		graph_string=graph_string+"}" #closing submaster2		

		graph_string=graph_string+"}" #Closing topmaster


		graph_string=graph_string+"\n\nsubgraph level_middlemaster {"
		graph_string=graph_string+'''
		rank=max;
		'''

		#j=1 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave1 {"
		graph_string=graph_string+'''
		rank=max;
		node[style=filled, shape=box,color=green, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[1])):   #j=1 so dictoflevels[1]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[1][k] or '.' in dictoflevels[1][k]: 
				if '-' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '-', '_')
					dictoflevels[1][k]=new_str
				if '.' in dictoflevels[1][k]:
					new_str=string.replace(dictoflevels[1][k], '.', '_')
					dictoflevels[1][k]=new_str

			graph_string=graph_string+dictoflevels[1][k]+";\n"
		graph_string=graph_string+"}" #closing slave1

		#j=2 container and devices
		graph_string=graph_string+"\n\nsubgraph level_slave2 {"
		graph_string=graph_string+'''
		rank=min;
		node[style=filled, shape=box,color=yellow, fontsize=8];

		'''	
		for k in xrange(0,len(dictoflevels[2])):   #j=2 so dictoflevels[2]

			#Handling '-' or '.' present in the name
			if '-' in dictoflevels[2][k] or '.' in dictoflevels[2][k]: 
				if '-' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '-', '_')
					dictoflevels[2][k]=new_str
				if '.' in dictoflevels[2][k]:
					new_str=string.replace(dictoflevels[2][k], '.', '_')
					dictoflevels[2][k]=new_str

			graph_string=graph_string+dictoflevels[2][k]+";\n"
		graph_string=graph_string+"}" #Closing slave2

		graph_string=graph_string+"}" #Closing middlemaster
		graph_string=graph_string+"}" #Closing master

	
	#The below block is used for adding the connections to DUTs for graph generation

	graph_string=graph_string+'''
	subgraph connector{
	'''	
	#The below loop is for converting the topology to graphviz format. Adding the connection details to the graphviz container created above
	for i in xrange(0,len(dictionaryOfConnections)):
		if intfInfo:
			tempvar=dictionaryOfConnections[i]['neighbor'] + ' -> ' + dictionaryOfConnections[i]['myDevice'] + ' [ label = "' + dictionaryOfConnections[i]['neighbor-port'] + '<------>' + dictionaryOfConnections[i]['port'] + '",labelfontsize=0.5 ]'
		#The below else block is for case when user chose not to include interface labels in topology		
		else:
			tempvar=dictionaryOfConnections[i]['neighbor'] + ' -> ' + dictionaryOfConnections[i]['myDevice']		
		graph_string=graph_string+tempvar+'\n'

	graph_string=graph_string+'}}'


	logging.info("----------------------------------------------------------------------------")
	logging.info("[MESSAGE] If your device names contains either '.' or '-', it will be replaced by '_' to avoid conflict with other packages")
	logging.info("[MESSAGE] If you get a blank file as output, please verify your choice for device levels. Your choice may have given impossible to comprehend/design for our tool \n \n")

	logging.info("> Completed: \n")

	# The below try-except block is for handling errors in graphviz installation due to all the above dependencies on Mac (linux doesn't have much), I try to install brew and then 'brew install graphviz' since brew (unlike apt-get) is not installed by default.
	try:
		s = Source(graph_string, filename="Topology.gv", format="pdf")
		s.view()

		#Send Email with the script
		sendEmailSwatExtension()

	#The below except block is used to install Xcode-Cli tools, brew and graphviz since Mac requires additional dependencies (if not present already)
	except Exception as e:
		logging.info("\n ---------------------------------------------------------------------------------------------------------------------- ")
		logging.info("[ERROR] Looks like we encountered an error. ERROR is:")
		logging.info(e)
		logging.info(" We'll see if installing a few packages fixes it. Please provide your device (Mac/server) password if prompted.")
		logging.info("---------------------------------------------------------------------------------------------------------------------- ")
		#Installing Xcode command-line tools for Mac
		var1= os.system("xcode-select --install")
		#Installing Brew
		var=os.system('''/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"''')
		#Installing Graphviz using brew
		var= os.system("brew install graphviz")
		#This is used to clear the screen ...similar to Ctrl+L in bash
		os.system('tput reset') 


		s = Source(graph_string, filename="Topology.gv", format="pdf")
		s.view()

		#Send Email with the script
		sendEmailSwatExtension()

	#The below code block if for opening the editable .gv file using Omnigraffle if it is installed on the user's Mac. Else, skip and print 'Script Complete'			
	try:
		installationcheckcmd="ls /Applications/ | grep -i OmniGraffle"
		returned_value = subprocess.call(installationcheckcmd, shell=True)

		if returned_value==1: #That means OmniGraffle is NOT present
			logging.info("[MESSAGE] The PDF file (graphic topology) and txt file (text) have been generated in current directory! ") #Instead of OmniGraffle not installed message
			abort("* Script Completed! ")

		elif returned_value==0: #That means OmniGraffle is present
			logging.info("\t * The PDF file (graphic topology) and txt file (text) have been generated in current directory. Also, OmniGraffle has been opened to edit the GV file (graphic topology). Please choose 'Hierarchial' in OmniGraffle to edit it.")
			subprocess.call(
    			["/usr/bin/open", "-W", "-n", "-a", "/Applications/OmniGraffle.app","Topology.gv"]
    		)

	except:
		abort("* Script Complete!")
Esempio n. 5
0
def automaticGraphGenerator(dictionaryOfConnections, intfInfo):

	# This part below checks the number of DUTs and connections and based on it, it creates containers for the graphviz code
	if len(dictionaryOfConnections)>20:
		graph_string='''
		digraph finite_state_machine {	
		size="8,5"
		node [shape = box];
		rankdir="LR"

		'''
	if len(dictionaryOfConnections)<=20:
		graph_string='''
		digraph finite_state_machine {	
		size="8,5"
		node [shape = box];

		'''	
	
	#The below block is for handling '-' and '.' being present in DUT name since it causes error in graphviz
	for i in xrange(0,len(dictionaryOfConnections)):
		if '-' in dictionaryOfConnections[i]['neighbor'] or '-' in dictionaryOfConnections[i]['myDevice'] or '.' in dictionaryOfConnections[i]['neighbor'] or '.' in dictionaryOfConnections[i]['myDevice']:
			if '-' in dictionaryOfConnections[i]['neighbor'] or '.' in dictionaryOfConnections[i]['neighbor']:
				new_str=string.replace(dictionaryOfConnections[i]['neighbor'], '-', '_')
				dictionaryOfConnections[i]['neighbor']=new_str
			if '-' in dictionaryOfConnections[i]['myDevice'] or '.' in dictionaryOfConnections[i]['myDevice']:
				new_str=string.replace(dictionaryOfConnections[i]['myDevice'], '-', '_')
				dictionaryOfConnections[i]['myDevice']=new_str

	#The below block is for converting the topology to graphviz format. Adding the connection details to the graphviz container created above
	for i in xrange(0,len(dictionaryOfConnections)):
		if intfInfo:
			tempvar=dictionaryOfConnections[i]['neighbor'] + ' -> ' + dictionaryOfConnections[i]['myDevice'] + ' [ label = "' + dictionaryOfConnections[i]['neighbor-port'] + '<------>' + dictionaryOfConnections[i]['port'] + '" ]'
		#The below else block is for case when user chose not to include interface labels in topology
		else:
			tempvar=dictionaryOfConnections[i]['neighbor'] + ' -> ' + dictionaryOfConnections[i]['myDevice']
		graph_string=graph_string+tempvar+'\n'

	graph_string=graph_string+'}'

	logging.info("----------------------------------------------------------------------------")
	logging.info("[MESSAGE] If your device names contains either '.' or '-', it will be replaced by '_' to avoid conflict with other packages\n \n")

	logging.info("> Completed:")

	# The below try-except block is for handling errors in graphviz installation due to all the above dependencies on Mac (linux doesn't have much), I try to install brew and then 'brew install graphviz' since brew (unlike apt-get) is not installed by default.
	try:
		s = Source(graph_string, filename="Topology.gv", format="pdf")
		s.view()

		#Send Email with the script
		sendEmailSwatExtension()


	#The below except block is used to install Xcode-Cli tools, brew and graphviz since Mac requires additional dependencies (if not present already)
	except Exception as e:
		logging.info("\n ---------------------------------------------------------------------------------------------------------------------- ")
		logging.info("[ERROR] Looks like we encountered an error. ERROR is:")
		logging.info(e)
		logging.info(" We'll see if installing a few packages fixes it. Please provide your device (Mac/server) password if prompted.")
		logging.info("---------------------------------------------------------------------------------------------------------------------- ")
		#Installing Xcode command-line tools for Mac
		var1= os.system("xcode-select --install")
		#Installing Brew
		var=os.system('''/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"''')
		#Installing Graphviz using brew
		var= os.system("brew install graphviz")
		#This is used to clear the screen ...similar to Ctrl+L in bash
		os.system('tput reset') 


		s = Source(graph_string, filename="Topology.gv", format="pdf")
		s.view()

		#Send Email with the script
		sendEmailSwatExtension()
	

	#The below code block if for opening the editable .gv file using Omnigraffle if it is installed on the user's Mac. Else, skip and print 'Script Complete'	
	try:
		installationcheckcmd="ls /Applications/ | grep -i OmniGraffle"
		returned_value = subprocess.call(installationcheckcmd, shell=True)

		if returned_value==1: #That means OmniGraffle is NOT present
			logging.info("\n [MESSAGE] * The PDF file (graphic topology) and txt file (text) have been generated in current directory! ") #Instead of OmniGraffle not installed message
			abort("* Script Completed!")

		elif returned_value==0: #That means OmniGraffle is present
			logging.info("\t * The PDF file (graphic topology) and txt file (text) have been generated in current directory. Also, OmniGraffle has been opened to edit the GV file (graphic topology). Please choose 'Hierarchial' in OmniGraffle to edit it.")
			subprocess.call(
    			["/usr/bin/open", "-W", "-n", "-a", "/Applications/OmniGraffle.app","Topology.gv"]
    		)

	except:
		abort("* Script Complete!")
Esempio n. 6
0
from scriptLib import abort
try:
	from proxyLib import Proxy, checkProxySession
	#from labLib import findDuts   #Doesn't work due to oauth2client version issue...using proxylib to run Art command directly
except ImportError as e:
	message='''
	If you get import error above, then, you have 2 options to fix it:

	Option A: Run this SWAT tool from your mac and update the oauth2client using "sudo pip install oauth2client==4.1.2" on your mac
	Option B: Run this SWAT tool from a VIRTUALENV on arst or syscon servers using "source /opt/venv/bin/activate" and then update oauth2client using "pip install oauth2client==4.1.2" and then run this script

	WARNING: DO NOT UPDATE oauthclient using 'sudo' on syscon or arst servers since installing this version breaks Art tools..Install it on virtualenv without using 'sudo'
	'''
	print("ERROR: "+ str(e))
	print(message)
	abort('')




#Internal Functions to massage data provided by SWAT and generate graphs

#The below function gets DUTlist from a file
def fileDutList(username,filePath):
	try:

		listofdutsasperfile=[]
		temp=[]

		file = open(filePath)
		listofdutsasperfile = file.readlines()