02-20-2023 09:51 AM
Hi,
I am trying to construct a API query on class vzBrCP (contract). I want to find a contract where a certain EPG is a consumer and another EPG is a provider.
This is an example of a contract (I have changed the names and removed some unnecessary information):
{
"imdata": [
{
"vzBrCP": {
"attributes": {
"accessPrivilege": "USER",
"annotation": "",
"childAction": "",
"configIssues": "",
"descr": "",
"dn": "uni/tn-tenant1/brc-ctr_epg_1",
"extMngdBy": "",
"intent": "install",
"lcOwn": "local",
"modTs": "2020-07-23T04:24:09.948+01:00",
"monPolDn": "uni/tn-common/monepg-default",
"name": "ctr_epg_1",
"nameAlias": "",
"ownerKey": "",
"ownerTag": "",
"prio": "unspecified",
"reevaluateAll": "no",
"scope": "context",
"status": "",
"targetDscp": "unspecified",
"uid": "23465",
"userdom": "all"
},
"children": [
{
"vzRtProv": {
"attributes": {
"childAction": "",
"lcOwn": "local",
"modTs": "2020-06-17T23:00:24.609+01:00",
"rn": "rtfvProv-[uni/tn-tenant1/ap-ap_1/epg-epg_epg_1]",
"status": "",
"tCl": "fvAEPg",
"tDn": "uni/tn-tenant1/ap-ap_1/epg-epg_epg_1"
}
}
},
{
"vzRtCons": {
"attributes": {
"childAction": "",
"lcOwn": "local",
"modTs": "2020-06-17T23:04:02.550+01:00",
"rn": "rtfvCons-[uni/tn-tenant1/ap-ap_1/epg-epg_2]",
"status": "",
"tCl": "fvAEPg",
"tDn": "uni/tn-tenant1/ap-ap_1/epg-epg_2"
}
}
},
{
"vzRtCons": {
"attributes": {
"childAction": "",
"lcOwn": "local",
"modTs": "2020-06-17T23:01:13.328+01:00",
"rn": "rtfvCons-[uni/tn-tenant1/ap-ap_1/epg-epg_3]",
"status": "",
"tCl": "fvAEPg",
"tDn": "uni/tn-tenant1/ap-ap_1/epg-epg_3"
}
}
}
]
}
}
],
"totalCount": "1"
}
I have tried to construct a query like this:
api/class/vzBrCP.json?query-target=children
&query-target-filter=and(eq(vzRtCons.tDn,"uni/tn-tenant1/ap-ap_1/epg-epg_3"),eq(vzRtProv.tDn,"uni/tn-tenant1/ap-ap_1/epg-epg_epg_1"))
I thought this would do the trick but all I get as a response is:
{
"imdata": [],
"totalCount": "0"
}
What I hope and look for as a response to the query is like the example in the beginning of this post.
Thanks in advance for any help.
//Andreas
02-22-2023 10:57 AM
bash
CONTRACT='brc-<name of contract>'
#CHECK CONSUMERS #To get the count of epg's consuming a contract (excluding vzany consumer):
icurl -g 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=subtree&target-subtree-class=vzRtCons,vzConsDef&rsp-subtree-include=count&query-target-filter=or(eq(vzRtCons.tCl,"fvAEPg"),eq(vzRtCons.tCl,"l2extInstP"),eq(vzRtCons.tCl,"l3extInstP"),wcard(vzConsDef.dn,"uni/tn-'.*'/inherited-\[uni/tn-"))'
#To list all epg objects consuming a contract (excluding vzany consumers):
icurl -g 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=subtree&target-subtree-class=vzRtCons,vzConsDef&query-target-filter=or(eq(vzRtCons.tCl,"fvAEPg"),eq(vzRtCons.tCl,"l2extInstP"),eq(vzRtCons.tCl,"l3extInstP"),wcard(vzConsDef.dn,"uni/tn-'.*'/inherited-\[uni/tn-"))' | python -m json.tool
#To get the count of vzany's consuming a contract:
#To list all vzany objects consuming a contract:
icurl 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=children&target-subtree-class=vzRtAnyToCons' | python -m json.tool
#CHECK PROVIDERS
#To get the count of epg's providing a contract (excluding vzany consumer):
icurl -g 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=subtree&target-subtree-class=vzRtProv,vzProvDef&rsp-subtree-include=count&query-target-filter=or(eq(vzRtProv.tCl,"fvAEPg"),eq(vzRtProv.tCl,"l2extInstP"),eq(vzRtProv.tCl,"l3extInstP"),wcard(vzProvDef.dn,"uni/tn-'.*'/inherited-\[uni/tn-"))'
#To list all epg objects providing a contract (excluding vzany consumers):
icurl -g 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=subtree&target-subtree-class=vzRtProv,vzProvDef&query-target-filter=or(eq(vzRtProv.tCl,"fvAEPg"),eq(vzRtProv.tCl,"l2extInstP"),eq(vzRtProv.tCl,"l3extInstP"),wcard(vzProvDef.dn,"uni/tn-'.*'/inherited-\[uni/tn-"))' | python -m json.tool
#To get the count of vzany's providing a contract:
#To list all vzany objects providing a contract:
icurl 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=children&target-subtree-class=vzRtAnyToProv' | python -m json.tool
02-23-2023 09:28 AM
Thanks for your reply.
My problem is the other way around though. I don't know if there is a contract between 2 EPG's and would like to find out. I'm trying to create a script for automating.
I'm guessing I could get all contracts where epg1 is provider and where epg3 is consumer, as an example. Then massage that output in python. But it would be good if the APIC could answer this for me directly with a query.
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