incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [2/2] git commit: CLOUDSTACK-717: Fix response json handling in cloudmonkey
Date Fri, 04 Jan 2013 23:17:18 GMT
Updated Branches:
  refs/heads/master 569ca6d7a -> c7563cb7b


CLOUDSTACK-717: Fix response json handling in cloudmonkey

- Fixes response handling
- Sorts alphabetically, count and id are on top if available
- Fix colors

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>


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

Branch: refs/heads/master
Commit: 9a66beb6589634ae4e0792706a332e447e6ba6dc
Parents: 569ca6d
Author: Rohit Yadav <bhaisaab@apache.org>
Authored: Fri Jan 4 14:51:08 2013 -0800
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Fri Jan 4 15:17:06 2013 -0800

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cloudmonkey.py |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9a66beb6/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index edb62cc..e1fc63e 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -160,11 +160,11 @@ class CloudMonkeyShell(cmd.Cmd, object):
                     elif 'type' in arg:
                         print colored.green(arg),
                     elif 'state' in arg or 'count' in arg:
-                        print colored.yellow(arg),
+                        print colored.magenta(arg),
                     elif 'id =' in arg:
-                        print colored.cyan(arg),
+                        print colored.yellow(arg),
                     elif 'name =' in arg:
-                        print colored.magenta(arg),
+                        print colored.cyan(arg),
                     else:
                         print arg,
                 else:
@@ -203,7 +203,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
                 print printer
 
         def print_result_as_dict(result, result_filter=None):
-            for key in result.keys():
+            for key in sorted(result.keys(),
+                              key=lambda x: x!='id' and x!='count' and x):
                 if not (isinstance(result[key], list) or
                         isinstance(result[key], dict)):
                     self.print_shell("%s = %s" % (key, result[key]))
@@ -268,7 +269,11 @@ class CloudMonkeyShell(cmd.Cmd, object):
             while timeout > 0:
                 response = process_json(conn.make_request_with_auth(command,
                                                                     requests))
-                result = response[response.keys()[0]]
+                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"]
@@ -346,9 +351,9 @@ class CloudMonkeyShell(cmd.Cmd, object):
         if result is None:
             return
         try:
-            # Response is in the key "apiname+response" (lowercase)
-            self.print_result(result[api_name.lower() + 'response'],
-                              field_filter)
+            responsekeys = filter(lambda x: 'response' in x, result.keys())
+            for responsekey in responsekeys:
+                self.print_result(result[responsekey], field_filter)
             print
         except Exception as e:
             self.print_shell("🙈  Error on parsing and printing", e)


Mime
View raw message