Saturday, 17 June 2017

Development of Applications on Cisco ACI

Image result for cisco aci logo
 Application Development on Cisco ACI

Cisco's Application Centric Infrastructure has been recently making headway in the industry. They

recently launched the Cisco ACI app-center which is something like the Android app store. I have

 recently been playing around with it and have been wanting to put together a tutorial about it.

Get your development environment ready

 For windows users -  As of the initial release ACI Apps can be developed only using a Linux environment. I would recommend running a virtual machine on vagrant . I am running a Ubuntu trusty vagrant on windows.

1) Get the cisco aci-app-packager utility by executing this command on the linux shell

        wget https://developer.cisco.com/fileMedia/download/3b2c497f-2da5-4003-8773-304c529bfe1d

or clicking on the "App packager Utility" link in    this website
   
       https://developer.cisco.com/site/aci/docs/app-center/getting-started/index.gsp

2) Do a tar -xvf <filename of the file which got downloaded> . In my case
   
       tar -xvf 3b2c497f-2da5-4003-8773-304c529bfe1d

(where 
3b2c497f-2da5-4003-8773-304c529bfe1d was the name of the file which got downloaded)
3) After you extract the contents of the file you should see a folder called cisco_aci_app_tools-1.0

                               

4) Change your present working directory to cisco_aci_app_tools-1.0

       cd cisco_aci_app_tools-1.0/


5) Install cisco_aci_app_tools python package by executing

       python setup.py install

(Windows users, if you get a memory error while installing , try increasing the RAM size of the vagrant)
6)  Once the tools have been installed , cd into the tools directory.

      cd tools

7) Install Zip package.

     sudo apt-get install zip

 8) There would be three scripts in the tools directory

                                   

   -] aci_app_creator.py  - Cisco ACI expects the app to have a particular directory structure and have certain legal documents and stuff to be present in the directory . This script simplifies it , more on this later.
   -] aci_app_packager.py - Packages the app into a .aci extension

   -] aci_app_validator.py - Validates the app and verifies if the app directory is of proper directory structure

Before proceeding further, I would like to give you a small tutorial on the two types of ACI apps

-] Stateless app

-] Statefull app

Every ACI app has 2 components a front end and a back end.  The apps are loaded in the ACI apps tab on the APIC.


Stateless app

A stateless app on Cisco ACI is one with only front end in it. Its basically a static HTML, javascript

 and CSS combination. The stateless app is loaded within an iframe in the Cisco ACI. 


Stateful  app
Let me put the concept of a stateful app in a simple way. Imagine you are developing a python

application for Cisco ACI (like maybe getting the list of all tenants, or checking the health of each 

tenant maybe) what you would normally do is you would write the code using Cobra SDK or ACI 

toolkit . Now you just don't want to leave it accessible from a command line , you want to give a nice

GUI and everything, so you would say , let me write a python flask application and when i do an 

action on the GUI let me invoke functions of the code i wrote using Cobra SDK or ACItoolkit via

javascript or AJAX.

This is what, Cisco ACI appstore actually does but in a neater way.

So what actually happens is that the front end actually remains as it was in the stateless application,


but the backend is now run in a docker container in the APIC. More on how to do this in just a 

moment!


Directory Structure

Cisco dictates the application being developed have a particular directory structure before you can 

package the application and deploy it on the APIC. Although the directory structure looks

complicated you really dont have to do much thanks to the awesome aci app creator tool developed 

by Cisco. Let me go over the important files and their uses

-]   app.json - The app.json is a json file which describes the application you are about to deploy.

You really do not have to touch anything unless you are developing a stateful application where you 

just need to add the rest api's exposed in your server.py , in the "api" field in the file.  


-] Legal - The legal folder contains all the legal stuff that cisco needs you to have before deploying 

the application on Apic :)

-] Media - The Media folder contains the Intro video to your app, License , ReadMe and Snapshots.

-] UIAssets - The UIAssets is the place where you have to place your HTML, CSS and Javascript 

code.  The CSS and Javascript code go into the CSS and Scripts folders respectivley. 

-] UIAssets/app-start.html - You really don't have to touch the file

-] UIAssets/app.html -  This is a starting application , which the creator utility provides, you really 

just need to add your functions to this file.

Note the icon.png file in the UI Assets folder you need reference  this in the "iconfile" field in the

app.json  file.

Creating a Stateless application 

1) Change into cisco_aci_app_tools-1.0/tools directory 

          cd cisco_aci_app_tools-1.0/tools/

2) Execute the aci_app_creator tool 
                 
          python aci_app_creator.py



Note- Make sure you select no when the tool asks you to add a docker container to your application, the docker application is only when you need to create a stateful application. Also when it asks if you want to package the application make sure you select no

3) Add your application code into the UIAssets folder in the respective places as described above.

4)  Once you are done , execute the packager utility by specifying the root folder of the application

                 python aci_app_validator.py -f  <full path name>

 Once  your done a .aci file would be created with the same name as your folder

        

5) Login into your apic and in go to the "Apps tab", under the apps tab go to the "All apps" subtab 

and click on the small plus sign to upload your .aci file. 



6) After the upload completes in a short while you will see your  app under the "All apps" section .



7) Click on the app and select the install button to install it.


8) Once the app finishes installing you should see it in the "Installed apps" section




9) And ..... 





 Finally congrats :) you got your first app running!!! Will be posting on stateful app soon! 

Equation