def getEndpointObjByDeviceGroupName(self, deviceGroupName, endpointObj): """ Description Based on the Device Group name, return the specified endpointObj object handle. The endpointObj is the NGPF endpoint: topology, deviceGroup, networkGroup, ethernet, ipv4|ipv6, bgpIpv4Peer, ospfv2, igmpHost, etc. The exact endpoint name could be found in the IxNetwork API Browser. Parameter deviceGroupName: : The Device Group name. endpointObj: : The NGPF endpoint object handle to get. Example usage: # This example shows how to get the bgp object handle from the Device Group named DG-2. protocolObj = Protocol(mainObj) obj = protocolObj.getEndpointObjByDeviceGroupName('DG-2', 'bgpIpv4Peer') returns: ['/api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/1/ethernet/1/ipv4/1/bgpIpv4Peer'] obj = protocolObj.getEndpointObjByDeviceGroupName('DG-2', 'topology') returns: ['/api/v1/sessions/1/ixnetwork/topology/2'] Returns []|The NGPF endpoint object handle(s) in a list. """ returnList = [] self.ixnObj.logInfo('{0}...'.format('\ngetEndpointObjByDeviceGroupName'), timestamp=False) # Loop each Topology and search for matching port or portName response = self.ixnObj.get(self.ixnObj.sessionUrl+'/topology', silentMode=False) 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=False) topologyObj = response.json()['links'][0]['href'] response = self.ixnObj.get(topology+'/deviceGroup', silentMode=False) deviceGroupList = [] for response in response.json(): deviceGroupObj = response['links'][0]['href'] deviceGroupList.append(deviceGroupObj) # Get inner device group objects also. Verify if there are additional device groups within a device group. response = self.ixnObj.get(self.ixnObj.httpHeader + deviceGroupObj + '/deviceGroup') if response.json(): for response in response.json(): deviceGroupList.append(response['links'][0]['href']) for deviceGroupObj in deviceGroupList: response = self.ixnObj.get(self.ixnObj.httpHeader+deviceGroupObj) if response.json()['name'] == deviceGroupName: if endpointObj == 'topology': return [topologyObj] if endpointObj == 'deviceGroup': return [deviceGroupObj] response = self.ixnObj.get(self.ixnObj.httpHeader+deviceGroupObj+'/ethernet', silentMode=False) ethernetList = ['%s/%s/%s' % (deviceGroupObj, 'ethernet', str(i["id"])) for i in response.json()] if ethernetList == []: continue if endpointObj == 'ethernet': headlessEthernetList = [] for eachEthernetObj in ethernetList: match = re.match('http.*(/api.*)', eachEthernetObj) if match: headlessEthernetList.append(match.group(1)) return headlessEthernetList if endpointObj == 'networkGroup': response = self.ixnObj.get(deviceGroup+'/networkGroup', silentMode=False) networkGroupList = ['%s/%s/%s' % (deviceGroup, 'networkGroup', str(i["id"])) for i in response.json()] headlessNetworkGroupList = [] for eachNetworkGroupObj in networkGroupList: match = re.match('http.*(/api.*)', eachNetworkGroupObj) if match: headlessNetworkGroupList.append(match.group(1)) return headlessNetworkGroupList for ethernet in ethernetList: # Dynamically get all Ethernet child endpoints response = self.ixnObj.get(self.ixnObj.httpHeader+ethernet+'?links=true', silentMode=False) for ethernetChild in response.json()['links']: print('Ethernet child:', ethernetChild['href']) currentChildName = ethernetChild['href'].split('/')[-1] if currentChildName == endpointObj: response = self.ixnObj.get(self.ixnObj.httpHeader+ethernetChild['href']) if response.json() == []: raise IxNetRestApiException('getEndpointObjByDeviceGroupName: The endpointObj you specified "{0}" is not configured. No endpointObj found'.format(endpointObj)) returnList.append(response.json()[0]['links'][0]['href']) # Search IPv4/IPv6 if currentChildName in ['ipv4'] or currentChildName in ['ipv6']: l3Obj = currentChildName response = self.ixnObj.get(self.ixnObj.httpHeader+ethernet+'/'+l3Obj+'?links=true', silentMode=True) if response.json() == []: # L3 is not configured continue for child in response.json(): for l3Child in child['links']: print('L3Child:', l3Child['href']) currentL3ChildName = l3Child['href'].split('/')[-1] if currentL3ChildName == endpointObj: response = self.ixnObj.get(self.ixnObj.httpHeader+l3Child['href'], silentMode=True) if response.json() == []: raise IxNetRestApiException('getEndpointObjByDeviceGroupName: The endpointObj you specified "{0}" is not configured. No endpointObj found.'.format(endpointObj)) returnList.append(l3Child['href']) return returnList