def getProtocolListByPortNgpf(self, port=None, portName=None): """ Description Based on either the vport name or the physical port, get the Topology Group object and all the protocols in each Device Group within the same Topology Group. Parameter port: [chassisIp, cardNumber, portNumber] Example: ['10.10.10.1', '2', '8'] portName: : The virtual port name. Example usage: protocolObj = Protocol(mainObj) protocolList = protocolObj.getProtocolListByPortNgpf(port=['192.168.70.120', '1', '2']) Subsequently, you could call getProtocolObjFromProtocolList to get any protocol object handle: obj = protocolObj.getProtocolObjFromProtocolList(protocolList['deviceGroup'], 'bgpIpv4Peer') Returns {'topology': '/api/v1/sessions/1/ixnetwork/topology/2', 'deviceGroup': [['/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/2', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/2/ethernet/1', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/2/ethernet/1/ipv4/1', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/2/ethernet/1/ipv4/1/bgpIpv4Peer'], ['/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/3', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/3/ethernet/1', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/3/ethernet/1/ipv4/1', '/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/3/ethernet/1/ipv4/1/ospfv2'] ]} """ self.ixnObj.logInfo('{0}...'.format('\ngetProtocolListByPortNgpf'), timestamp=False) if port: chassisIp = str(port[0]) cardNum = str(port[1]) portNum = str(port[2]) specifiedPort = chassisIp+':'+cardNum+':'+portNum loopFlag = 0 # Loop each Topology and search for matching port or portName response = self.ixnObj.get(self.ixnObj.sessionUrl+'/topology', silentMode=True) topologyList = ['%s/%s/%s' % (self.ixnObj.sessionUrl, 'topology', str(i["id"])) for i in response.json()] for topology in topologyList: response = self.ixnObj.get(topology, silentMode=True) topologyObj = response.json()['links'][0]['href'] vportList = response.json()['vports'] for eachVport in vportList: response = self.ixnObj.get(self.ixnObj.httpHeader+eachVport, silentMode=True) vportName = response.json()['name'] if portName != None: if portName != vportName: continue else: loopFlag = 1 break if port != None: # actualPort: ['192.168.70.3:1:2'] actualPort = self.portMgmtObj.getPhysicalPortFromVport([eachVport])[0] if actualPort != specifiedPort: continue else: loopFlag = 1 break if loopFlag == 0: # The port or portName is not found. continue enabledProtocolList = {'topology': topologyObj} response = self.ixnObj.get(topology+'/deviceGroup', silentMode=True) deviceGroupList = ['%s/%s/%s' % (topology, 'deviceGroup', str(i["id"])) for i in response.json()] deviceGroupObjects = [] enabledProtocolList = {'topology': topologyObj, 'deviceGroup': []} for deviceGroup in deviceGroupList: deviceGroupObj = '/api' + deviceGroup.split('/api')[1] deviceGroupObjects.append(deviceGroupObj) response = self.ixnObj.get(deviceGroup+'/ethernet', silentMode=True) ethernetList = ['%s/%s/%s' % (deviceGroup, 'ethernet', str(i["id"])) for i in response.json()] for ethernet in ethernetList: deviceGroupObjects.append('/api'+ethernet.split('/api')[1]) response = self.ixnObj.get(ethernet+'/ipv4', silentMode=True) ipv4List = ['%s/%s/%s' % (ethernet, 'ipv4', str(i["id"])) for i in response.json()] if ipv4List: deviceGroupObjects.append('/api'+ipv4List[0].split('/api')[1]) response = self.ixnObj.get(ethernet+'/ipv6', silentMode=True) ipv6List = ['%s/%s/%s' % (ethernet, 'ipv6', str(i["id"])) for i in response.json()] if ipv6List: deviceGroupObjects.append('/api'+ipv6List[0].split('/api')[1]) for layer3Ip in ipv4List+ipv6List: url = layer3Ip+'?links=true' response = self.ixnObj.get(url, silentMode=True) for protocol in response.json()['links']: currentProtocol = protocol['href'] if (bool(re.match('^/api/.*(ipv4|ipv6)/[0-9]+$', currentProtocol))): continue if (bool(re.match('^/api/.*(ipv4|ipv6)/[0-9]+/port$', currentProtocol))): continue url = self.ixnObj.httpHeader+currentProtocol response = self.ixnObj.get(url, silentMode=True) if response.json() == []: # The currentProtocol is not configured. continue else: response = self.ixnObj.get(url, silentMode=True) currentProtocol =response.json()[0]['links'][0]['href'] deviceGroupObjects.append(currentProtocol) enabledProtocolList['deviceGroup'].insert(len(enabledProtocolList), deviceGroupObjects) deviceGroupObjects = [] # Getting here means either the port or portName is found and the object is obtained. # Break and return the object handle. break if loopFlag == 0: if port != None: raise IxNetRestApiException('\nError: No port found: {0}'.format(port)) if portName != None: raise IxNetRestApiException('\nError: No portName found: {0}'.format(portName)) self.ixnObj.logInfo('\ngetProtocolListByPortNgpf: {0}'.format(str(enabledProtocolList)), timestamp=False) return enabledProtocolList