Repository: cloudstack-cloudmonkey Updated Branches: refs/heads/master 0ae940815 -> ad69d2b9b
cloudmonkey: have filter applicable for list outputs as well If filter is used for list output (default output) now, it filters out keys based on the filter passed. If only one filter is applied say 'id', then only the values are printed. For example; $ cloudmonkey list domains filter=id 111b3bf9-4234-11e4-be95-00012e4ff7d0 In the above example, only UUIDs are printed. This can be useful for people to just grab uuids and do interesting things with it. Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com> Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/ad69d2b9 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/ad69d2b9 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/ad69d2b9 Branch: refs/heads/master Commit: ad69d2b9b4d8bf022d62c12d7d79c0035dc8752e Parents: 0ae9408 Author: Rohit Yadav <rohit.ya...@shapeblue.com> Authored: Fri Oct 3 14:51:14 2014 +0200 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Fri Oct 3 14:51:30 2014 +0200 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/ad69d2b9/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index 2d88786..bb01247 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -247,8 +247,16 @@ class CloudMonkeyShell(cmd.Cmd, object): x not in ['id', 'count', 'name'] and x): if not (isinstance(result[key], list) or isinstance(result[key], dict)): - self.monkeyprint("%s = %s" % (key, result[key])) + if result_filter != None and key not in result_filter: + continue + if result_filter != None and len(result_filter) == 1: + self.monkeyprint(result[key]) + else: + self.monkeyprint("%s = %s" % (key, result[key])) else: + if result_filter != None and key not in result_filter: + self.print_result(result[key], result_filter) + continue self.monkeyprint(key + ":") self.print_result(result[key], result_filter) @@ -257,7 +265,7 @@ class CloudMonkeyShell(cmd.Cmd, object): if isinstance(node, dict) and self.display == 'table': print_result_tabular(result, result_filter) break - self.print_result(node) + self.print_result(node, result_filter) if len(result) > 1: self.monkeyprint(self.ruler * 80) @@ -298,7 +306,7 @@ class CloudMonkeyShell(cmd.Cmd, object): args.append(next_val.replace('\x00', '')) args_dict = dict(map(lambda x: [x.partition("=")[0], - urllib.quote(x.partition("=")[2])], + x.partition("=")[2]], args[1:])[x] for x in range(len(args) - 1)) field_filter = None if 'filter' in args_dict: @@ -320,6 +328,9 @@ class CloudMonkeyShell(cmd.Cmd, object): if 'asyncapis' in self.apicache: isasync = apiname in self.apicache['asyncapis'] + for key in args_dict.keys(): + args_dict[key] = urllib.quote(args_dict[key]) + result = self.make_request(apiname, args_dict, isasync) if result is None: @@ -377,8 +388,7 @@ class CloudMonkeyShell(cmd.Cmd, object): autocompletions = uuids search_string = value - if subject != "" and (self.display == "table" or - self.display == "json"): + if subject != "": autocompletions.append("filter=") return [s for s in autocompletions if s.startswith(search_string)]