01-09-2020 01:50 PM
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
01-14-2020 06:10 AM - edited 01-14-2020 06:18 AM
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
01-14-2020 08:42 AM
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
01-17-2020 02:48 PM
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
03-14-2024 07:21 AM
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
03-14-2024 10:39 AM - edited 03-14-2024 01:13 PM
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))
03-14-2024 01:09 PM
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:
This will give you access to the paragraph formatting drop down
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide