Rename Hostnames
Workflow tutorial for renaming hostnames pycentral script
Source code for this guide can be found at our GitHub Repository central-python-workflows.
Workflow Overview
This is a Python script that uses pycentral (beta version v2.0beta2) to change the hostname of devices in Central at scale from an input CSV file. Devices can be of any supported type in Central and do not have to be sorted in any order. The input CSV file is provided by the user and should be filled out with the required information before execution. An example input file can be found here
Prerequisites
- All devices have valid Central licenses before the workflow is run.
- Devices are all online and configurable.
Setup
In order to run the script, please complete the steps below:
Virtual environment and dependencies
In a terminal at the location you want to execute the script:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Clone the repository
git clone https://github.com/aruba/central-python-workflows.git
# Navigate into the appropriate directory
cd central-python-workflows\rename-hostnames
# Install dependencies
pip install -r requirements.txt
Provide the Central API Gateway Base URL & Access Token
In the rename-hostnames directory open the central_token.json file and provide the base_url, client_id, and client_secret of your Central client credential. If you need help finding this information please follow the links in the information block below for guidance.
{
"new_central": {
"base_url": "",
"client_id": "",
"client_secret": "",
"access_token": ""
}
}
Information for filling out the central_token file can be found at the following links:
Update the variables.csv file
variables.csv is the default CSV file. Required values are device serial numbers and new hostnames. Fill in the details in their respective columns required for execution. You can optionally create a custom named CSV with the same structure to be used which can be passed as an argument when executing the script.
Headers must stay in file, do not remove them
Example structure from variables_sample.csv
serial,new_hostname
{device1_serial},{device1_new_hostname}
{device2_serial},{device2_new_hostname}
Execution
Once central_token.json and variables_sample.csv are updated with the relevant information, you can execute the script with the following command:
python renaming_hostnames.py
Optional arguments can be used to execute script with custom token and CSV files
This script takes the following optional arguments to override default filenames for the script:
--central_auth
: Path of the Central Token File.--csv_names
: Path of the CSV file with device serial numbers and new hostnames(if no CSV is specified, the defaultvariables_sample.csv
file will be used).- You can run the following command to use the optional parameters:
python renaming_hostnames.py --central_auth <central_token_file> --csv_names <csv_names_file>
If the script runs successfully, your terminal output should look like this:

A file named output.csv will be created in the working directory with the results of the script:
- Columns will consist of:
serial_number
,new_name
,status
. - The
status
variable shows whether or not the device was successfully renamed.
serial_number,new_name,status
{device1_serial},{device1_new_hostname},success
{device2_serial},{device2_new_hostname},failure
Known Issues
- Due to an API bug, the script incorrectly reports the current hostnames of devices as 'sys_host_name' on the CLI output. However, this bug does not affect the functionality of the script and new hostnames of the devices do get updated via API as expected.
Updated 3 days ago
Take a look a some of our other workflows to see what capabilities are available!