forked from fromcloud/python_api_sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral_request.py
More file actions
executable file
·47 lines (40 loc) · 1.31 KB
/
Copy pathgeneral_request.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
import sys
sys.path.insert(0, "../config/")
import urllib2
import urllib
import hashlib
import hmac
import base64
import urlparse
import linecache
import url_config
import user_config
def get_sig_request(request, secretkey, baseurl):
request_str='&'.join(['='.join([k,urllib.quote_plus(request[k])]) for k in request.keys()])
print request_str
sig_str='&'.join(['='.join([k.lower(),urllib.quote_plus(request[k]).replace('+','%20').lower()])for k in sorted(request.iterkeys())])
print sig_str
sig=urllib.quote_plus(base64.encodestring(hmac.new(secretkey,sig_str,hashlib.sha1).digest()).strip())
print sig
return baseurl+request_str+'&signature='+sig
baseurl = url_config.server_url
apikey = user_config.apikey
secretkey = user_config.secretkey
if apikey:
expirationtime = datetime.utcnow() + timedelta(seconds=int(600))
request={}
request['command']='listVirtualMachines'
request['state']='Running'
request['expires']=expirationtime.strftime('%Y-%m-%dT%H:%M:%S+0900')
request['response']='xml'
request['apikey']=apikey
request['signatureVersion']='3'
print "request dictionary = %s \n" % request
req_url=get_sig_request(request, secretkey, baseurl)
print "Request URL = %s\n" % req_url
#res=urllib2.urlopen(req_url)
#print res.read()
#res.close()
else:
print "apikey none"