You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2013/01/05 02:23:35 UTC

[6/8] git commit: CLOUDSTACK-717: Fix response json handling in cloudmonkey

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 <bh...@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/api_refactoring
Commit: 9a66beb6589634ae4e0792706a332e447e6ba6dc
Parents: 569ca6d
Author: Rohit Yadav <bh...@apache.org>
Authored: Fri Jan 4 14:51:08 2013 -0800
Committer: Rohit Yadav <bh...@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)