06-29-2021 08:26 AM
Hi everyone,
I am looking for some help as I am stuck writing a smal script that helps me get the list of configured BDs per leaf switch in the aci fabric. I managed to do few things with acitoolkit but it is not what I want to have as output. I am not sure how can I resolve it. Any help is appreciated. here is the piece of code i have so far:
import sys import acitoolkit.acitoolkit as ACI from acitoolkit.aciphysobject import Node from acitoolkit import (Tenant, Session, Filter, EPG, Contract, Context, ContractSubject, AppProfile, BridgeDomain, AttributeCriterion, OutsideL3, OutsideEPG, OutsideNetwork, Session) if __name__ == "__main__": creds = ACI.Credentials('apic', description) args = creds.get() Login to APIC session = ACI.Session(args.url, args.login, args.password) resp = session.login() if not resp.ok: print('%% Could not login to APIC') sys.exit(0) template = '{0:20} {1:20} {2:20} {3:20} {4:20}' a_file = open("sample.txt", "w") print (template.format("Leaf Switch name", "Switch ID", "TENANT", "Context", "BRIDGE DOMAIN")) print (template.format("----------------","--------", "--------", "-------", "--------------")) nodes = Node.get(session) for node in nodes: if ((node.role) == 'leaf'): tenants = ACI.Tenant.get(session, node) ##tenants = Tenant.get_deep(session) for tenant in tenants: Cxts = ACI.Context.get(session, tenant) bds = ACI.BridgeDomain.get(session, tenant) for Cxt in Cxts: for bd in bds: print (template.format(node.name, node.node, tenant.name, Cxt.name, bd.name), file=a_file) a_file.close()
-------------
this is a snippet of the output. It basically loops over the leaf switches but returning the same results over and over which means i am not getting the BDs and VRfs specific for each switch.
leaf-me2lp1at-pw01 1201 common copy default
leaf-me2lp1at-pw01 1201 k_sandbox-3_ten std_vrf server2_bd
leaf-me2lp1at-pw01 1201 k_sandbox-3_ten std_vrf server1_bd
many thanks
12-03-2022 03:55 AM
well done !! I appreciate
12-03-2022 05:52 AM
Cxts = ACI.Context.get(session, tenant) bds = ACI.BridgeDomain.get(session, tenant)
If I am not mistaking, these two lines will return all VRFs and all BDs associated to your tenants, regardless of the tenant.
That's why you always get the list of all VRFs and all BDs.
Take care,
Sergiu
12-05-2022 12:08 AM
You get the entire list of BDs and Tenants, because you are cycling within the for loop in python !
Max
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