def sendIgmpJoinLeaveNgpf(self, routerId=None, igmpHostUrl=None, multicastIpAddress=None, action='join'): """ Description Send IGMP joins or leaves. A IGMP host object is acceptable. If you don't know the IGMP host object, use Device Group RouterID. Since a Device Group could have many routerID, you could state one of them. If multicastIpAddress is 'all', this will send IGMP join on all multicast addresses. Else, provide a list of multicast IP addresses to send join. Parameters routerId: The Device Group Router ID address. igmpHostUrl: '/api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/ethernet/1/ipv4/1/igmpHost/1' multicastIpAddress: 'all' or a list of multicast IP addresses to send join. Example: ['225.0.0.3', '225.0.0.4'] action: join|leave """ if action == 'join': action = 'igmpjoingroup' if action == 'leave': action = 'igmpleavegroup' # In case somebody passes in http://{ip:port}. All this function needs is the Rest API. if igmpHostUrl: match = re.match('http://.*(/api.*)', igmpHostUrl) if match: igmpHostUrl = match.group(1) if routerId: deviceGroupObj = self.getDeviceGroupByRouterId(routerId=routerId) if deviceGroupObj == 0: raise IxNetRestApiException('No Device Group found for router ID: %s' % routerId) queryData = {'from': deviceGroupObj, 'nodes': [{'node': 'routerData', 'properties': [], 'where': []}, {'node': 'ethernet', 'properties': [], 'where': []}, {'node': 'ipv4', 'properties': [], 'where': []}, {'node': 'igmpHost', 'properties': [], 'where': []}, ]} queryResponse = self.ixnObj.query(data=queryData) routerIdObj = queryResponse.json()['result'][0]['routerData'][0]['href'] response = self.ixnObj.get(self.ixnObj.httpHeader+routerIdObj) routerIdMultivalue = response.json()['routerId'] routerIdList = self.ixnObj.getMultivalueValues(routerIdMultivalue, silentMode=True) if routerId in routerIdList: igmpHostUrl = queryResponse.json()['result'][0]['ethernet'][0]['ipv4'][0]['igmpHost'][0]['href'] # Based on the list of multicastIpAddress, get all their indexes. response = self.ixnObj.get(self.ixnObj.httpHeader+igmpHostUrl+'/igmpMcastIPv4GroupList') startMcastAddrMultivalue = response.json()['startMcastAddr'] listOfConfiguredMcastIpAddresses = self.ixnObj.getMultivalueValues(startMcastAddrMultivalue) self.ixnObj.logInfo('sendIgmpJoinNgpf: List of configured Mcast IP addresses: %s' % listOfConfiguredMcastIpAddresses) if listOfConfiguredMcastIpAddresses == []: raise IxNetRestApiException('sendIgmpJoinNgpf: No Mcast IP address configured') if multicastIpAddress == 'all': listOfMcastAddresses = listOfConfiguredMcastIpAddresses else: listOfMcastAddresses = multicastIpAddress # Note: Index position is not zero based. indexListToSend = [] for eachMcastAddress in listOfMcastAddresses: index = listOfConfiguredMcastIpAddresses.index(eachMcastAddress) indexListToSend.append(index+1) url = igmpHostUrl+'/igmpMcastIPv4GroupList/operations/%s' % action data = {'arg1': [igmpHostUrl+'/igmpMcastIPv4GroupList'], 'arg2': indexListToSend} self.ixnObj.logInfo('sendIgmpJoinNgpf: %s' % url) self.ixnObj.logInfo('\t%s' % multicastIpAddress) response = self.ixnObj.post(self.ixnObj.httpHeader+url, data=data) self.ixnObj.waitForComplete(response, url+response.json()['id'])