cli: Fix asyncblock to search for correct key instead of hardcoded index

Signed-off-by: Rohit Yadav <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/50347461
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/50347461
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/50347461

Branch: refs/heads/marvin-refactor
Commit: 50347461c149b5b9409913fcd652d71dfab0a8f3
Parents: 57d463c
Author: Rohit Yadav <[email protected]>
Authored: Wed Jan 23 14:12:38 2013 -0800
Committer: Prasanna Santhanam <[email protected]>
Committed: Sat Mar 30 22:22:39 2013 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cloudmonkey.py |   38 +++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/50347461/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py 
b/tools/cli/cloudmonkey/cloudmonkey.py
index 94006c9..ba874ae 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -225,8 +225,42 @@ class CloudMonkeyShell(cmd.Cmd, object):
         if self.pipe_runner(args):
             return
 
-        apiname = args.partition(' ')[0]
-        verb, subject = splitverbsubject(apiname)
+        isAsync = isAsync and (self.asyncblock == "true")
+        responsekey = filter(lambda x: 'response' in x, response.keys())[0]
+        if isAsync and 'jobid' in response[responsekey]:
+            jobId = response[responsekey]['jobid']
+            command = "queryAsyncJobResult"
+            requests = {'jobid': jobId}
+            timeout = int(self.timeout)
+            pollperiod = 3
+            progress = 1
+            while timeout > 0:
+                print '\r' + '.' * progress,
+                sys.stdout.flush()
+                response = process_json(conn.make_request_with_auth(command,
+                                                                    requests))
+                responsekeys = filter(lambda x: 'response' in x,
+                                      response.keys())
+                if len(responsekeys) < 1:
+                    continue
+                result = response[responsekeys[0]]
+                jobstatus = result['jobstatus']
+                if jobstatus == 2:
+                    jobresult = result["jobresult"]
+                    self.print_shell("\rAsync query failed for jobid",
+                                     jobId, "\nError", jobresult["errorcode"],
+                                     jobresult["errortext"])
+                    return
+                elif jobstatus == 1:
+                    print '\r',
+                    return response
+                time.sleep(pollperiod)
+                timeout = timeout - pollperiod
+                progress += 1
+                logger.debug("job: %s to timeout in %ds" % (jobId, timeout))
+            self.print_shell("Error:", "Async query timeout for jobid", jobId)
+
+        return response
 
         lexp = shlex.shlex(args.strip())
         lexp.whitespace = " "

Reply via email to