From c7563cb7bd5f813332cfe7bbdf96bc235d56c1ff Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 4 Jan 2013 15:15:21 -0800 Subject: [PATCH] cli: Show progress during polling for async jobs If asyncblock is set to true, prints dots as polling requests are made. When result is obtained, dots are wiped and result is printed. Signed-off-by: Rohit Yadav --- tools/cli/cloudmonkey/cloudmonkey.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index e1fc63eeb83..3bc87169f63 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -266,7 +266,11 @@ class CloudMonkeyShell(cmd.Cmd, object): command = "queryAsyncJobResult" requests = {'jobid': jobId} timeout = int(self.timeout) + pollperiod = 3 while timeout > 0: + progress = int((int(self.timeout) - timeout) / pollperiod ) + 1 + print '\r' + '.' * progress, + sys.stdout.flush() response = process_json(conn.make_request_with_auth(command, requests)) responsekeys = filter(lambda x: 'response' in x, @@ -282,9 +286,10 @@ class CloudMonkeyShell(cmd.Cmd, object): jobresult["errortext"]) return elif jobstatus == 1: + print '\r', return response - time.sleep(4) - timeout = timeout - 4 + time.sleep(pollperiod) + timeout = timeout - pollperiod logger.debug("job: %s to timeout in %ds" % (jobId, timeout)) self.print_shell("Error:", "Async query timeout for jobid=", jobId)