Wired Intelligent Edge (Campus Switching and Routing)

Upcoming community maintenance Oct. 27th through Oct. 29th
For more info click here
Reply
Highlighted
Occasional Contributor II

Upgrade 6300 via REST API

Hi all,

 

I want to upgrade 6300 switches using the API in a python script. 

At the moment I always get the response error code 500 "Message Error processing the form."

My main question is: Is the image being sent binary in the post request or is only a download link being sent?

 

The API v10.04 documentation doesn't help:

https://support.hpe.com/hpesc/public/docDisplay?docLocale=en_US&docId=emr_na-a00091710en_us

 

The documentation on the switch is not very helpful either ( https://{switch_ip}/api/v10.04/ ), but it shows the, what I assume, correct content type 'multipart/form-data'.

 

here is my curent code, maybe someone can spot the problem quickly:

 

def upgrade(firmware: str, partition: str = 'primary', **session_dict):
        target_url = session_dict["url"] + "firmware?image={}".format(partition.lower())
        firmware = os.path.abspath(firmware)

        params = (
            ('image', 'secondary'),
        )

        files = {'file': open(firmware, 'rb')}

        headers = {
            'accept': '*/*',
            'Content-Type': 'multipart/form-data',
        }

        r = session_dict['s'].post(target_url, files=files, headers=headers, params=params, verify=False)

 

Thanks,

Bjarne

Highlighted
MVP Guru Elite

Re: Upgrade 6300 via REST API

Hi,

 

For me, it is URI



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: Upgrade 6300 via REST API

Hi, 

thanks for the reply and compliments to the great Powershell module!

 

I tried a lot in the URI format. 

 

From what I gathered, the firmware file should be binary:

{
file	[string($binary)]
}

 

But I can't get anything else than error 500 "Error processing the form."

 

I looked into your PowerShell files, but couldn't find a firmware post method. Have you had any experience with it?

Highlighted
MVP Guru Elite

Re: Upgrade 6300 via REST API

Thanks for my module,

 

I'm not yet try with firmware !



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
MVP Guru Elite

Re: Upgrade 6300 via REST API

on this doc https://support.hpe.com/hpesc/public/docDisplay?docLocale=en_US&docId=emr_na-a00091710en_us

 

there is an example with curl for upload a firmware and it is directly the file (using a form...) (-F)



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: Upgrade 6300 via REST API

I believe the documentation is outdated. it says 'Content-Type: application/json' but the switch api says "Content-Type: multipart/form-data"

 

I tried using your PS scripts and got to this:

 

Import-Module PowerArubaCX
$connection = Connect-ArubaCX 172.16.66.5 -SkipCertificateCheck

$Server = $connection.Server
$port = $connection.port
$headers = $connection.headers
$invokeParams = $connection.invokeParams
$sessionvariable = $connection.session
$fullurl ='https://172.16.66.5/rest/v10.04/firmware?image=secondary'

$upload = Invoke-RestMethod $fullurl -Method 'POST' -Headers $headers -InFile '.\ArubaOS-CX_6400-6300_10_04_0020.swi' -WebSession $sessionvariable @invokeParams

 

But I got error 401. 

Do I need to pass something more to use my authentication cookie?

 

I will try to set the timeout to 2h and look if that was the problem. Because the request takes some time (705MB fimrware file)

Highlighted
MVP Guru Elite

Re: Upgrade 6300 via REST API

You can use directly Invoke-ArubaCXRestMethod already include authentification stuff (and ip...) (but using v10.04 API call, you can use -noapiversion if you want to select the full URI



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: Upgrade 6300 via REST API

I couldn't use -InFile parameter with Invoke-ArubaCXRestMethod, to select the firmware file in the POST

 

Highlighted
MVP Guru Elite

Re: Upgrade 6300 via REST API

ugly hack... but you can add to $defaultArubaCXConnection.invokeParams...

 

You can also add issue on GitHub, and i will (later) for add this parameter



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