Wired Intelligent Edge (Campus Switching and Routing)

Reply
Highlighted
Occasional Contributor II

AOS-S REST API - Delete VLAN & File-Transfer

Hello everyone,

 

I recently started playing around with the rather newer REST API of the ArubaOS-Switch devices. It is the first time for me programming in python, but thanks to the French How-To-Guides from Aruba Employee  and Google Translate, I was able to get a basic setup running.

However I've encountered two problems so far, that unfortunately I cannot solve by myself.

 

1. On the factory-default configuration without a username and password, I'm able to create a specific VLAN on the Switch without generating a cookie.

But I'm not able to delete that VLAN. Is that an intended behavior?

url = "http://192.168.1.10/rest/v1/vlans"
delete_vlan = requests.delete(url, data=json.dumps({"vlan_id": 10}))

2. I was unable to get the file-transfer working. As far as I understood that function, I should be able to upload a firmware to the switch. The primary file transfer method in the past was TFTP, so I assumed that one.

 

url = "http://192.168.1.10/rest/v2/file-transfer"
fw = {
"file_type": "FTT_FIRMWARE",
"action": "FTA_DOWNLOAD",
"url": "<path to TFTP>",
"boot_image": "BI_PRIMARY_IMAGE"
}
firmware_update = requests.post(url, data=json.dumps(fw))

 I appreciate any help or further reading material.


Accepted Solutions
Highlighted

Re: AOS-S REST API - Delete VLAN & File-Transfer

Hi AirMart,

 

Please see comments below :

 

1. When you want to delete a VLAN, you need to specify its ID in the URI. So in your case, you need to use the following code :

 

url = "http://192.168.1.10/rest/v1/vlans/10"
delete_vlan = requests.delete(url)

2. FileTransfer URI only uses HTTP/HTTPS remote server. So your binary needs to be hosted on a Web Server, and the URL key will have to be the complete URL to your file (ex : "http://192.168.1.1/depot/WC_16_06_0006.swi") :

 

View solution in original post


All Replies
Highlighted

Re: AOS-S REST API - Delete VLAN & File-Transfer

Hi AirMart,

 

Please see comments below :

 

1. When you want to delete a VLAN, you need to specify its ID in the URI. So in your case, you need to use the following code :

 

url = "http://192.168.1.10/rest/v1/vlans/10"
delete_vlan = requests.delete(url)

2. FileTransfer URI only uses HTTP/HTTPS remote server. So your binary needs to be hosted on a Web Server, and the URL key will have to be the complete URL to your file (ex : "http://192.168.1.1/depot/WC_16_06_0006.swi") :

 

View solution in original post

Highlighted
Occasional Contributor II

Re: AOS-S REST API - Delete VLAN & File-Transfer

Thank you very much for your answer, the delete VLAN function is now working fine. I just wasn't aware that the id needs to be placed in the URI. But for the file-transfer, the switch is still returning Code 404. So it seems that the switch cannot find the resource.

 

Switch shows these lines in the debug console:

rest RestSrv-2:Method = POST, URI = /rest/v2/file-transfer
rest RestSrv-2:status = 404, reason = Not Found

 

EDIT: Found the problem. Seems that my first testing switch an 2620 is just not having the file-transfer resource. I switched to an 2540 and now it's working.

Highlighted

Re: AOS-S REST API - Delete VLAN & File-Transfer

Great - Thanks for the update.

 

Enjoy your automation journey :-)

Highlighted
MVP Guru Elite

Re: AOS-S REST API - Delete VLAN & File-Transfer


@AirMart wrote:

 

Switch shows these lines in the debug console:

rest RestSrv-2:Method = POST, URI = /rest/v2/file-transfer
rest RestSrv-2:status = 404, reason = Not Found

 

 


Need API v3 for file-transfer ? (



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

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

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

PowerArubaIAP: Powershell Module to use Aruba Instant AP

PowerArubaMC: Powershell Module to use Mobility Controller / Master


ACMP 6.4 / ACMX #107 / ACCP 6.5 / ACSP
Highlighted
Occasional Contributor II

Re: AOS-S REST API - Delete VLAN & File-Transfer

In a way you are correct. After further testing it appers to me that "v2/file-transfer" works only since 16.04, although it has been documented since 16.02.

Is there any explanation for that?

Highlighted

Re: AOS-S REST API - Delete VLAN & File-Transfer

Hi AirMart,

 

Actually, the File-Transfer appeared in 16.02, but only with only 1 supported type of transfer - This API has been enhanced in 16.03, especially in order to support more transfer types.

In the REST API and JSON schema in 16.02, in "device-rest-api -> schema -> common -> FileTransferType.json", you'll get this : 

{
"$schema":"http://json-schema.org/draft-04/schema#",
"description":"File types to transfer (FTT_)",
"title": "FileTransferType",
"enum":
[
"FTT_FIRMWARE"
]
}

So the only supported type is FTT_FIRMWARE.

 

For the same FileTransferType,json file, but in 16.03, you'll get this :

{
"$schema":"http://json-schema.org/draft-04/schema#",
"description":"File types to transfer (FTT_)",
"title": "FileTransferType",
"enum":
[
"FTT_CONFIG",
"FTT_FIRMWARE",
"FTT_EVENT_LOGS",
"FTT_CRASH_FILES",
"FTT_SYSTEM_INFO",
"FTT_SHOW_TECH",
"FTT_DEBUG_LOGS"
]
}

So 16.03 brought the support of config/event_logs/crash_files/system_info/show_tech/debug_logs file transfers.

 

Hoping that helps.

Highlighted
Occasional Contributor II

Re: AOS-S REST API - Delete VLAN & File-Transfer

This is perfecly clear. But my problem is that my code is perfectly working with 16.04 but with 16.02 the response of the switch is always 404.

 

My Code:

fw = {
    "file_type": "FTT_FIRMWARE",
    "action": "FTA_DOWNLOAD",
    "url": "http://192.168.1.1/YA_16_02_0014.swi",
    "boot_image": "BI_PRIMARY_IMAGE"
    }
firmware_update = requests.post(http://192.168.1.10/rest/v2/file-transfer", data=json.dumps(fw))
print(firmware_update.json())

Highlighted

Re: AOS-S REST API - Delete VLAN & File-Transfer

OK, I didn't understand that you we're working on the Firmware side.

Which version of 16.02 are you using ?

 

Highlighted
Occasional Contributor II

Re: AOS-S REST API - Delete VLAN & File-Transfer

Perhaps I wasn't clear regarding this. I'm using YA.16.02.0014 at the moment.

 

Edit: Same result with YA.16.02.0025

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: