You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/02/07 21:04:12 UTC

[42/51] [abbrv] git commit: refs/heads/ui-plugins - CLOUDSTACK-1037: Implement fuzzy parameter completion

CLOUDSTACK-1037: Implement fuzzy parameter completion

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/1fd05631
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1fd05631
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1fd05631

Branch: refs/heads/ui-plugins
Commit: 1fd0563137075a8b405bdd5f17d0b821442c4f58
Parents: bf1b40e
Author: Rohit Yadav <bh...@apache.org>
Authored: Thu Feb 7 16:00:22 2013 +0530
Committer: Rohit Yadav <bh...@apache.org>
Committed: Thu Feb 7 16:01:05 2013 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/cachemaker.py  |    4 +-
 tools/cli/cloudmonkey/cloudmonkey.py |   36 +++++++++++++++++++++++-----
 tools/cli/cloudmonkey/config.py      |    3 +-
 3 files changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1fd05631/tools/cli/cloudmonkey/cachemaker.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cachemaker.py b/tools/cli/cloudmonkey/cachemaker.py
index 8827f29..42a077a 100644
--- a/tools/cli/cloudmonkey/cachemaker.py
+++ b/tools/cli/cloudmonkey/cachemaker.py
@@ -56,8 +56,8 @@ def savecache(apicache, json_file):
     """
     Saves apicache dictionary as json_file, returns dictionary as indented str
     """
-    if isinstance(type(apicache), types.NoneType) or apicache is None or apicache is {}:
-      return ""
+    if apicache is None or apicache is {}:
+        return ""
     apicachestr = json.dumps(apicache, indent=2)
     with open(json_file, 'w') as cache_file:
         cache_file.write(apicachestr)

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1fd05631/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index 53f73bd..b5b185f 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -246,13 +246,13 @@ class CloudMonkeyShell(cmd.Cmd, object):
                                   map(lambda x: x.strip(),
                                       args_dict.pop('filter').split(',')))
 
-        missing_args = []
+        missing = []
         if verb in self.apicache and subject in self.apicache[verb]:
-            missing_args = filter(lambda x: x not in args_dict.keys(),
-                           self.apicache[verb][subject]['requiredparams'])
+            missing = filter(lambda x: x not in args_dict.keys(),
+                             self.apicache[verb][subject]['requiredparams'])
 
-        if len(missing_args) > 0:
-            self.monkeyprint("Missing arguments: ", ' '.join(missing_args))
+        if len(missing) > 0:
+            self.monkeyprint("Missing arguments: ", ' '.join(missing))
             return
 
         isasync = False
@@ -293,12 +293,33 @@ class CloudMonkeyShell(cmd.Cmd, object):
                                   map(lambda x: x['name'],
                                       self.apicache[verb][subject]['params']))
             search_string = text
+            if self.paramcompletion == 'true':
+                param = line.split(" ")[-1]
+                idx = param.find("=")
+                value = param[idx + 1:]
+                param = param[:idx]
+                if len(value) < 36 and idx != -1:
+                    params = self.apicache[verb][subject]['params']
+                    related = filter(lambda x: x['name'] == param,
+                                     params)[0]['related']
+                    api = min(filter(lambda x: 'list' in x, related), key=len)
+                    response = self.make_request(api, args={'listall': 'true'})
+                    responsekey = filter(lambda x: 'response' in x,
+                                         response.keys())[0]
+                    result = response[responsekey]
+                    uuids = []
+                    for key in result.keys():
+                        if isinstance(result[key], list):
+                            for element in result[key]:
+                                if 'id' in element.keys():
+                                    uuids.append(element['id'])
+                    autocompletions = uuids
+                    search_string = value
 
         if self.tabularize == "true" and subject != "":
             autocompletions.append("filter=")
         return [s for s in autocompletions if s.startswith(search_string)]
 
-
     def do_sync(self, args):
         """
         Asks cloudmonkey to discovery and sync apis available on user specified
@@ -396,7 +417,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
                     helpdoc += "\nRequired params are %s" % ' '.join(required)
                 helpdoc += "\nParameters\n" + "=" * 10
                 for param in api['params']:
-                    helpdoc += "\n%s = (%s) %s" % (param['name'], param['type'], param['description'])
+                    helpdoc += "\n%s = (%s) %s" % (param['name'],
+                               param['type'], param['description'])
                 self.monkeyprint(helpdoc)
             else:
                 self.monkeyprint("Error: no such api (%s) on %s" %

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1fd05631/tools/cli/cloudmonkey/config.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/config.py b/tools/cli/cloudmonkey/config.py
index 8b718c2..5dfe09b 100644
--- a/tools/cli/cloudmonkey/config.py
+++ b/tools/cli/cloudmonkey/config.py
@@ -42,6 +42,8 @@ cache_file = expanduser(config_dir + '/cache')
 config_fields = {'core': {}, 'ui': {}, 'server': {}, 'user': {}}
 
 # core
+config_fields['core']['asyncblock'] = 'true'
+config_fields['core']['paramcompletion'] = 'false'
 config_fields['core']['history_file'] = expanduser(config_dir + '/history')
 config_fields['core']['log_file'] = expanduser(config_dir + '/log')
 
@@ -51,7 +53,6 @@ config_fields['ui']['prompt'] = '> '
 config_fields['ui']['tabularize'] = 'false'
 
 # server
-config_fields['server']['asyncblock'] = 'true'
 config_fields['server']['host'] = 'localhost'
 config_fields['server']['path'] = '/client/api'
 config_fields['server']['port'] = '8080'