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

Function monkeyrequest

tools/ngui/requester.py:90–153  ·  view source on GitHub ↗
(command, args, isasync, asyncblock, logger, host, port,
                  apikey, secretkey, timeout, protocol, path)

Source from the content-addressed store, hash-verified

88
89
90def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
91 apikey, secretkey, timeout, protocol, path):
92
93 response = None
94 error = None
95 logger_debug(logger, "======== START Request ========")
96 logger_debug(logger, "Requesting command=%s, args=%s" % (command, args))
97 response, error = make_request(command, args, logger, host, port,
98 apikey, secretkey, protocol, path)
99 logger_debug(logger, "======== END Request ========\n")
100
101 if error is not None:
102 return response, error
103
104 def process_json(response):
105 try:
106 response = json.loads(str(response))
107 except ValueError, e:
108 error = "Error processing json response, %s" % e
109 logger_debug(logger, "Error processing json", e)
110 return response
111
112 response = process_json(response)
113 if response is None:
114 return response, error
115
116 isasync = isasync and (asyncblock == "true")
117 responsekey = filter(lambda x: 'response' in x, response.keys())[0]
118
119 if isasync and 'jobid' in response[responsekey]:
120 jobid = response[responsekey]['jobid']
121 command = "queryAsyncJobResult"
122 request = {'jobid': jobid}
123 timeout = int(timeout)
124 pollperiod = 3
125 progress = 1
126 while timeout > 0:
127 print '\r' + '.' * progress,
128 time.sleep(pollperiod)
129 timeout = timeout - pollperiod
130 progress += 1
131 logger_debug(logger, "Job %s to timeout in %ds" % (jobid, timeout))
132 sys.stdout.flush()
133 response, error = monkeyrequest(command, request, isasync,
134 asyncblock, logger,
135 host, port, apikey, secretkey,
136 timeout, protocol, path)
137 response = process_json(response)
138 responsekeys = filter(lambda x: 'response' in x, response.keys())
139 if len(responsekeys) < 1:
140 continue
141 result = response[responsekeys[0]]
142 jobstatus = result['jobstatus']
143 if jobstatus == 2:
144 jobresult = result["jobresult"]
145 error = "\rAsync job %s failed\nError %s, %s" % (jobid,
146 jobresult["errorcode"], jobresult["errortext"])
147 return response, error

Callers

nothing calls this directly

Calls 8

logger_debugFunction · 0.85
make_requestFunction · 0.85
process_jsonFunction · 0.85
filterFunction · 0.85
intFunction · 0.85
keysMethod · 0.80
sleepMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected