def getIpv4ObjByPortName(self, portName=None): """ Description Get the IPv4 object by the port name. Parameter portName: : Optional: The name of the port. Default=None. """ # Step 1 of 3: Get the Vport by the portName. queryData = {'from': '/', 'nodes': [{'node': 'vport', 'properties': ['name'], 'where': [{'property': 'name', 'regex': portName}]}]} queryResponse = self.ixnObj.query(data=queryData, silentMode=False) if queryResponse.json()['result'][0]['vport'] == []: raise IxNetRestApiException('\nNo such vport name: %s\n' % portName) # /api/v1/sessions/1/ixnetwork/vport/2 vport = queryResponse.json()['result'][0]['vport'][0]['href'] self.ixnObj.logInfo(vport) # Step 2 of 3: Query the API tree for the IPv4 object queryData = {'from': '/', 'nodes': [{'node': 'topology', 'properties': ['vports'], 'where': []}, {'node': 'deviceGroup', 'properties': [], 'where': []}, {'node': 'ethernet', 'properties': [], 'where': []}, {'node': 'ipv4', 'properties': [], 'where': []}, ]} queryResponse = self.ixnObj.query(data=queryData, silentMode=False) # Step 3 of 3: Loop through each Topology looking for the vport. # If found, get its IPv4 object for topology in queryResponse.json()['result'][0]['topology']: if vport in topology['vports']: # Get the IPv4 object: /api/v1/sessions/1/ixnetwork/topology/2/deviceGroup/1/ethernet/1/ipv4/1 ipv4Obj = topology['deviceGroup'][0]['ethernet'][0]['ipv4'][0]['href'] return ipv4Obj