MCPcopy Create free account
hub / github.com/apache/cloudstack / make_request

Function make_request

tools/ngui/requester.py:47–87  ·  view source on GitHub ↗
(command, args, logger, host, port,
                 apikey, secretkey, protocol, path)

Source from the content-addressed store, hash-verified

45
46
47def make_request(command, args, logger, host, port,
48 apikey, secretkey, protocol, path):
49 response = None
50 error = None
51
52 if protocol != 'http' and protocol != 'https':
53 error = "Protocol must be 'http' or 'https'"
54 return None, error
55
56 if args is None:
57 args = {}
58
59 args["command"] = command
60 args["apiKey"] = apikey
61 args["response"] = "json"
62 request = zip(args.keys(), args.values())
63 request.sort(key=lambda x: x[0].lower())
64
65 request_url = "&".join(["=".join([r[0], urllib.quote_plus(str(r[1]))])
66 for r in request])
67 hashStr = "&".join(["=".join([r[0].lower(),
68 str.lower(urllib.quote_plus(str(r[1]))).replace("+",
69 "%20")]) for r in request])
70
71 sig = urllib.quote_plus(base64.encodebytes(hmac.new(secretkey, hashStr,
72 hashlib.sha1).digest()).strip())
73 request_url += "&signature=%s" % sig
74 request_url = "%s://%s:%s%s?%s" % (protocol, host, port, path, request_url)
75
76 try:
77 logger_debug(logger, "Request sent: %s" % request_url)
78 connection = urllib2.urlopen(request_url)
79 response = connection.read()
80 except Exception, e:
81 error = str(e)
82
83 logger_debug(logger, "Response received: %s" % response)
84 if error is not None:
85 logger_debug(logger, error)
86
87 return response, error
88
89
90def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,

Callers 2

apicallFunction · 0.90
monkeyrequestFunction · 0.85

Calls 8

logger_debugFunction · 0.85
keysMethod · 0.80
replaceMethod · 0.80
sortMethod · 0.65
valuesMethod · 0.45
joinMethod · 0.45
digestMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected