cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1392
Views
0
Helpful
3
Replies
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)

Everyone's tags (5)
3 REPLIES 3
Highlighted
Cisco Employee

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

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

Highlighted

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

Hi,

the same problem, apic 1.2(1k)

Highlighted
Beginner

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

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