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:
- Connecting to Central with the Pycentral base object
- Individual Profile Operations
- Bulk Profile Operations
Prerequisites
Installation Steps
-
Install a virtual environment (refer to Python venv documentation). Make sure Python version 3 is installed on your system.
python -m venv env
-
Activate the virtual environment:
- On Mac/Linux:
source env/bin/activate
- On Windows:
env\Scripts\activate.bat
- On Mac/Linux:
-
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
-
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:
- Base URLs of Central Clusters
- Generating Access Token from Central UI
- Generating Access Token using OAuth APIs
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.
-
Locate the API endpoint
The API endpoint will be the last suffix appended to the full URL on the reference page -
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.
-
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)
- Create a DNS profile
- Read the created profile
- Update the profile description
- Delete the profile
Bulk Operations (VLAN Profiles)
- Create multiple VLAN profiles at once
- Read all VLAN profiles from Central library
- Update the description of all VLANS simultaneously
- Delete all profiles
Documentation
Updated 3 days ago