cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
790
Views
0
Helpful
2
Replies

ACI API query contract/vzBrCP

andreaswall
Level 1
Level 1

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

2 Replies 2

micgarc2
Cisco Employee
Cisco Employee
Moquery might be easier:
 
moquery -c vzRtCons -f 'vz.RtProv.dn*"tn-common/brc-default"' <-- epgs consuming this contract in common tenant
moquery -c vzRtProv -f 'vz.RtProv.dn*"tn-common/brc-default"'  <-- epgs providng this contract in common tenant
 
but here are multiple examples to do it with an icurl:

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:

icurl 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=children&target-subtree-class=vzRtAnyToCons&rsp-subtree-include=count'

 

#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:

icurl 'http://localhost:7777/api/node/mo/uni/tn-mg/'$CONTRACT'.json?query-target=children&target-subtree-class=vzRtAnyToProv&rsp-subtree-include=count'

 

#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

 
 
I did one example for you in the lab 
 
#To get the count of epg's providing a contract (excluding vzany consumer):
 
micgarc2@a-apic1# bash
micgarc2@a-apic1:~> CONTRACT='brc-pbr_stretched_contract'
micgarc2@a-apic1:~> 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
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 278 100 278 0 0 23166 0 --:--:-- --:--:-- --:--:-- 23166
{
"imdata": [
{
"vzRtProv": {
"attributes": {
"childAction": "",
"dn": "uni/tn-mg/brc-pbr_stretched_contract/rtfvProv-[uni/tn-mg/ap-pbr/epg-server]",
"lcOwn": "local",
"modTs": "2023-02-02T16:58:27.301-05:00",
"status": "",
"tCl": "fvAEPg",
"tDn": "uni/tn-mg/ap-pbr/epg-server"
}
}
}
],
"totalCount": "1"
}

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.

Save 25% on Day-2 Operations Add-On License