def assignPorts(connection, sessionUrl, portListPerCommunity): ''' This method is used to assign ports from a connected chassis to the required NetTraffics. Args: - connection is the connection object that manages the HTTP data transfers between the client and the REST API - sessionUrl is the address of the session that should run the test - portListPerCommunity is the dictionary mapping NetTraffics to ports (format -> { community name : [ port list ] }) ''' communityListUrl = "%s/ixload/test/activeTest/communityList" % sessionUrl communityList = connection.httpGet(url=communityListUrl) communityNameList = [community.name for community in communityList] for communityName in portListPerCommunity: if communityName not in communityNameList: errorMsg = "Error while executing assignPorts operation. Invalid NetTraffic name: %s. This NetTraffic is not defined in the loaded rxf." % communityName raise Exception(errorMsg) for community in communityList: if portListPerCommunity.get(community.name): portListForCommunity = portListPerCommunity.get(community.name) portListUrl = "%s/%s/network/portList" % (communityListUrl, community.objectID) for portTuple in portListForCommunity: chassisId, cardId, portId = portTuple paramDict = {"chassisId": chassisId, "cardId": cardId, "portId": portId} performGenericPost(connection, portListUrl, paramDict) else: errorMsg = "Error while executing assignPorts operation. For community: %s you dont't have ports assigned." % community.name raise Exception(errorMsg)