def flapBgpPeerNgpf(self, bgpObjHandle, enable=True, flapList='all', uptime=0, downtime=0): """ Description Enable or disable BGP flapping on either all or a list of IP interfaces. Parameters bgpObjHandle: The bgp object handle. /api/v1/sessions//ixnetwork/topology//deviceGroup//ethernet//ipv4//bgpIpv4Peer/ enable: : Default = True flapList: 'all' or a list of IP addresses to enable/disable flapping. [['10.10.10.1', '10.10.10.8', ...] Default = 'all' uptime: : In seconds. Defaults = 0 downtime: : In seconds. Defaults = 0 Syntax POST = /api/v1/sessions//ixnetwork/topology//deviceGroup//ethernet//ipv4//bgpIpv4Peer/ """ if flapList != 'all' and type(flapList) != list: ipRouteListToFlap = flapList.split(' ') response = self.ixnObj.get(self.ixnObj.httpHeader+bgpObjHandle) # Get the IP object from the bgpObjHandle match = re.match('(/api.*)/bgp', bgpObjHandle) ipObj = match.group(1) ipAddressList = self.getIpAddresses(ipObj) count = len(ipAddressList) # Recreate an index list based on user defined ip address to enable/disable indexToFlapList = [] if flapList != 'all': for ipAddress in flapList: # A custom list of indexes to enable/disable flapping based on the IP address index number. indexToFlapList.append(ipAddressList.index(ipAddress)) # Copy the same index list for uptime and downtime indexUptimeList = indexToFlapList indexDowntimeList = indexToFlapList response = self.ixnObj.get(self.ixnObj.httpHeader+bgpObjHandle) enableFlappingMultivalue = response.json()['flap'] upTimeMultivalue = response.json()['uptimeInSec'] downTimeMultivalue = response.json()['downtimeInSec'] flappingResponse = self.ixnObj.getMultivalueValues(enableFlappingMultivalue) uptimeResponse = self.ixnObj.getMultivalueValues(upTimeMultivalue) downtimeResponse = self.ixnObj.getMultivalueValues(downTimeMultivalue) # Flapping IP addresses flapOverlayList = [] uptimeOverlayList = [] downtimeOverlayList = [] # Build a valueList of either "true" or "false" if flapList == 'all': for counter in range(0,count): if enable == True: flapOverlayList.append("true") if enable == False: flapOverlayList.append("false") uptimeOverlayList.append(str(uptime)) downtimeOverlayList.append(str(downtime)) if flapList != 'all': # ['true', 'true', 'true'] currentFlappingValueList = flappingResponse # ['10', '10', '10'] currentUptimeValueList = uptimeResponse # ['20', '20', '20'] currentDowntimeValueList = downtimeResponse indexCounter = 0 for (eachFlapValue, eachUptimeValue, eachDowntimeValue) in zip(currentFlappingValueList, currentUptimeValueList, currentDowntimeValueList): # Leave the setting alone on this index position. User did not care to change this value. if indexCounter not in indexToFlapList: flapOverlayList.append(eachFlapValue) uptimeOverlayList.append(eachUptimeValue) downtimeOverlayList.append(eachDowntimeValue) else: # Change the value on this index position. if enable == True: flapOverlayList.append("true") else: flapOverlayList.append("false") uptimeOverlayList.append(str(uptime)) downtimeOverlayList.append(str(downtime)) indexCounter += 1 self.ixnObj.patch(self.ixnObj.httpHeader + enableFlappingMultivalue+'/valueList', data={'values': flapOverlayList}) self.ixnObj.patch(self.ixnObj.httpHeader + upTimeMultivalue+'/valueList', data={'values': uptimeOverlayList}) self.ixnObj.patch(self.ixnObj.httpHeader + downTimeMultivalue+'/valueList', data={'values': downtimeOverlayList})