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: cloudmonkey: Implement caching mechanism for paramcompletion background calls
Date Wed, 29 Oct 2014 06:57:51 GMT
cloudmonkey: Implement caching mechanism for paramcompletion background calls

Signed-off-by: Rohit Yadav <rohit.yadav@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/78920d02
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/78920d02
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/78920d02

Branch: refs/heads/master
Commit: 78920d02a849577afe43a6f1057c510413a577eb
Parents: b9ad1c6
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Wed Oct 29 12:27:25 2014 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Wed Oct 29 12:27:25 2014 +0530

----------------------------------------------------------------------
 cloudmonkey/cloudmonkey.py | 47 ++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/78920d02/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 2690ef8..efe90e4 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -22,13 +22,14 @@ try:
     import argparse
     import atexit
     import cmd
+    import copy
     import json
     import logging
     import os
     import shlex
     import sys
+    import time
     import types
-    import copy
     import urllib
 
     from cachemaker import loadcache, savecache, monkeycache, splitverbsubject
@@ -73,6 +74,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
     config_options = []
     profile_names = []
     verbs = []
+    param_cache = {}
     prompt = "🐵 > "
     protocol = "http"
     host = "localhost"
@@ -385,16 +387,41 @@ class CloudMonkeyShell(cmd.Cmd, object):
                     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'])
+                    if api in self.param_cache.keys() and self.param_cache[api]["ts"] >
(int(time.time()) - 1000):
+                        for option in self.param_cache[api]["options"]:
+                            uuid = option[0]
+                            name = option[1]
+                            if uuid.startswith(value):
+                                uuids.append(uuid)
+                    else:
+                        response = self.make_request(api, args={'listall': 'true', 'templatefilter':
'all'})
+                        responsekey = filter(lambda x: 'response' in x,
+                                            response.keys())[0]
+                        result = response[responsekey]
+                        self.param_cache[api] = {}
+                        self.param_cache[api]["ts"] = int(time.time())
+                        self.param_cache[api]["options"] = []
+                        for key in result.keys():
+                            if isinstance(result[key], list):
+                                for element in result[key]:
+                                    if 'id' in element.keys():
+                                        uuid = element['id']
+                                        name = ""
+                                        if 'name' in element.keys():
+                                            name = element['name']
+                                        elif 'username' in element.keys():
+                                            name = element['username']
+                                        self.param_cache[api]["options"].append((uuid, name,))
+                                        uuids.append(uuid)
+
+                    if len(uuids) > 1:
+                        print "\n"
+                        for option in self.param_cache[api]["options"]:
+                            uuid = option[0]
+                            name = option[1]
+                            if uuid.startswith(value):
+                                print uuid, name
                     autocompletions = uuids
                     search_string = value
 


Mime
View raw message