1 Reply Latest reply: Oct 10, 2016 11:37 AM by Wenxuan Guo RSS

Shark update REST API

Rossel Vermette

Hey,

 

I'm looking to script an updgrade for our sharks/vsharks,  but I'm having issues with the "file upload".  Here is what my current script looks like:

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
# Description: Scriypt to update Riverbed Sharks via REST APO
import pycurl, argparse, cStringIO, json, pprint, re, sys
from urllib import urlencode

parser = argparse.ArgumentParser(description='Parameter options')
parser.add_argument('-u','--username',help="username",required=True)
parser.add_argument('-p','--password',help="password",required=True)
rargs = parser.parse_args()

METHODE = 'https://'
URL1='/api/shark/5.1/system/update/iso'
DOMNAME = 'localdomain.name'
SHARKLIST = ['shark1']
def POSTSystemUpdateISO(URL):
        c = pycurl.Curl()
        c.setopt(pycurl.URL, METHODE+SHARK+DOMNAME+URL)
        c.setopt(pycurl.SSL_VERIFYPEER, 0)
        c.setopt(pycurl.SSL_VERIFYHOST, 0)
        c.setopt(pycurl.SSL_VERIFYHOST, 0)
        c.setopt(pycurl.HTTPHEADER, ['Content-Disposition: form-data; name="iso_file"; filename="rbt_csk_update-10.9.2a-2d41.iso"'])
        c.setopt(pycurl.VERBOSE, True)
        c.setopt(pycurl.USERPWD, rargs.username+':'+rargs.password)
        c.setopt(pycurl.HTTPPOST, [("iso_file", (pycurl.FORM_FILE, "rbt_csk_update-10.9.2a-2d41.iso"))])
        c.perform()
        c.close()
for SHARK in SHARKLIST:
        POSTSystemUpdateISO(URL1)



 

Here is the results:

> POST /api/shark/5.1/system/update/iso HTTP/1.1

Authorization: Basic XXXXXXXXXXXXXXX

User-Agent: PycURL/7.22.0

Host: shark1.localdomain.name

Accept: */*

Content-Disposition: form-data; name="iso_file"; filename="rbt_csk_update-10.9.2a-2d41.iso"

Content-Length: 211964131

Expect: 100-continue

Content-Type: multipart/form-data; boundary=----------------------------a057c49c3ccf

 

< HTTP/1.1 100 Continue

< HTTP/1.1 200 OK

< Cache-control: no-cache

< Connection: Keep-Alive

< Content-Length: 20

< Content-Type: text/plain

< Date: Tue, 04 Oct 2016 13:59:57 GMT

< ETag: 49bb50d16c23f0b1696011843fddf6e3

< Pragma: no-cache

<

{

        "message": "OK"

* Connection #0 to host shark1.localdomain.name left intact

* Closing connection

 

Based on the message, it looks like the file is uploaded successfully, but I don't see the status change on the shark itself?  Is there another REST API I need to run to trigger the update, or is there something wrong with the request because the message returned in the body has "message":ok?

 

Thanks,

 

Rossel

  • Re: Shark update REST API
    Wenxuan Guo

    I would suggest leveraging SteelScript.Netshark package for your task. below is the link about installation.

    http://https://support.riverbed.com/apis/steelscript/install/toc.html

     

    Once installed, you can use the below code to upload files and check the available files on the shark.

     

    #! /usr/bin/env python
    import pprint
    from steelscript.netshark.core.netshark import NetShark
    from steelscript.common.service import UserAuth
    
    auth = UserAuth('<username>', '<password>')
    shark = NetShark('<hostname>', auth=auth)
    
    # Upload the file
    shark.upload_trace_file(local_file='<absolute_file_path>', path='<username>/<base_file_name>')
    
    # Print out the uploaded files
    pprint.pprint(shark.get_files(force_refetch=True))
    
    

     

    Hopefully it helps.