cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
4391
Views
5
Helpful
4
Replies
dyoshiha
Cisco Employee

How do I get a specific child of a Mo using subtree query in cobra SDK?

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)

4 REPLIES 4
Geevarghese Cheria
Cisco Employee

Hi Daisuke,

   Request to post your question under APIC community. Also for related information please refer -

Example of getting interface status with Cobra SDK | Application Centric Infrastructure | Cisco Support Community | 1220…

Thanks and Regards,

Geevarghese

Hi,

the same problem, apic 1.2(1k)

Beau Poehls
Beginner

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

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))
Create
Recognize Your Peers
Content for Community-Ad