Wired Intelligent Edge

 View Only
  • 1.  Upgrade 6300 via REST API

    Posted Mar 12, 2020 12:38 PM

    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



  • 2.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 04:08 AM

    Hi,

     

    For me, it is URI



  • 3.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 07:55 AM

    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?



  • 4.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 09:30 AM

    Thanks for my module,

     

    I'm not yet try with firmware !



  • 5.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 09:34 AM

    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)



  • 6.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 10:59 AM

    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)



  • 7.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 11:03 AM

    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



  • 8.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 11:14 AM

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

     



  • 9.  RE: Upgrade 6300 via REST API

    Posted Mar 13, 2020 11:18 AM

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

     

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



  • 10.  RE: Upgrade 6300 via REST API

    Posted Sep 27, 2023 10:42 AM

    Hi bkohnke,

    were you successful at the end? I´m trying to get the same done and got a '502 Bad Gateway' back.

    Thanks

    Martin



    ------------------------------
    Regards
    Martin
    ------------------------------