cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2886
Views
4
Helpful
6
Replies

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

Waqar675
Cisco Employee
Cisco Employee

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

 

 

 

 

 

6 Replies 6

Marcel Zehnder
Spotlight
Spotlight

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

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

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

Hi Marcel,

 

that is great script, would it be possible to alter it so it also displays EPG related to each BD?

So something line subnet/BD/VRF/EPG

 

thank you!

Peter

ok, replying to myself:) I have updated your scrip so it lists EPG as well.

now, another challene would be to list also vlan-encap for each epg along this subnet/bd/vrf

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,EPG')
    data = getJson('class/fvBD.json?rsp-subtree=full&order-by=fvBD.dn|asc')
    for x in data:
        bd = x['fvBD']['attributes']['dn']
        subnet = ''
        vrf = ''
	epg = ''
        for child in x['fvBD']['children']:
            if 'fvSubnet' in child:
                subnet = child['fvSubnet']['attributes']['ip']
            if 'fvRsCtx' in child:
                vrf = child['fvRsCtx']['attributes']['tDn']
            if 'fvRtBd' in child:
                epg = child['fvRtBd']['attributes']['tDn']
        print('{},{},{},[]'.format(subnet, bd, vrf, epg))

 

 

Hi @pjvonbanhoff 

Pity this is a dead thread that has never been marked as answered. (Maybe your should post it as a NEW question and then answer it, and mark it correct)

But since your answer involves a python script, and because python gets fussy about indentations, I'm suggesting you edit your script to make it "cut-and-pastable".

RedNectar's Forum Tips:

    • When pasting code/CLI output, expand the top menu by clicking the ellipsis RedNectar_0-1707169195575.png

      This will give you access to the paragraph formatting drop down

    • Choose Preformatted RedNectar_0-1707177746787.png
    • After clicking Preformatted, click HTML and paste your content between the <pre> </pre> tags.  This will stop multiple spaces being squeezed into a single space.RedNectar_1-1707177831922.png

 

    • When you add pictures, add your pictures inline - i.e. PASTE your picture right where you want it.  If it is a screenshot, you'll probably then want to click on the image and make the image large - like this.

RedNectar_1-1685651021448.png

This means you pictures are actually SEEN (a) in the email that gets sent to subscribers and (b) anyone who looks at this post in the future. Adding pictures as attachments... puts your submission into the TL;DR category.

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Save 25% on Day-2 Operations Add-On License