def activateRouterIdRouteRanges(self, protocol=None, routeRangeAddressList=None, activate=True): """ Description Activate the protocols based on the RouterId. Parameter protocol: The protocol to disable/enable route ranges. Current choices: bgp, ospf, ldp, isis routeRangeAddress: A list of two lists grouped in a list: For example: [[[list_of_routerID], [list_of_route_ranges]]] activate: True|False Examples: 1> activateRouterIdRouteRanges(routeRangeAddressList=[[['all'], ['all']]], protocol='ospf', activate=True) 2> activateRouterIdRouteRanges(routeRangeAddressList=[[['all'], ['202.13.0.0', '202.23.0.0', '203.5.0.0']]], protocol='isis', activate=False) 3> activateRouterIdRouteRanges(routeRangeAddressList=[[['192.0.0.2', '192.0.0.3'], ['202.11.0.0', '202.21.0.0']], [['192.0.0.1'], ['all']]], protocol='ospf', activate=False) 4> activateRouterIdRouteRanges(routeRangeAddressList=[[['192.0.0.1', '192.0.0.3'], ['202.3.0.0', '202.23.0.0']]], protocol='ospf', activate=False) """ if protocol == 'bgp': protocol = 'bgpIPRouteProperty' if protocol == 'ospf': protocol = 'ospfRouteProperty' if protocol == 'isis': protocol = 'isisL3RouteProperty' if protocol == 'ldp': protocol = 'ldpFECProperty' # 1: Get all the Device Group objects with the user specified router IDs. queryData = {'from': '/', 'nodes': [{'node': 'topology', 'properties': [], 'where': []}, {'node': 'deviceGroup', 'properties': ['multiplier'], 'where': []}, {'node': 'routerData', 'properties': ['routerId', 'count'], 'where': []} ]} deviceGroupObjList = [] allRouterIdList = [] queryResponse = self.ixnObj.query(data=queryData, silentMode=False) for topology in queryResponse.json()['result'][0]['topology']: for deviceGroup in topology['deviceGroup']: deviceGroupObj = deviceGroup['href'] deviceGroupMultiplier = deviceGroup['multiplier'] routerIdMultivalue = deviceGroup['routerData'][0]['routerId'] routerIdList = self.ixnObj.getMultivalueValues(routerIdMultivalue, silentMode=True) deviceGroupObjList.append((deviceGroupObj, deviceGroupMultiplier, routerIdList, routerIdMultivalue)) for rId in routerIdList: if rId not in allRouterIdList: allRouterIdList.append(rId) # 2: For each Device Group, look for the protocol to enable|disable # Enable|disable based on the specified routerId list for deviceGroup in deviceGroupObjList: deviceGroupObj = deviceGroup[0] deviceGroupMultiplier = deviceGroup[1] deviceGroupRouterIdList = deviceGroup[2] routerIdMultivalue = deviceGroup[3] self.ixnObj.logInfo('Searching Device Group: %s' % deviceGroupObj) queryData = {'from': deviceGroupObj, 'nodes': [{'node': 'networkGroup', 'properties': [], 'where': []}, {'node': 'ipv4PrefixPools', 'properties': ['networkAddress', 'count'], 'where': []}, {'node': protocol, 'properties': ['active'], 'where': []} ]} queryResponse = self.ixnObj.query(data=queryData, silentMode=False) # Note: A device group could have multiple network groups. # Loop through all configured network groups for the ipv4PrefixPools with the user specified protocol. for networkGroup in queryResponse.json()['result'][0]['networkGroup']: networkGroupObj = networkGroup['href'] for ipv4Prefix in networkGroup['ipv4PrefixPools']: if ipv4Prefix[protocol] != []: ipv4PrefixPoolMultivalue = ipv4Prefix['networkAddress'] ipv4PrefixPool = self.ixnObj.getMultivalueValues(ipv4PrefixPoolMultivalue, silentMode=True) protocolMultivalue = ipv4Prefix[protocol][0]['active'] protocolActiveList = self.ixnObj.getMultivalueValues(protocolMultivalue, silentMode=True) totalCountForEachRouterId = ipv4Prefix['count'] // deviceGroupMultiplier totalRouteRangeCount = ipv4Prefix['count'] # Create a dictionary containing routerID starting/ending indexes. routerIdIndexes = {} startingIndex = 0 endingIndex = totalCountForEachRouterId for routerId in deviceGroupRouterIdList: routerIdIndexes[routerId, 'startingIndex'] = {} routerIdIndexes[routerId, 'endingIndex'] = {} routerIdIndexes[routerId, 'startingIndex'] = startingIndex routerIdIndexes[routerId, 'endingIndex'] = endingIndex startingIndex += totalCountForEachRouterId endingIndex += totalCountForEachRouterId for key,value in routerIdIndexes.items(): print('', key, value) self.ixnObj.logInfo('Current active list: %s' % protocolActiveList) startingIndex = 0 endingIndex = totalCountForEachRouterId for eachRouterId in deviceGroupRouterIdList: print(eachRouterId) for item in routeRangeAddressList: currentUserDefinedRouterIdList = item[0] currentUserDefinedRouteRangeList = item[1] if 'all' not in currentUserDefinedRouterIdList: if eachRouterId not in currentUserDefinedRouterIdList: continue if 'all' in currentUserDefinedRouteRangeList: for index in range(routerIdIndexes[eachRouterId,'startingIndex'], routerIdIndexes[eachRouterId,'endingIndex']): protocolActiveList[index] = activate if 'all' not in currentUserDefinedRouteRangeList: for index in range(startingIndex, totalRouteRangeCount): currentIpv4PrefixPoolsIndex = ipv4PrefixPool[index] if ipv4PrefixPool[index] in currentUserDefinedRouteRangeList: protocolActiveList[index] = activate self.ixnObj.logInfo('Modifying: %s' % networkGroupObj) self.ixnObj.configMultivalue(protocolMultivalue, multivalueType='valueList', data={'values': protocolActiveList})