def getPortObjectId(connection, sessionUrl, communityPortIdTuple): ''' This method is used to get the objectID of a port from a communityList. Args: - connection is the connection object that manages the HTTP data transfers between the client and the REST API - communityPortIdTuple is a tuple composed of (communityID and portName) - communityID is the id of the community list for which captures should be retrieved. - portName is the name of the port for which the objectID will be retrieved ( in the following format:'1.5.1') - sessionUrl is the address of the session on which the test was ran. ''' communityObjectID, portID = communityPortIdTuple communityUrl = sessionUrl + ("/ixload/test/activeTest/communityList/%s/network/portList" % communityObjectID) portList = connection.httpRequest('GET', communityUrl).json() objectID = None for port in portList: if port['id'] == portID: objectID = port["objectID"] break if objectID is None: raise Exception("Could not find port with id '%s' on community with id '%s'" % (portID, communityObjectID)) return objectID } Format for network/protocol names: - Server Load Balancer: slb. - Packet Switch: originateNetwork., terminateNetwork., terminateProtocolPort., originateProtocolPort. - Virtual DUT: network., protocolPort. ''' actionDict = { "post": performGenericPost, "patch": performGenericPatch, "delete": performGenericDelete } # We hard code the order in which we want the actions to be performed actionOrder = ["post", "patch", "delete"] noRangeListDuts = ["Firewall", "ExternalServer"] rangeListDuts = ["PacketSwitch", "ServerLoadBalancer", "VirtualDut"] dutType = connection.httpGet(dutUrl).type dutRangesInfo = {} if dutType in noRangeListDuts: dutConfigUrl = "%s/dutConfig" % (dutUrl) performGenericPatch(connection, dutConfigUrl, configDict) elif dutType in rangeListDuts: for action in actionOrder: if action in configDict: for networkInfo in configDict[action]: networkInfoList = networkInfo.split('.') if action == "post": dutListUrl = "%s/dutConfig/%sRangeList" % (dutUrl, networkInfoList[0]) else: dutListUrl = "%s/dutConfig/%sRangeList/%s" % (dutUrl, networkInfoList[0], networkInfoList[1]) dutRangesInfo[networkInfo] = actionDict[action](connection, dutListUrl, configDict[action][networkInfo]) return dutRangesInfo