cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4508
Views
0
Helpful
3
Replies

bridge domains per leaf switch -- ACI fabric -- acitoolkit

FadiH
Level 1
Level 1

Hi everyone, 

I am trying to get the list of configured VRfs and BDs per leaf switch in my aci fabric. I did not manage to produce a piece of code that fulfill this. below if the short python code i have. 

 

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

leaf-me2lp1at-pw01 1202 common copy default
leaf-me2lp1at-pw01 1202 k_sandbox-3_ten std_vrf server2_bd
leaf-me2lp1at-pw01 1202 k_sandbox-3_ten std_vrf server1_bd  

 

3 Replies 3

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @FadiH 

To me it looks like the script works. On both leafs 1201 and 1202 you have k_sandbox-3_ten tenant, along with the vrf std_vrf, and 2x BDs: server1_bd and server2_bd.

Do you have other tenants/vrfs/BDs on these two leafs?

 

Cheers,

Sergiu

Hi, 

exact! the script works but not the correct way. Actually, leaf 1201 has the following:

common copy default

 and leaf 1202 has 

k_sandbox-3_ten std_vrf server2_bd
k_sandbox-3_ten std_vrf server1_bd

but what i get is somehow the list of tenants, VRFs, BDs  that are configured in the whole fabric (not per leaf) printed out in a recurrent way (for loop). So I am not sure how to specify that I want to list tenants/VRFs/BDs per leaf  

 

Cheers

I see what's the problem.

 

Basically, you are doing this:

    for node in nodes:
        if ((node.role) == 'leaf'):
            tenants = ACI.Tenant.get(session, node)
            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))

You are getting tenants for each node, but then you get ALL the VRFs and BDs from the tenant, which are not node specific. Which means that yes, you will get all VRFs and BDs for a tenant regardless if that one is configured or not on the leaf.

 

You should take a look at what EPGs are configured on each Leaf, and based on EPG to get information about the BD.

 

Stay safe,

Sergiu