def editDutConfig(connection, dutUrl, configDict): ''' This method is used to modify the settings found in the dutConfig page and its subpages Returns a dictionary with either the reply from the server for patch/delete and the objectId for post actions as value, and the corresponding networkDict as a key Args: - connection is the connection object that manages the HTTP data transfers between the client and the REST API - dutUrl is the address of the dut that needs to be changed/modified - configDict is a list that contains the actions needed to be performed on the target DUT, and dictionaries with the information required for every action Example dictionary: { "post": { "originateNetwork.": {} "originateNetwork.": { "ipCount": "200", "firstIp": "10.10.10.10" } } "patch": { "terminateNetwork.": { "ipCount": "500" } } } 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