Cloud Managed Networks

 View Only
  • 1.  Aruba Central API Script with variables from a CSV file

    Posted Oct 16, 2022 04:28 PM
    Edited by mkk Oct 16, 2022 04:39 PM
    Hi Airheads Guys,

    A while ago i create a python script to run Aruba Central API Calls where variables are read from a CSV file. In this case i used the script for bulk change the name of 600 Access Points where the serial number and new AP name are read from a CSV file.

    In fact the script can easily customizable for other API calls because the first part just read the variables from a CSV and next run a API POST Payload to Central where this variables are used.

    - The central_url depend on which Aruba Cental datacenter your account in located in.
    - The token can be generated for 2 hours in de Aruba Central WebGui under Global > Organization > Platform Intergration > API Gateway 
    - The file_location is the full-path where the impor.txt file is located, keep the "r" before the C:\ to make it a raw variable.

    I hope you find the script useful and have some nice use cases for it.

    # This python script use the Aruba Central API interface to bulk change the Access Point names based on a CSV import file.
    
    import requests
    import json
    
    ### Editable parameters ###
    central_url = https://eu-apigw.central.arubanetworks.com
    access_token = "token_here"
    file_location = r"C:\test\import.txt"
    ###########################
    
    ### Note: The Aruba Cental API URL is based on the datacenter location.
    ### Note: The access_token must be created in Aruba Central first and is valid for 2 hours.
    ### Note: The file location is the fullpath incl. filename to the import.txt CSV. The "r" is needed to make the variable a raw format.
    
    ### HTML header in json code contains the access_token.
    header = {'Authorization': 'Bearer ' + access_token}
    
    ### Open the file_location CSV where "," is the delimter to devide the collums into two variables "serial" and "apname".
    with open(file_location) as importfile:
       for line in importfile:
          serial, apname = line.split(',')
          print(serial.strip(), apname.strip())
    
    ### Aruba Central API URL.
          url = central_url+"/configuration/v2/ap_settings/"+serial
    
    ### HTML body in raw json format contains the API payload.
          payload = {"hostname": apname,
                     "ip_address": "",
                     "zonename": "",
                     "achannel": "",
                     "atxpower": "",
                     "gchannel": "",
                     "gtxpower": "",
                     "dot11a_radio_disable": False,
                     "dot11g_radio_disable": False,
                     "usb_port_disable": False}
    
    ### Execute the API POST
          r = requests.post(url, json=payload, headers=header)
    
    ### Print the API Response code on screen
          response = r.text
          print (response)
    ​


    ------------------------------
    Marcel Koedijk | MVP Expert 2022 | ACEP | ACMP | ACCP | ACDP | Ekahau ECSE | Not an HPE Employee | Opinions are my own
    ------------------------------


  • 2.  RE: Aruba Central API Script with variables from a CSV file

    Posted Oct 25, 2022 06:26 PM
    This is great. Thanks.

    Also be aware of  this Aruba Central automation tool
    https://central.wifidownunder.com/settings.html
    online documentation
    https://central.wifidownunder.com/documentation.html



    ------------------------------
    Any opinions expressed here are solely my own and not necessarily that of Hewlett Packard Enterprise or Aruba.
    ------------------------------