def assignChassisAndPorts(self, communityPortListDict): """ Assign ports. Parameter communityPortListDict: : A list of community ports. Example shown below. Usage: NOTE: Traffic#@Network# are the names from your configuration. You must know what they are. If all the ports are in the same chassis: communityPortList = { 'chassisIp': '192.168.70.128', 'Traffic1@Network1': [(1,1)], 'Traffic2@Network2': [(2,1)] } restObj.assignChassisAndPorts([communityPortList]) If ports are on different chassis, create two dicts. communityPortList1 = { 'chassisIp': '192.168.70.128', 'Traffic1@Network1': [(1,1)] } communityPortList2 = { 'chassisIp': '192.168.70.129', 'Traffic2@Network2': [(1,1), } restObj.assignChassisAndPorts([communityPortList1, communityPortList2]) """ if type(communityPortListDict) == dict: # Make this updated API backward compatible by passing in one dict versus a list. communityPortListDict = [communityPortListDict] for communityPorts in communityPortListDict: # Assign Chassis chassisIp = communityPorts['chassisIp'] newChassisId, locationUrl = self. addNewChassis(chassisIp) self.logInfo('assignChassisAndPorts: To new chassis: %s' % locationUrl, timestamp=False) # Assign Ports communityListUrl = self.sessionIdUrl+'/ixLoad/test/activeTest/communityList/' communityList = self.get(communityListUrl) self.refreshConnection(locationUrl=locationUrl) self.waitForChassisIpToConnect(locationUrl=locationUrl) failedToAddList = [] communityNameNotFoundList = [] for eachCommunity in communityList.json(): currentCommunityObjectId = str(eachCommunity['objectID']) currentCommunityName = eachCommunity['name'] if currentCommunityName not in communityPorts: continue if communityNameNotFoundList == []: for eachTuplePort in communityPorts[currentCommunityName]: # Going to ignore user input chassisId. When calling addNewChassis(), # it will verify for chassisIp exists. If exists, it will return the # right chassisID. cardId,portId = eachTuplePort params = {"chassisId":int(newChassisId), "cardId":cardId, "portId":portId} url = communityListUrl+str(currentCommunityObjectId)+'/network/portList' self.logInfo('assignChassisAndPorts URL: %s' % url, timestamp=False) self.logInfo('assignChassisAndPorts Params: %s' % json.dumps(params), timestamp=False) response = self.post(url, data=params, ignoreError=True) if response.status_code != 201: portAlreadyConnectedMatch = re.search('.*has already been assigned.*', response.json()['error']) if portAlreadyConnectedMatch: self.logInfo('%s/%s is already assigned' % (cardId,portId), timestamp=False) else: failedToAddList.append((newChassisId,cardId,portId)) self.logInfo('\nassignChassisAndPorts failed: %s' % response.text) if communityNameNotFoundList != []: raise IxLoadRestApiException if failedToAddList != []: if self.deleteSession: self.abortActiveTest() raise IxLoadRestApiException('Failed to add ports to chassisIp %s: %s:' % (chassisIp, failedToAddList))