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

Cisco ACI API get interface status

p.juarezponte
Beginner
Beginner

Hello team,

I am trying to get interface status from all the spine and leafs by using API.

I just need to collect interface status, like speed and operational status to create some excel spreedsheets just to have an inventory and know how many switchports are available (up/down).

I have been able to login to ACI and make a basic request, but I dont know which should be the url to get that info.

Any help?

 

1 Accepted Solution

Accepted Solutions

Claudia de Luna
Rising star
Rising star

HI @p.juarezponte 

 

The basic hardcoded API call would look something like this (this isa postman call with an environment that defines the variable URL):

 

 

https://{{URL}}/api/node/mo/topology/pod-1/node-101/sys/phys-[eth1/1].json


This returns this data structure and you can see that 'adminSt' is there.

 

 

{
    "totalCount": "1",
    "imdata": [
        {
            "l1PhysIf": {
                "attributes": {
                    "adminSt": "up",
                    "autoNeg": "on",
                    "brkoutMap": "none",
                    "bw": "0",
                    "childAction": "",
                    "delay": "1",
                    "descr": "",
                    "dfeDelayMs": "0",
                    "dn": "topology/pod-1/node-101/sys/phys-[eth1/1]",
                    "dot1qEtherType": "0x8100",
                    "ethpmCfgFailedBmp": "",
                    "ethpmCfgFailedTs": "00:00:00:00.000",
                    "ethpmCfgState": "0",
                    "fcotChannelNumber": "Channel32",
                    "fecMode": "inherit",
                    "id": "eth1/1",
                    "inhBw": "unspecified",
                    "isReflectiveRelayCfgSupported": "Supported",
                    "layer": "Layer2",
                    "lcOwn": "local",
                    "linkDebounce": "100",
                    "linkFlapErrorMax": "30",
                    "linkFlapErrorSeconds": "420",
                    "linkLog": "default",
                    "mdix": "auto",
                    "medium": "broadcast",
                    "modTs": "2022-01-12T10:39:37.423+00:00",
                    "mode": "trunk",
                    "monPolDn": "uni/infra/moninfra-default",
                    "mtu": "9000",
                    "name": "",
                    "pathSDescr": "",
                    "portPhyMediaType": "auto",
                    "portT": "leaf",
                    "prioFlowCtrl": "auto",
                    "reflectiveRelayEn": "off",
                    "routerMac": "not-applicable",
                    "snmpTrapSt": "enable",
                    "spanMode": "not-a-span-dest",
                    "speed": "inherit",
                    "status": "",
                    "switchingSt": "disabled",
                    "trunkLog": "default",
                    "usage": "discovery"
                }
            }
        }
    ]
}


To make a "reusable" string you would want to turn pod, node, and the ethernet port into variables so you could cycle through the fabric.

 

 

For example using Python f-string:

rest_call = f"https://{URL}/api/node/mo/topology/pod-{pod_number}/node-{node_id}/sys/phys-[eth1/{port_number}].json

 

Next you need to get all the nodes in the fabric so you could use something like below:

https://{{URL}}/api/node/class/fabricNode.json

 

 

This returns:

{
    "totalCount": "9",
    "imdata": [
        {
            "fabricNode": {
                "attributes": {
                    "adSt": "on",
                    "address": "10.0.184.66",
                    "annotation": "",
                    "apicType": "apic",
                    "childAction": "",
                    "delayedHeartbeat": "no",
                    "dn": "topology/pod-1/node-102",
                    "extMngdBy": "",
                    "fabricSt": "active",
                    "id": "102",
                    "lastStateModTs": "2022-01-12T10:40:57.385+00:00",
                    "lcOwn": "local",
                    "modTs": "2022-01-13T08:30:55.811+00:00",
                    "model": "N9K-C9396PX",
                    "monPolDn": "uni/fabric/monfab-default",
                    "name": "leaf-2",
                    "nameAlias": "",
                    "nodeType": "unspecified",
                    "role": "leaf",
                    "serial": "TEP-1-102",
                    "status": "",
                    "uid": "0",
                    "userdom": "all",
                    "vendor": "Cisco Systems, Inc",
                    "version": "simsw-5.2(1g)"
                }
            }
        },
.... data structure continues but not included for brevity...

 

I find the API Inspector to be great at figuring out the rest calls.

 

Final note is that for ACI you probably want to understand if a port is part of a policy in addition to Admin state and speed.   Here I'm making some assumptions though so hopefully the above will be of some help and in the ball park of what you needed!

 

 

View solution in original post

2 Replies 2

cattymaloudy
Beginner
Beginner

Only issue with my method is that the ascending sort places numbers before the square bracket, so port 10-19 are listed before port 1, etc. http://www.kitchensinn.com/ 

Claudia de Luna
Rising star
Rising star

HI @p.juarezponte 

 

The basic hardcoded API call would look something like this (this isa postman call with an environment that defines the variable URL):

 

 

https://{{URL}}/api/node/mo/topology/pod-1/node-101/sys/phys-[eth1/1].json


This returns this data structure and you can see that 'adminSt' is there.

 

 

{
    "totalCount": "1",
    "imdata": [
        {
            "l1PhysIf": {
                "attributes": {
                    "adminSt": "up",
                    "autoNeg": "on",
                    "brkoutMap": "none",
                    "bw": "0",
                    "childAction": "",
                    "delay": "1",
                    "descr": "",
                    "dfeDelayMs": "0",
                    "dn": "topology/pod-1/node-101/sys/phys-[eth1/1]",
                    "dot1qEtherType": "0x8100",
                    "ethpmCfgFailedBmp": "",
                    "ethpmCfgFailedTs": "00:00:00:00.000",
                    "ethpmCfgState": "0",
                    "fcotChannelNumber": "Channel32",
                    "fecMode": "inherit",
                    "id": "eth1/1",
                    "inhBw": "unspecified",
                    "isReflectiveRelayCfgSupported": "Supported",
                    "layer": "Layer2",
                    "lcOwn": "local",
                    "linkDebounce": "100",
                    "linkFlapErrorMax": "30",
                    "linkFlapErrorSeconds": "420",
                    "linkLog": "default",
                    "mdix": "auto",
                    "medium": "broadcast",
                    "modTs": "2022-01-12T10:39:37.423+00:00",
                    "mode": "trunk",
                    "monPolDn": "uni/infra/moninfra-default",
                    "mtu": "9000",
                    "name": "",
                    "pathSDescr": "",
                    "portPhyMediaType": "auto",
                    "portT": "leaf",
                    "prioFlowCtrl": "auto",
                    "reflectiveRelayEn": "off",
                    "routerMac": "not-applicable",
                    "snmpTrapSt": "enable",
                    "spanMode": "not-a-span-dest",
                    "speed": "inherit",
                    "status": "",
                    "switchingSt": "disabled",
                    "trunkLog": "default",
                    "usage": "discovery"
                }
            }
        }
    ]
}


To make a "reusable" string you would want to turn pod, node, and the ethernet port into variables so you could cycle through the fabric.

 

 

For example using Python f-string:

rest_call = f"https://{URL}/api/node/mo/topology/pod-{pod_number}/node-{node_id}/sys/phys-[eth1/{port_number}].json

 

Next you need to get all the nodes in the fabric so you could use something like below:

https://{{URL}}/api/node/class/fabricNode.json

 

 

This returns:

{
    "totalCount": "9",
    "imdata": [
        {
            "fabricNode": {
                "attributes": {
                    "adSt": "on",
                    "address": "10.0.184.66",
                    "annotation": "",
                    "apicType": "apic",
                    "childAction": "",
                    "delayedHeartbeat": "no",
                    "dn": "topology/pod-1/node-102",
                    "extMngdBy": "",
                    "fabricSt": "active",
                    "id": "102",
                    "lastStateModTs": "2022-01-12T10:40:57.385+00:00",
                    "lcOwn": "local",
                    "modTs": "2022-01-13T08:30:55.811+00:00",
                    "model": "N9K-C9396PX",
                    "monPolDn": "uni/fabric/monfab-default",
                    "name": "leaf-2",
                    "nameAlias": "",
                    "nodeType": "unspecified",
                    "role": "leaf",
                    "serial": "TEP-1-102",
                    "status": "",
                    "uid": "0",
                    "userdom": "all",
                    "vendor": "Cisco Systems, Inc",
                    "version": "simsw-5.2(1g)"
                }
            }
        },
.... data structure continues but not included for brevity...

 

I find the API Inspector to be great at figuring out the rest calls.

 

Final note is that for ACI you probably want to understand if a port is part of a policy in addition to Admin state and speed.   Here I'm making some assumptions though so hopefully the above will be of some help and in the ball park of what you needed!

 

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers