summaryrefslogtreecommitdiff
path: root/novaclient/base.py
diff options
context:
space:
mode:
authorJoe Gordon <joe.gordon0@gmail.com>2014-09-04 03:45:13 +0000
committerJoe Gordon <joe.gordon0@gmail.com>2014-09-08 18:10:25 -0700
commit07260236ab2179579e0d0d2f9b7fb8027652dc32 (patch)
tree75aa274e93c53994872d428d2a2fd91c5724fe09 /novaclient/base.py
parent7377b42482787f1dd9b65938d9fd2ca3758f7be4 (diff)
downloadpython-novaclient-07260236ab2179579e0d0d2f9b7fb8027652dc32.tar.gz
Make findall support server side filtering
Instead of listing all servers and doing clientside filtering, use the servers filtering on name.the server's list already supports filtering so just pass a search_opts dictionary into list(). This should speed up nova commands when a user has large numbers of servers. Change-Id: I6deea8523754ff213f43bd059fb00f34fc0e1a12 Closes-Bug: #1202179
Diffstat (limited to 'novaclient/base.py')
-rw-r--r--novaclient/base.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/novaclient/base.py b/novaclient/base.py
index ff8308bd..173eda08 100644
--- a/novaclient/base.py
+++ b/novaclient/base.py
@@ -131,9 +131,6 @@ class ManagerWithFind(Manager):
def find(self, **kwargs):
"""
Find a single item with attributes matching ``**kwargs``.
-
- This isn't very efficient: it loads the entire list then filters on
- the Python side.
"""
matches = self.findall(**kwargs)
num_matches = len(matches)
@@ -148,9 +145,6 @@ class ManagerWithFind(Manager):
def findall(self, **kwargs):
"""
Find all items with attributes matching ``**kwargs``.
-
- This isn't very efficient: it loads the entire list then filters on
- the Python side.
"""
found = []
searches = kwargs.items()
@@ -173,6 +167,20 @@ class ManagerWithFind(Manager):
del tmp_kwargs['is_public']
searches = tmp_kwargs.items()
+ if 'search_opts' in list_argspec.args:
+ # pass search_opts in to do server side based filtering.
+ # TODO(jogo) not all search_opts support regex, find way to
+ # identify when to use regex and when to use string matching.
+ # volumes does not support regex while servers does. So when
+ # doing findall on servers some client side filtering is still
+ # needed.
+ if "human_id" in kwargs:
+ list_kwargs['search_opts'] = {"name": kwargs["human_id"]}
+ elif "name" in kwargs:
+ list_kwargs['search_opts'] = {"name": kwargs["name"]}
+ elif "display_name" in kwargs:
+ list_kwargs['search_opts'] = {"name": kwargs["display_name"]}
+
listing = self.list(**list_kwargs)
for obj in listing: