Adding an interface policy via API on Cisco ACI

Abstract

This post summarizes how to create any interface policy on Cisco ACI using API.

Cisco ACI allows to download any object in different formats (json, xml). That downloaded file can be used as a template to create objects.

Using the GUI navigate to Fabric -> Access Policies -> Interface Policies -> Policies and create, for example a new policy for CDP:

  • Name: CDP_on
  • Description: Enable CDP
  • Admin State: Enabled

Confirm then right click on the CDP_on policy and save it:

  • Content: Only configuration
  • Scope: Tree
  • Export Format: json

Now delete the policy CDP_on from the GUI.

The saved json file will be something like the following:

{
  "totalCount": "1",
  "imdata": [
    {
      "cdpIfPol": {
        "attributes": {
          "adminSt": "enabled",
          "descr": "Enable CDP",
          "dn": "uni/infra/cdpIfP-CDP_on",
          "name": "CDP_on",
          "nameAlias": "",
          "ownerKey": "",
          "ownerTag": ""
        }
      }
    }
  ]
}

The important content is:

{
  "cdpIfPol": {
    "attributes": {
      "adminSt": "enabled",
      "descr": "Enable CDP",
      "dn": "uni/infra/cdpIfP-CDP_on",
      "name": "CDP_on"
    }
  }
}

Now login to the APIC using API and POST the same content:

curl -c /tmp/cookie -b /tmp/cookie -k -s -X POST -d '{"cdpIfPol":{"attributes":{"adminSt":"enabled","descr":"Enable CDP","dn":"uni/infra/cdpIfP-CDP_on","name":"CDP_on"}}}' -H 'Content-type: application/json' 'https://172.25.82.1/api/mo/uni.json?challenge=557c50785a8a6e759f39f139db86b4cafbaefe0e984305a1173c0cc4396cc474' | python -m json.tool

References

Posted on 21 Mar 2018 by Andrea.
  • Gmail icon
  • Twitter icon
  • Facebook icon
  • LinkedIN icon
  • Google+ icon