def ixiaConnectionDetailGrabber(dutslist, finalConnectionDetails): ixialist = [] for i in range(0, len(dutslist)): try: #We already have a session during the lldp...using the same session a = connectDevices(dutslist[i]) logging.info(" * Getting Ixia Details info from " + dutslist[i]) a, = a listofconnections = a.getConnectedIntfs() #Removing management and port-channel interfaces from list and changing naming scheme from swat's 'et' to my 'Et' for k in range(0, len(listofconnections)): if 'ma' in listofconnections[k] or 'po' in listofconnections[ k] or '.' in listofconnections[k]: listofconnections[k] = None elif 'et' in listofconnections[k]: listofconnections[k] = listofconnections[k].replace( 'et', 'Et') #Removing lldp interfaces from ixia interfaces for j in range(0, len(finalConnectionDetails)): if finalConnectionDetails[j][ 'neighbor'] or finalConnectionDetails[j][ 'myDevice'] == dutslist[i]: if finalConnectionDetails[j]['neighbor'] == dutslist[i]: for k in range(0, len(listofconnections)): if listofconnections[k] == finalConnectionDetails[ j]['neighbor-port']: listofconnections[k] = None if finalConnectionDetails[j]['myDevice'] == dutslist[i]: for k in range(0, len(listofconnections)): if listofconnections[k] == finalConnectionDetails[ j]['port']: listofconnections[k] = None #Makes a dictionary containing the DUT name and the Ixia ports onlyixiaconnections = [] for k in range(0, len(listofconnections)): ixiadict = {} if listofconnections[k] != None: onlyixiaconnections.append(listofconnections[k]) ixiadict['neighbor'] = dutslist[i] ixiadict['neighbor-port'] = listofconnections[k] ixiadict['myDevice'] = 'Ixia' ixiadict['port'] = 'unknown' ixialist.append(ixiadict) except Exception as e: logging.info("[MESSAGE]: Skipping " + dutslist[i] + " from Ixia connection calculation due to error: " + str(e)) continue return ixialist
def lineCardFinderForModularDevices(dut): from initToolLib import connectDevices class ModuleInfo: def getModuleInfo(self, *args): ''' This method returns the information about the modules on a DUT. Inputs : None Outputs: A list containing the names of linecards. ''' # Initialize Variables cmd = 'show module' retVal = [] ##ASSUMING SSH ACCESS .ie. API=False # Goto Appropriate Prompt Level self._enablePrompt() output = self._cliSend(cmd) # Preparing Output data for line in output[1:]: # Ignore Empty Lines if line: retVal.append(line[0].lower()) # Return List of Interfaces return retVal try: a = connectDevices(dut, api=False) a, = a temp = a.getModuleInfo() except: temp = {} #print(temp) varForOnlyLinecards = [ value for key, value in temp.items() if 'Linecard' in key or 'Supervisor' in key ] #print(len(varForOnlyLinecards)) i = 0 lc_list = [] for i in range(0, len(varForOnlyLinecards)): lc_list.append(varForOnlyLinecards[i]['model']) return lc_list
def lldpInfo(dutslist): #The below code will grab lldp info from all DUTs in json format using SWAT library tempDictOfConnections=[] for i in xrange(0,len(dutslist)): #Getting LLDP info using SWAT library function a=connectDevices(dutslist[i]) logging.info("[MESSAGE]: Getting LLDP info from "+dutslist[i]) a,=a temp = a.getLldpInfo() allneighbors =temp['neighbors'] for j in xrange(0,len(allneighbors)): temp_diction = allneighbors[j] temp_diction['myDevice']=str(dutslist[i]) #+'.sjc.aristanetworks.com' tempDictOfConnections.append(temp_diction) tempDictOfConnections = tempDictOfConnections[:-1] #************************************************************************ #The below code will use regular expresions to get only the DUT name (and not hostname) since some people use naming schemes like ck221_leaf (OR) s1_ckp355 regex = r"(?:[^\-_\+\|\.]*)[a-z][a-z][0-9][0-9][0-9](?:[^\-_\+\|\.]*)" for i in xrange(0,len(tempDictOfConnections)): #For neighbor names test_str = tempDictOfConnections[i]['neighbor'] matches = re.search(regex, test_str, re.IGNORECASE) tempDictOfConnections[i]['neighbor']= matches.group() #For my device names test_str = tempDictOfConnections[i]['myDevice'] matches = re.search(regex, test_str, re.IGNORECASE) tempDictOfConnections[i]['myDevice']= matches.group() #************************************************************************ #The below code will remove the duplicates from the grand dictionary such that one connection shows up only once. The duplicates are marked as key=temp and value=NULL for i in xrange(0,len(tempDictOfConnections)): tempvar= tempDictOfConnections[i] #Storing each dictionary in one temp variable instantaneoustempvar= [] instantaneoustempvar=[tempvar['neighbor'],tempvar['neighbor-port']] tempvar['neighbor']= tempvar['myDevice'] tempvar['neighbor-port']= tempvar['port'] tempvar['myDevice']=instantaneoustempvar[0] tempvar['port']=instantaneoustempvar[1] count=0 for j in xrange(0,len(tempDictOfConnections)): if tempvar == tempDictOfConnections[j]: count=count+1 if count==2: tempDictOfConnections[i]={'temp':'Null'} #************************************************************************ #The below code will remove the duplicates completely by removing dictionaries with key as temp. ALso, removing the '.sjc.aristanetworks.com' in DUT name dictionaryOfConnections=[] #This list will have only non-duplicate values for i in xrange(0,len(tempDictOfConnections)): if tempDictOfConnections[i].get('temp')== None: tempDictOfConnections[i]['neighbor']=tempDictOfConnections[i]['neighbor'].split('.')[0] tempDictOfConnections[i]['myDevice']=tempDictOfConnections[i]['myDevice'].split('.')[0] try: tempDictOfConnections[i]['port']='Et'+(tempDictOfConnections[i]['port'].split('Et')[1]) tempDictOfConnections[i]['neighbor-port']='Et'+(tempDictOfConnections[i]['neighbor-port'].split('Et')[1]) except: #This block will not make any changes to non-Arista devices continue dictionaryOfConnections.append(tempDictOfConnections[i]) return dictionaryOfConnections
##ASSUMING SSH ACCESS .ie. API=False # Goto Appropriate Prompt Level self._enablePrompt() output = self._cliSend(cmd) # Preparing Output data for line in output[1:]: # Ignore Empty Lines if line: retVal.append(line[0].lower()) # Return List of Interfaces return retVal a = connectDevices(dut, api=False) a, = a temp = a.getModuleInfo() #print(temp) varForOnlyLinecards = [ value for key, value in temp.items() if 'Linecard' in key or 'Supervisor' in key ] #print(len(varForOnlyLinecards)) i = 0 lc_list = [] for i in range(0, len(varForOnlyLinecards)): lc_list.append(varForOnlyLinecards[i]['model']) print(lc_list)