cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
384
Views
0
Helpful
3
Replies
Highlighted
Cisco Employee

EPG --> BD and BD --> VRF association through moquery

Hi Experts,

 

As we know every object in ACI worked in MIT hierarchy, for example one or more EPG can bind to BD likewise one or more BD can bind to VRF.

 

I am trying to get the output of these association through moquery and my question here is that, i want the output of moquery command in a way that it would show me all the subnets of Bridge Domains that are associated to VRF.

 

Subnet-1 ==> BD-1 ===> VRF-1

Subnet-2 ==> BD-2 ===> VRF-1

 

Regards,

Waqar

 

 

 

 

 

3 REPLIES 3
Highlighted
Participant

Re: EPG --> BD and BD --> VRF association through moquery

Hi

You'll find all the information in the fvBD (Bridge Domain)-MO and in the child-objects of fvBD:

BD: fvBD.dn

Subnet: Child-MO fvSubnet.ip

VRF: Child-MO fvRsCtx.tDn

 

You can't display your requested output with moquery. You'll need to write a script in order to get that kind of report (or use something like Postman Visualizer).

 

Here is a script which you can copy to one of your APICs and run it locally on the APIC (python <name of file containing script>) it will display the output in CSV-format:

import subprocess
import json
import re

def getJsonFromIcurl(cmd, httpStatus=False):
    try:
        if httpStatus:
            cmd = cmd.replace('icurl', 'icurl -i')
        data = subprocess.check_output(cmd, shell=True)
        if httpStatus:
            code = re.search('HTTP.* (\d+)', data).group(1)
            jsonResult = re.search('{.*}', data).group(0)
            return [code, json.loads(jsonResult)['imdata']]
        else:
            return json.loads(data)['imdata']
    except Exception as e:
        return False


def getJson(query):
    result = False
    cmd = 'icurl -s -g -X GET \'http://localhost:7777/api/{}\''.format(query)
    result = getJsonFromIcurl(cmd)
    return result


if __name__ == '__main__':
    print('SUBNET-ADDR,BD-DN,VRF-DN')
    data = getJson('class/fvBD.json?rsp-subtree=full&order-by=fvBD.dn|asc')
    for x in data:
        bd = x['fvBD']['attributes']['dn']
        subnet = ''
        vrf = ''
        for child in x['fvBD']['children']:
            if 'fvSubnet' in child:
                subnet = child['fvSubnet']['attributes']['ip']
            if 'fvRsCtx' in child:
                vrf = child['fvRsCtx']['attributes']['tDn']
        print('{},{},{}'.format(subnet, bd, vrf))

HTH

Marcel

Highlighted
Cisco Employee

Re: EPG --> BD and BD --> VRF association through moquery

Hi Marcel,

 

Thanks for your valuable feedback, and yes you are right we couldn't get the desired output in one go through moquery approach, which i asked.

 

But "moquery" the fvBD + rsp-subtree=children gives us alot of info about the BD and their respective childrens.

 

I will try the script and will let you know.

Thanks

 

Regards,

Waqar

Cisco Employee

Re: EPG --> BD and BD --> VRF association through moquery

Hi Marcel,

 

The script works fine for me and it's displaying all the requested data which i want.

 

Actually i want to limit my query to specific VRF, can we do it by altering the script, however this script displaying all the configured VRF and their associated BD subnet information which is great though.

Thanks

 

 

Regards,

Waqar

CreatePlease to create content