NSX

Avi Networks | NSX ALB

Base Configuration via API

Posted by Chris Noon on Fri, Jun 19, 2020

API Reference

I wrote a post a few weeks back on how to get an Avi proof of concept up and running. Hopefully, it helped and continues to help others wanting to start playing with Avi.

I like to spin my lab up and down, pushing config when needed. This post will be focused around the Avi APIs and how to stand up the basic configuration previously discussed.

I used the Avi API guide for reference: https://avinetworks.com/docs/latest/

Alternatively, you can navigate to: https://{Avi Controller IP}/api

At this stage, I will assume at least 1 or 3 Controller(s) has been deployed, a logical cloud has been created along with the relevant networks for Avi consumption.

Disclaimer. I will be providing the bare minimum to get a pool and VIP up and running. There are tones of options when using Avi API!

What I’ll end up with?

My VIP will be 10.0.14.40/24 which is part of my predefined pool for the Avi SE’s.

My Pool members will be 172.16.1.21, 172.16.1.22 and 172.16.1.23. Running an HTTP service.

Logical Diagram

Prerequisites

You will need a few API calls to learn the Cloud ID and the Network ID used in the later examples.

https://{Avi Controller IP}/api/cloud

https://{Avi Controller IP}/api/network

Authentication

There are 2 types of authentication when using Avi APIs. The fist is token-based and the second is basic authentication.

I’m still figuring out the token-based but will update the blog as I crack it.

Using basic authentication requires you to edit the controllers using the CLI: https://avinetworks.com/docs/18.2/http-basic-auth-for-api-queries/

Pools

POST https://[Avi Controller IP]/avi/pool Header:

X-Avi-Version = version number e.g. 18.2.8
Content-Type = application/json
Specify your chosen authentication.

BODY:

 1{
 2     "cloud_ref": "https://10.0.10.23/api/cloud/[Cloud UUID]",
 3     "lb_algorithm": "LB_ALGORITHM_ROUND_ROBIN", 
 4     "default_server_port": 80, 
 5     "name": "web_pool", 
 6     "servers": [
 7         {
 8             "ip": {
 9                 "type": "V4", 
10                 "addr": "172.16.1.21"
11             }
12         }, 
13         {
14             "ip": {
15                 "type": "V4", 
16                 "addr": "172.16.1.22"
17             }
18         },
19         {
20             "ip": {
21                 "type": "V4", 
22                 "addr": "172.16.1.23"
23             }
24         }
25     ]
26 }

It’s important to note the return response as you’ll need the pool UUID for the VIP creation:

e.g. “UUID”: “pool-40c3fbd2-7873-458f-8718-ab15d728d015”

VIPs

POST https://{Avi Controller IP}/avi/virtualservice Header:

X-Avi-Version = version number e.g. 18.2.8
Content-Type = application/json
Specify your chosen authentication.

BODY:

 1{
 2     "cloud_ref": "https://10.0.10.23/api/cloud/[Cloud UUID]",
 3     "pool_ref": "https://10.0.10.23/api/pool/[Pool UUID]",
 4     "name": "web_vip",
 5     "vip": [
 6         {
 7             "auto_allocate_ip": true,
 8             "discovered_networks": [
 9                 {
10                 "network_ref": "https://10.0.10.23/api/network/[Port Group UUID]"
11                 }
12             ]
13         }
14     ],
15     "services": [
16             {
17                 "enable_ssl": false,
18                 "port": 80
19             }
20         ]
21 }

Cleanup

X-Avi-Version = version number e.g. 18.2.8
Content-Type = application/json
Specify your chosen authentication.

1GET https://10.0.10.23/api/virtualservice
2    N.B. Virtual Server UUID.
3
4GET https://10.0.10.23/api/pool
5    N.B. Pool UUID.
6
7DELETE https://10.0.10.23/api/virtualservice/[Virtual Server UUID]
8
9DELETE https://10.0.10.23/api/pool/[Pool UUID]

Closing

I’ve only shown the API calls for the GET, POST and DELETE on Pools and VIPs which I believe is the most repeatable task with any Load Balancer. If you want more API calls on the base configuration of Avi or other areas please let me know in the comments or on twitter.