Cisco ACI Programmability - Using REST APIs

by [Published on 14 July 2015 / Last Updated on 14 July 2015]

I thought I’d take a break from the series of writing how to setup Cisco ACI and talk a little bit about the programmability features available within ACI. Any of the other articles I’ve written where I’ve shown how to set things up using the GUI, you can also do by using REST API calls to the Cisco Application Policy Infrastructure Controller (APIC). You can write python scripts incorporating these calls to orchestrate things, or we can simply just use a REST client, available for free, to make API calls that will do anything from setting up the initial fabric to creating End Point Groups and probably anything else you can think of.

To start we’re going to use the POSTMAN REST client. It can be downloaded for free from the Chrome Web Store. You can use any other REST client if you prefer one from Mozilla, for example.  Within Postman we make GET, PUT, POST, and DELETE calls to the API (there are other calls, but these are the four used most). We then use XML or JSON code in the payload which is where the programmability occurs. In the picture below we see the saved collections on the left. We can see that I’m using the POST method in the main window. When I click on Body I see the JSON payload which in this example is configuring Leaf 1 in our fabric.

Now, just looking at the JSON code, especially if you’re not familiar with JSON or XML can be a bit intimidating. The first question people usually ask is where do I get this code from? You can absolutely read the documentation and figure out how to make your own code. You can also get on Github.com and check out the ACI code already available there. However, the coolest option with ACI is that you can use what is called the API Inspector. The API Inspector will actually record the tasks you do manually in the APIC GUI and give you the XML code output so that you can re-use it later.

To use the API Inspector:

  1. Login to the APIC GUI
  2. Click on Admin in the upper right corner
  3. Select Show the API Inspector
  4. Minimize the API Inspector
  5. Do whatever task you’d like to record in XML, like adding a switch to the fabric, creating a Bridge Domain or End Point Group, etc.
  6. Bring the API Inspector back up and find the right payload.
  7. Copy and paste the XML or JSON code into POSTMAN and save it for later use!

In the video below I show an example of setting up an ACI fabric with two spine switches and two leaf switches. It shows me authenticating to the APIC and then running four scripts to join each switch to the fabric. Now, this could all be done in one script as well, if we wanted to, but this shows it in a more understandable way.

Please check out the video below and if you have any questions please post them in the comments below or reach out to me on Twitter @Malhoit.

See Also


The Author — Lauren Malhoit

Lauren Malhoit avatar

Lauren Malhoit has been in the IT field for over 10 years and has acquired several data center certifications. She has been writing for a few years for several different websites.

Latest Contributions

Advertisement

Featured Links