HomeGuidesAPI ReferenceGuidesMRT APIConfiguration API
GitHubAirheads Developer Community
Guides

Profile Operations

How to use Pycentral to operate on Central Library profiles

Source code for this guide can be found at our GitHub Repository central-python-workflows.

Overview

This workflow demonstrates how to use the Pycentral library to manage Central library profiles. It covers creating, reading, updating, and deleting configuration profiles through Central API handled by Pycentral. In doing so you will learn how to connect to Central and demonstrate the two main approaches to profile operations with Pycentral:

  1. Connecting to Central with the Pycentral base object
  2. Individual Profile Operations
  3. Bulk Profile Operations

Prerequisites

Installation Steps

  1. Install a virtual environment (refer to Python venv documentation). Make sure Python version 3 is installed on your system.

    python -m venv env
    
  2. Activate the virtual environment:

    • On Mac/Linux:
      source env/bin/activate
      
    • On Windows:
      env\Scripts\activate.bat
      
  3. Clone the repository and cd into the profile-operations directory.

    git clone https://github.com/aruba/central-python-workflows.git
    cd central-python-workflows/profile-operations
    
  4. Install the required packages:

    python -m pip install -r requirements.txt
    

Aruba Central API Credentials

Generating a central connection with pycentral requires passing a dictionary
containing information to the NewCentralBase class as an argument. This dictionary should
include the base URL, client ID, and client secret for the Central API.

  • Base URL: Central instance URL
  • Client ID: Central client ID
  • Client Secret: Central client secret

📘

Best Practice

Credentials should be loaded from a separate file instead of hardcoded into a script.

Learn more about obtaining credentials with the following links:

Configuration Requirements

To work with configuration profiles with Pycentral we need to gather
several pieces of information required for interacting with the Central API. This
includes the API endpoint, the bulk key, and the profile configurations we want to use.
We can gather this information by referring to the official configuration API reference on the Developer Hub

Gathering API information from the Configuration Reference

We will use the API reference for DNS as an example to demonstrate how to gather the information required for working with profiles.

  1. Locate the API endpoint
    The API endpoint will be the last suffix appended to the full URL on the reference page

    api endpoint
  2. Determine the bulk key
    We refer to the bulk key in Pycentral as the key for the body object of the payload.
    Most often, the bulk key will simply be 'profile', however some APIs will use a unique
    identifier.

  3. Profile configurations
    You can use the body object in the API reference to find valid configuration values to use in your own
    configuration object for Pycentral. Here are some of the values for the DNS profile body
    object for example:

Sample Configuration

Here is an example profile configuration in python that we can use to create a DNS library profile with Pycentral:

dns_profile = {
    "name": "example-dns",
    "description": "example-dns description",
    "resolver": [
        {"vrf": "default", "name-server": [{"ip": "8.8.8.8", "priority": 1}]}
    ],
}

👍

Protip:

An easy way to get example configurations for profile payloads you are unfamiliar with is to create a profile using the web UI in Central. Then, run a GET request for the profile with Pycentral.

Executing the script

The script can be run as is with valid credentials to see how Pycentral runs operations
in the terminal.

With the API credentials filled out in the profiles_operations.py file, and in the profile-operations directory:

python profiles_operations.py

Script Operations

Individual Operations (DNS Profile)

  1. Create a DNS profile
  2. Read the created profile
  3. Update the profile description
  4. Delete the profile

Bulk Operations (VLAN Profiles)

  1. Create multiple VLAN profiles at once
  2. Read all VLAN profiles from Central library
  3. Update the description of all VLANS simultaneously
  4. Delete all profiles

Documentation