cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1694
Views
5
Helpful
3
Replies

List of Bridge domains per leaf switch -- acitoolkit

FadiH
Level 1
Level 1

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

3 Replies 3

well done !! I appreciate

Sergiu.Daniluk
VIP Alumni
VIP Alumni
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

You get the entire list of BDs and Tenants, because you are cycling within the for loop in python !

Max

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: