10-09-2015 10:59 AM
I wrote the following code to get all BDs in a specified tenant.
However, I got the error message like: AttributeError: 'list' object has no attribute 'BD'
Could someone tell me what is the problem?
Reference:
Examples — Cisco APIC Python API 0.1 documentation
APIC version: 1.1(3f)
---
from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession
from cobra.mit.request import DnQuery
from cobra.model.fv import Tenant, Ctx, BD
session = LoginSession('http://1.1.1.1', 'admin', 'cisco')
moDir = MoDirectory(session)
moDir.login()
dnQuery = DnQuery('uni/tn-TENANT')
dnQuery.subtree = 'children'
tenantMo = moDir.query(dnQuery)
for bdMo in tenantMo.BD:
print str(bdMo.dn)
01-14-2016 01:05 AM
Hi Daisuke,
Request to post your question under APIC community. Also for related information please refer -
Thanks and Regards,
Geevarghese
01-25-2016 02:53 PM
Hi,
the same problem, apic 1.2(1k)
02-28-2017 07:35 AM
To add to gcheria's answer, the way you can do this is to add a subclass filter to the query that you're doing. This is outlined in the link that they referenced, under the the 4. User query() method section.
You could use the ClassQuery instead of the DN query, which would look like this -
classDn = 'uni/tn-TENANT' + '/fvBD'
classQuery = ClassQuery(classDn)
tenantBdMoList = moDir.query(classQuery)
for tenantBd in tenantBdMoList:
print tenantBd.dn
07-05-2021 09:22 AM
Hello everyone,
I want to know if it is possible to get a specific portion of a child object. I use the following piece of code for the purpose but I end up have a printing of the Tenant-name, VRF-name, BD-name and VLAN-name. All I wanted to get was simply the BD name here. Can someone point out what's wrongly written in the code? many thanks,
def l3l2(pod, leaf, moDir): nodeid=leaf podid=pod vrfclass = ClassQuery('l3Ctx') vrfclass.subtree ="children" vrfclass.subtreeClassFilter="l2BD" vrflist = moDir vrflist=vrflist.query(vrfclass) print(f"Pod ID: {podid}, Node ID: {nodeid}") for vrf in vrflist: if vrf._BaseMo__parentDnStr == f"topology/pod-{podid}/node-{nodeid}/sys": for bd in vrf.children: #print(f" BD : {bd.name}") print(" Tenant/BD: {:10s}".format(bd.name))
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