def getProtocolObjFromProtocolList(self, protocolList, protocol, deviceGroupName=None): """ Description This is an internal API used after calling self.getProtocolListByPortNgpf(). self.getProtocolListByPortNgpf() returns a dict containing a key called deviceGroup that contains all the device group protocols in a list. Use this API to get the protocol object handle by passing in the deviceGroup list and specify the NGPF protocol endpoint name. Parameters protocolList: : protocol: : The NGPF endpoint protocol name. View below: deviceGroupName: : If there are multiple Device Groups within the Topology, filter the Device Group by its name. NGPF endpoint protocol names: 'ancp', 'bfdv4Interface', 'bgpIpv4Peer', 'bgpIpv6Peer', 'dhcpv4relayAgent', 'dhcpv6relayAgent', 'dhcpv4server', 'dhcpv6server', 'geneve', 'greoipv4', 'greoipv6', 'igmpHost', 'igmpQuerier', 'lac', 'ldpBasicRouter', 'ldpBasicRouterV6', 'ldpConnectedInterface', 'ldpv6ConnectedInterface', 'ldpTargetedRouter', 'ldpTargetedRouterV6', 'lns', 'mldHost', 'mldQuerier', 'ptp', 'ipv6sr', 'openFlowController', 'openFlowSwitch', 'ospfv2', 'ospfv3', 'ovsdbcontroller', 'ovsdbserver', 'pcc', 'pce', 'pcepBackupPCEs', 'pimV4Interface', 'pimV6Interface', 'ptp', 'rsvpteIf', 'rsvpteLsps', 'tag', 'vxlan' Example usage: protocolObj = Protocol(mainObj) protocolList = protocolObj.getProtocolListByPortNgpf(port=['192.168.70.120', '1', '2']) obj = protocolObj.getProtocolObjFromProtocolList(protocolList['deviceGroup'], 'bgpIpv4Peer') If you expect multiple Device Groups in your Topology, you could filter by the Device Group name: obj = protocolObj.getProtocolObjFromProtocolList(protocolList['deviceGroup'], 'ethernet', deviceGroupName='DG2') Returns The protocol object handle in a list. For example: ['/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/2/ethernet/1/ipv4/1/bgpIpv4Peer'] """ self.ixnObj.logInfo('\n{0}...'.format('\ngetProtocolObjFromProtocolList'), timestamp=False) protocolObjectHandleList = [] for protocols in protocolList: if protocol in ['deviceGroup', 'ethernet', 'ipv4', 'ipv6']: for endpointObj in protocols: if protocol == 'deviceGroup': # Include the deviceGroup object handle also match = re.search( r'(/api/v1/sessions/[0-9]+/ixnetwork/topology/[0-9]+/deviceGroup/[0-9]+)$', endpointObj) if match: # A topology could have multiple Device Groups. Filter by the Device Group name. if deviceGroupName: deviceGroupObj = match.group(1) response = self.ixnObj.get(self.ixnObj.httpHeader + deviceGroupObj, silentMode=True) if deviceGroupName == response.json()['name']: self.ixnObj.logInfo(str([endpointObj]), timestamp=False) return [endpointObj] else: protocolObjectHandleList.append(endpointObj) # Search for the protocol after the deviceGroup endpoint. match = re.search(r'(/api/v1/sessions/[0-9]+/ixnetwork/topology/[0-9]+/deviceGroup/[0-9]+).*/%s/[0-9]+$' % protocol, endpointObj) if match: # A topology could have multiple Device Groups. Filter by the Device Group name. if deviceGroupName: deviceGroupObj = match.group(1) response = self.ixnObj.get(self.ixnObj.httpHeader + deviceGroupObj, silentMode=True) if deviceGroupName == response.json()['name']: self.ixnObj.logInfo(str([endpointObj]), timestamp=False) return [endpointObj] else: protocolObjectHandleList.append(endpointObj) else: if any(protocol in x for x in protocols): index = [index for index, item in enumerate(protocols) if protocol in item] protocolObjectHandle = protocols[index[0]] self.ixnObj.logInfo('Appending protocol: %s' % str([protocolObjectHandle]), timestamp=False) protocolObjectHandleList.append(protocolObjectHandle) return protocolObjectHandleList