API Scripting with AVI Networks

This blog is about AVI-networks, a leader in the world of load balancers that developed their Vantage platform from the ground up to be compatible with the new methods of building datacenter.

Avi Networks delivers multi-cloud application services with elastic application delivery, security, and pervasive analytics across data centers and clouds. Avi Vantage makes it easy to apply load balancing, web application firewall and service mesh to any application.

This blog will help you in getting familiar with simple API calls using curl with the help of a script developed by Metsi to facilitate authentication and structure commands to the controller.

The platform offers incredible flexibility to integrate in any cloud using automation through the API. And this API can be controlled via many different methods. To name a few:

  • Web API using JSON coded data
  • Python SDK
  • Ansible playbooks

But this flexibility often leads to confusion about which tools fits best for the job. Should I use Ansible for a basic task? Or will this be overkill? Should I use web-API capable scripting tool such as Postman for orchestration, or does this has certain limits and will I have to switch over to another tool later on? As a result, often automation via the API is considered as cumbersome and technically challenging.

But it does not need to be. We at Metsi are there to help customers facilitate the adoption of automation and orchestration and here below is a short description of how a simple script can help facilitate day to day tasks on AVI-Networks Vantage platform.

When using the AVI Networks API everything is JSON coded. JSON is another lightweight format to store data or configuration statements in a human readable format, comparable to XML. For more info about JSON, visit:

Using the AVI Networks API makes it very easy to get existing configuration of …, alter it and re-upload to add for instance a new pool or Virtual Service (VS). But it can be used for anything within the AVI Vantage platform that you want to add or remove. Manipulations of a Pools or VS are required most often and are a good candidate to look at automating.

Take the below example to add a pool, structured in JSON code:

  "default_server_port": 80,
  "name": "demo_pool",
  "servers": [
      "ip": {
        "type": "V4",
        "addr": ""
      "hostname": "backend1"
      "ip": {
        "type": "V4",
        "addr": ""
      "hostname": "backend2"
  "fail_action": {
  "inline_health_monitor": true,
  "health_monitor_refs": [


In the above example, some of the basic parameters which are easily recognisable, have been highlighted. You have the load balancing algorithm, the port and two backend servers to balance. Adjusting this to fit the need of a new farm is easy. A reference of the statements that can be used, per version, can always be found at:

If more complex pools are required, you can first build them once using the GUI. And then collect the resulting JSON via API to re-use it over and over again, with other data.

But how to do this in practice. It is always easy if you know what you are doing, but the first time a little help might be welcome. This blog will help you get started and provides easy access to the API using basic Curl.

Reading through the documentation of AVI, getting access to the controller to be able to execute GET or POST statements will require a number of things.

  • A username and password, formatted in JSON (as of version 16.2)
  • The cookies returned after successful authentication
  • A CSRFTOKEN to be able to POST JSON data
  • A number of HTTP headers depending on the used operation (GET/POST)

To facilitate all of this, I created a scripted called so you only need to provide following data:

  • Controller IP address
  • Username
  • Password
  • AVI Version

Download the script using: git clone

When you run the script, it will create a simple variables file to load after which a curl can be used to control data.

Look at the below example to get the configuration statements for a pool:

Please provide the IP address of the AVI controller to login:
Please provide an administrator username: admin
Please provide the password for this user:
Please provide the API version to use [17.1.2]: 18.1.5
Will use version: 18.1.5
Log in as admin......ok
Execute commands to AVI controller using version 18.1.5:
Example GET command: curl -k -K avi.get " "
Example POST command: curl -k -K -d "@<JSONFILE>" " "

 -k: to not validate HTTPS certificate (for self signed certificate usage)
 <JSONFILE>: replace with the filename (and path) where the JSON config is located that you want to apply

When finished, Logout to the AVI controller via ./AVI_LOGOUT


$ . ./avi.vars

$ curl -k -K avi.get “ ” > demo_pool.json

Don’t forget to load the variables file before using curl or you will not have access to the controller.

The example will get the pool demo_pool. This is to limit the number of outputs as we are only interested in the pool, we want to base our modifications on. The resulting file, called demo_pool.json contains the JSON code for this pool. Open this in your favourite editor that supports formatting of JSON. As an example, I use Atom with the ‘Pretty JSON’ package to convert the layout to a nicely structured and readable format.

Below is a part of the resulting file:

You will notice the JSON code starts with a results array. Remove this part at the top and the 2 brackets at the bottom to match the following:

Now we just have to clean up some references of the current pool to be able to create a new pool. Remove following statements:

  • _last_modified
  • url
  • uuid

And change the name to a new name like ‘test_pool’.

Look at the parameters you want to change and refer to the AVI Networks API documentation to see which parameters are mandatory.

Next, we will add our new test_pool. Keep in mind, we still have a login to the controller as long as the session idle timer is not expired (defaults to 15 minutes):

$curl -k -K -d “@demo_pool.json” “”

Don’t be afraid of the JSON formatted response you receive. If you prefer, you can also pipe this output to a file to be able to read it in your favourite editor.

Most important part is that your pool was created and is visible in the controller GUI.

Don’t forget to logout to avoid abuse of your authenticated session using the variables stored! Do this by running the small script that was created automatically:


If you would like this script, or have comments, do not hesitate to reach out to us here.

Cisco Enterprise Cloud Suite

How you define agility is dependent on your role and the processes that need automating: End users want to order applications in a self-service manner and take delivery within minutes. Application developers need automated delivery of standardized infrastructure resources to develop, test, and deploy applications. IT needs to deliver application workloads on-demand in an automated and repeatable manner, eliminating manual provisioning or deprovisioning of resources.

View Cisco Enterprise Cloud Suite

Cisco ACI

Cisco ACI helps customers manage and excel in complex environments by increasing operational efficiencies, delivering network automation, and improving security for any combination of on-premises data centers, private, and public clouds. With ACI, customers can increase business agility through network optimisation, business protection, and cloud enablement.

View Cisco ACI

CASE STUDY: Large Financial Enterprise

Customer Overview Industry: Financial Sector Location: Brussels, Belgium Number of Employees: 4000 Challenge Complex request management process No automation and orchestration of business processes Complex business process and approvals requiring manual intervention Integration into VMware, XenDesktop, SCCM, IPAM, ITSM and more...

View Case Study


Are you interested in Metsi's solutions? Do you want more information about our offerings?

Contact Us

This website uses cookies to enhance your browsing experience... moregot it