Global IP Pool Guide

Introduction

As part of the Site Design, the Global IP Pool endpoints support for the developer to manage IP Address pools in Catalyst Center in places like virtual networks for Software Defined Access.

Goal

The goals of this guide are:

  1. Get the site topology.
  2. Get the physical topology.
  3. Get the logical topology.

Global IP Pool workflow

Endpoints and methods used

  • POST /dna/system/api/v1/auth/token
  • POST /dna/intent/api/v1/global-pool
  • GET /dna/intent/api/v1/global-pool

Prerequisites

For this module, we recommend that the user already has experience authenticating with Catalyst Center:

Environment

This guide was developed using:

Authentication

First, we must authenticate and retrieve a token from the API.

Note: Do not use verify=False or urllib3.disable_warnings() if you are not sure of its purpose. Read Authentication and Authorization.

import requests
from requests.auth import HTTPBasicAuth
import urllib3
urllib3.disable_warnings()

BASE_URL = 'https://<IP Address>'
AUTH_URL = '/dna/system/api/v1/auth/token'
USERNAME = '<USERNAME>'
PASSWORD = '<PASSWORD>'

response = requests.post(BASE_URL + AUTH_URL, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False)
token = response.json()['Token']

Global IP Pool API

It allows the user to create an IP Pool for configuring virtual networks.

Create Global IP Pool

Site Topology returns information about the sites in Catalyst Center and their hierarchy that is related to the Global site.

GLOBAL_IP_POOLS_URL='/dna/intent/api/v1/global-pool'
pool_information = {
    "settings": {
        "ippool": [
            {
                "ipPoolName": "DNAC-Guide_Pool",
                "type": "Generic",
                "ipPoolCidr": "172.30.200.0/24",
                "gateway": "172.30.200.1",
                "dhcpServerIps": ["10.255.3.50"],
                "dnsServerIps": ["10.255.3.50"],
                "IpAddressSpace":"IPv4"
            }
        ]
    }
}
response = requests.post(BASE_URL + GLOBAL_IP_POOLS_URL,
                        json=pool_information,
                        headers=headers, verify=False)
print(response)

List IP Pools

Using the APIs it is possible to list the available IP Pools:

GLOBAL_IP_POOLS_URL='/dna/intent/api/v1/global-pool'
query_params = {
    "limit": 10
}
response = requests.get(BASE_URL + GLOBAL_IP_POOLS_URL,
                        params=query_params,
                        headers=headers, verify=False)
for pool in response:
    print(pool['id'], pool['ipPoolName'], pool['ipPoolCidr'])

Code

The repository for this guide is here. The final code with functions appears as below.

# Modules import
import requests
from requests.auth import HTTPBasicAuth

# Disable SSL warnings. Not needed in production environments with valid certificates
import urllib3
urllib3.disable_warnings()

# Authentication
BASE_URL = 'https://<IP Address>'
AUTH_URL = '/dna/system/api/v1/auth/token'
USERNAME = '<USERNAME>'
PASSWORD = '<PASSWORD>'

# URLs
# URLs
GLOBAL_IP_POOLS_URL='/dna/intent/api/v1/global-pool'

# Get Authentication token
def get_dnac_jwt_token():
    response = requests.post(BASE_URL + AUTH_URL,
                             auth=HTTPBasicAuth(USERNAME, PASSWORD),
                             verify=False)
    token = response.json()['Token']
    return token

# Get Global pools
def get_global_ip_pools(headers, query_params):
    response = requests.get(BASE_URL + GLOBAL_IP_POOLS_URL,
                            params=query_params,
                            headers=headers, verify=False)
    return response.json()['response']

# Create Global pools
def create_global_ip_pools(headers, pool_information):
    response = requests.post(BASE_URL + GLOBAL_IP_POOLS_URL,
                            json=pool_information,
                            headers=headers, verify=False)
    return response.json()

def main():
    # obtain the Catalyst Center Auth Token
    token = get_dnac_jwt_token()
    headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
    pool_information = {
        "settings": {
            "ippool": [
                {
                    "ipPoolName": "DNAC-Guide_Pool",
                    "type": "Generic",
                    "ipPoolCidr": "172.30.200.0/24",
                    "gateway": "172.30.200.1",
                    "dhcpServerIps": ["10.255.3.50"],
                    "dnsServerIps": ["10.255.3.50"],
                    "IpAddressSpace":"IPv4"
                }
            ]
        }
    }

    response = create_global_ip_pools(headers, pool_information)

    time.sleep(5)

    response = get_global_ip_pools(headers, {})
    for pool in response:
        print(pool['id'], pool['ipPoolName'], pool['ipPoolCidr'])

if __name__ == "__main__":
    main()