Developer

 View Only
last person joined: an hour ago 

Expand all | Collapse all

Delete vlan and change vlan name on switch with REST API

This thread has been viewed 62 times
  • 1.  Delete vlan and change vlan name on switch with REST API

    Posted Sep 19, 2023 11:18 AM

    Hi all!

    I'm trying to use the REST API to delete a VLAN on a HP aruba switch.

    but when I try to delete a vlan I get HTTP Error 405 – Method Not Allowed

    I tried like this DELETE.../vlans/{Vlan.vlan_id}  eg. DELETE restApi/rest/v1/vlans/4

    Do anyone know what is the correct way? 

    And does anyone know if it's possible to change the name of a vlan with REST API?

    I can retrieve vlans with http://restApi/rest/v1/vlans

    Retrive vlans-ports with http://rest/v1/vlans-ports

    Assign port to vlan:

    String^ payLoad = "{\"vlan_id\":" + device->vlanInfo->vlan_id + ",\"port_id\":" + "\"" + device->connected_port + "\"" + ",\"port_mode\":" + "\"" + portMode + "\"" + "}";

    web->POST(vlanPortsPath, payLoad);

    Thanks!



  • 2.  RE: Delete vlan and change vlan name on switch with REST API

    MVP GURU
    Posted Sep 19, 2023 11:23 AM

    Hi,

    What switch model and firmware release ?



    ------------------------------
    PowerArubaSW : Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP...

    PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...)

    PowerArubaCL: Powershell Module to use Aruba Central

    PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)..

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 3.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 19, 2023 11:41 AM

    HP Model:  HP2530-24 Switch(J9782A)

    Firmware: YB.16.10.0002




  • 4.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 19, 2023 05:45 PM

    @scmalcom is the VLAN associated with any ports or interfaces?



    ------------------------------
    Ti Chiapuzio-Wong (they/them)
    HPE Aruba Networking
    ------------------------------



  • 5.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 19, 2023 05:55 PM

    @scmalcom also to change the name of a VLAN that already exists you'll want to use the PUT method



    ------------------------------
    Ti Chiapuzio-Wong (they/them)
    HPE Aruba Networking
    ------------------------------



  • 6.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 20, 2023 03:11 AM

    I tried with PUT method, but I get web error Method Not Allowed, this is my code:

    bool _Switch::updateVlanName(VlanData^ vlan) {
    	loginSwitch();
    	web->disableKeepAlive = true;
    	String^ payLoad = "{\"vlan_id\":" + vlan->vlan_id + ",\"name\":" + "\"" + vlan->name + "\"" + "}";
    	web->PUT(vlanPath, payLoad);
    
    	if (web->ErrorLevel == web_client::ErrorStatus::Created) {
    		log->write("VLAN name changed successfully", LogType::Success);
    		logoutSwitch();
    		return true;
    	}
    	log->write("Error changing name on VLAN: " + vlan->name + ", status: " + Convert::ToString(web->StatusCode), LogType::Error);
    	return false;
    }




  • 7.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 20, 2023 04:11 AM

    When I now try to delete a vlan with REST API, I get http error status OK, but it doesn't actually delete the VLAN, the vlan is still on the switch and there are no ports associated to the vlan.
    This is my code: 

    bool _Switch::deleteVlan(VlanData^ vlan) {
    	loginSwitch();
    	web->disableKeepAlive = true;
    	String^ deleteUrl = "http://" + selectedSwitch->switch_hostName + "/rest/v1/vlans/" + vlan->vlan_id;
    	web->DELETE(deleteUrl, nullptr);
    
    	if (web->ErrorLevel == web_client::ErrorStatus::OK) {
    		log->write("VLAN deleted successfully", LogType::Success);
    		logoutSwitch();
    		return true;
    	}
            logoutSwitch();
    	log->write("Error deleting VLAN id: " + vlan->vlan_id + " name: " + vlan->name + ", status: " + Convert::ToString(web->StatusCode), LogType::Error);
    	return false;
    }




  • 8.  RE: Delete vlan and change vlan name on switch with REST API

    MVP GURU
    Posted Sep 20, 2023 02:35 PM

    May be better to use v8 API (if you are using 16.10 firmware...)

    you can try to look the debug (debug rest interface if remember)

    on your LoginSwitch() function, you store the cookie needed for call API ?



    ------------------------------
    PowerArubaSW : Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP...

    PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...)

    PowerArubaCL: Powershell Module to use Aruba Central

    PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)..

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 9.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 20, 2023 02:46 PM

    Yes, I save the cookie in web class after login and then I use it to call other api calls and logout.

    I'm able to add new vlan, assign port to vlan, get vlans, get Mac-addresses, get ports and system info with the rest API, but not changing name on vlan or deleting a vlan.

    Do you have a link to docs for v8 API?

    Thanks in advance😊 




  • 10.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 20, 2023 05:37 PM

    @scmalcom what URL are you using for the PUT method to update? you can find the REST API documentation on our Aruba Support Portal : https://asp.arubanetworks.com/downloads/documents/RmlsZToxYjRkNTM2OC1mNGZiLTExZTktYjQ4Zi01M2MzNDFiNjZkNmQ%3D



    ------------------------------
    Ti Chiapuzio-Wong (they/them)
    HPE Aruba Networking
    ------------------------------



  • 11.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 20, 2023 06:04 PM

    Hi Tiffany! 

    For the PUT method I'm using:

    http://switchIp/rest/v1/vlans

    Eg.

    http://10.200.0.20/rest/v1/vlans




  • 12.  RE: Delete vlan and change vlan name on switch with REST API

    Posted Sep 21, 2023 03:18 PM

    For delete you need to use the URL : 

    .../vlans/{Vlan.vlan_id}


    ------------------------------
    Ti Chiapuzio-Wong (they/them)
    HPE Aruba Networking
    ------------------------------



  • 13.  RE: Delete vlan and change vlan name on switch with REST API

    MVP GURU
    Posted Sep 21, 2023 08:40 AM

    you can only this doc

    https://asp.arubanetworks.com/downloads/software/RmlsZTpiNmIwZDM1YS05OWFlLTExZTktODk5MS1kZmIzMTNkZWE5N2I%3D

    for vlan and other, it is the same like v1 (but need to use v7 or v8...) 



    ------------------------------
    PowerArubaSW : Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP...

    PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...)

    PowerArubaCL: Powershell Module to use Aruba Central

    PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)..

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------