0

I'm want to make a CloudStack API call 'uploadVolume' as described in here.

I'm using python and my code works for all others API calls, excepted uploadVolume.

secretkey = 'EdKz8Po3zmFWacumfxirauUBPVcLEWKq0qRox1iqhzAsrmLnJaEJxL2IsyDfyPE2Oh5AODJG3ZGKZf6A08xQAw'
apikey = 'YIShhcJ1PaGF5awJlci46qyAqhEN8WYdtUodHAT2wp7-zpN21_fJpcy1POTiMXOlFH-f-rO3zAs3tYRGcFqxwg'

request['command']='uploadVolume'
request['format']='QCOW2'
request['name']='test'
request['url']='http://192.168.122.100/image.qcow2'
request['zoneid']='959416fc-71f0-461c-99f0-28449e098036'
request['response']='json'
request['apikey']= apikey

baseurl='http://192.168.122.250:8080/client/api?'

request_str='&'.join(['='.join([k,urllib.quote_plus(request[k])]) for k in request.keys()])
sig_str='&'.join(['='.join([k.lower(),urllib.quote_plus(request[k].lower().replace('+','%20'))])for k in sorted(request.iterkeys())])
sig=urllib.quote_plus(base64.encodestring(hmac.new(secretkey,sig_str,hashlib.sha1).digest()).strip())

url=baseurl+request_str+'&signature='+sig

The generated URL looks like this:

http://192.168.122.250:8080/client/api?apikey=YIShhcJ1PaGF5awJlci46qyAqhEN8WYdtUodHAT2wp7-zpN21_fJpcy1POTiMXOlFH-f-rO3zAs3tYRGcFqxwg&name=test&format=QCOW2&url=http%3A%2F%2F192.168.122.100%2Fimage.qcow2&zoneid=959416fc-71f0-461c-99f0-28449e098036&command=uploadVolume&response=json&signature=EKhoEWKIG3QcmFM9k6sVRruZvFs%3D

Response indicates that there is a signature problem:

{"uploadvolumeresponse":{"uuidList":[],"errorcode":401,"errortext":"unable to verify user credentials and/or request signature"}}

After some tests, I have identified that the signature error occurs because of the url parameter. If I replace the url with any string in this parameter the signature is done correctly, but (obviously) the command fails (since CloudStack will not find the image).

I think the problem is in the special characters that make up the url, but I'm not sure.

Does anyone have any idea how to solve this?

Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67

0 Answers0