Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 180B817C5B for ; Wed, 29 Oct 2014 06:57:51 +0000 (UTC) Received: (qmail 33608 invoked by uid 500); 29 Oct 2014 06:57:50 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 33581 invoked by uid 500); 29 Oct 2014 06:57:50 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 33571 invoked by uid 99); 29 Oct 2014 06:57:50 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2014 06:57:50 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 68878999EFA; Wed, 29 Oct 2014 06:57:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Wed, 29 Oct 2014 06:57:51 -0000 Message-Id: <1b4b2aba4d7043bc8b8bb094093e77c4@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: cloudmonkey: Implement caching mechanism for paramcompletion background calls cloudmonkey: Implement caching mechanism for paramcompletion background calls Signed-off-by: Rohit Yadav 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 Authored: Wed Oct 29 12:27:25 2014 +0530 Committer: Rohit Yadav 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