Developer

 View Only
  • 1.  Automatic Port Naming using Aruba Central API

    Posted Oct 16, 2024 06:03 AM

    Hi,

    I am trying to automate naming ports on our 6100's using the Aruba Central API using the LLDP information available to each switch.  I keep getting 500 error codes when trying to PUT the information back up to the API.  I've been frustrated by this for some time, so if someone has an idea of what is going wrong, it would be greatly appreciated.  I am using python and the pycentral SDK.  I've not had any issues with any of the code prior to the PUT.

    import json
    import pycentral
    import pycentral.base
    import pprint
    
    
    central_info = {
        "base_url": "https://apigw-uswest5.central.arubanetworks.com/",
        "client_id": "",
        "client_secret": "",
        "customer_id": "",
        "token": {
            "refresh_token": "",
            "token_type": "bearer",
            "access_token": "",
            "expires_in": 7200
            }
    }
    
    
    ArubaBase = pycentral.base.ArubaCentralBase(central_info=central_info, ssl_verify=True)
    switches_response = ArubaBase.command("GET", "/monitoring/v1/switches")
    
    pprint.pprint(switches_response)
    for switch in switches_response["msg"]["switches"]:
        print(switch["name"] + " " + switch["ip_address"] + " " + switch["serial"])
        lldp_info = ArubaBase.command("GET", f"/monitoring/v1/cx_switches/{switch['serial']}/neighbors")
        pprint.pprint(lldp_info)
        ports = {}
        for list_item_dict in lldp_info["msg"]["data"]:
            print(list_item_dict["dn"]["name"])
            print(list_item_dict["dn"]["port"])
            ports[list_item_dict["dn"]["port"]] = list_item_dict["dn"]["name"]
        formatted_data = {
            "ports": [
                {"port_id": port.lstrip("1/1/"), "name": name} # not sure if the "1/1/" should be stripped or not
                for port, name in ports.items()
            ]
        }
        device_serial = {"device_serial": switch['serial']}
        
        print(device_serial)
        print(formatted_data)
        
        port_data = json.dumps(formatted_data)
    
        print(port_data)
        
        response = ArubaBase.command(
            "PUT",
            f"/configuration/v1/aos_switch/ports/devices/{switch['serial']}",
            apiData=port_data
        )
    
        pprint.pprint(response)
    


  • 2.  RE: Automatic Port Naming using Aruba Central API

    Posted Oct 16, 2024 07:37 AM

    Error code 500 is server side errors. Usually it means that json you are providing has wrong format.

    Try your json string with swagger interface. 

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2024
    ------------------------------



  • 3.  RE: Automatic Port Naming using Aruba Central API

    Posted Oct 16, 2024 08:38 AM
    Edited by GorazdKikelj Oct 16, 2024 08:39 AM

    I believe that the problem lies in the fact, that this API is for ArubaOS-S and not for ArubaOS-CX switches. Naming convention for ports is different. 

    I test it with AOS switch and it is working as expected. When I try with AOS-CX, it return 500 error like data is not in correct json format.

    So as for now no luck with AOS-CX via Central API :-(

    You can use template group for this for now, but not ideal solution. Hopefully CX support will be added in the future upgrades. 

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2024
    ------------------------------



  • 4.  RE: Automatic Port Naming using Aruba Central API

    Posted Oct 16, 2024 11:44 AM

    I appreciate you taking a look at it.  That is truly unfortunate if that is the case.  What is the best way to request that as a feature, since our organization is moving towards primarily all CX switches?




  • 5.  RE: Automatic Port Naming using Aruba Central API

    Posted Oct 16, 2024 01:12 PM

    Hi John.

    As with all enhancement requests the best way is to put a new feature request into Innovatoon zone where we can vote for it. 

    I'm sure cx support is coming but have no info about it. Currently there is a huge work going on on unified REST API interface to conform to GreenLake standard. 

    What I didn't have a time to check is if API for CX is available in new Central.

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2024
    ------------------------------