summaryrefslogtreecommitdiff
path: root/keystoneclient/base.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-01-07 03:59:43 +0000
committerGerrit Code Review <review@openstack.org>2016-01-07 03:59:43 +0000
commitf15918318c8b9f645ebc0b5fe672d10fce3e4d03 (patch)
tree84f3a90fcb5232a379c7d96d6f7736bbfa768168 /keystoneclient/base.py
parent411ab2ef2d82fda170bac9b1ef74ed5706d4be77 (diff)
parentc28d40814962b3a8ccb81e5e7d7f832c8f0a3c9a (diff)
downloadpython-keystoneclient-f15918318c8b9f645ebc0b5fe672d10fce3e4d03.tar.gz
Merge "Support `truncated` flag returned by keystone"
Diffstat (limited to 'keystoneclient/base.py')
-rw-r--r--keystoneclient/base.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/keystoneclient/base.py b/keystoneclient/base.py
index e10d888..4dd16d7 100644
--- a/keystoneclient/base.py
+++ b/keystoneclient/base.py
@@ -20,6 +20,7 @@ Base utilities to build API operation managers and objects on top of.
"""
import abc
+import collections
import copy
import functools
import warnings
@@ -76,6 +77,23 @@ def filter_kwargs(f):
return func
+class KeystoneReturnedList(collections.Sequence):
+ """A list of entities with additional attributes."""
+
+ def __init__(self, collection, truncated=False):
+ self.collection = collection
+ self.truncated = truncated
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def sort(self, *args, **kwargs):
+ return self.collection.sort(*args, **kwargs)
+
+
class Manager(object):
"""Basic manager type providing common operations.
@@ -127,6 +145,7 @@ class Manager(object):
obj_class = self.resource_class
data = body[response_key]
+ truncated = body.get('truncated', False)
# NOTE(ja): keystone returns values as list as {'values': [ ... ]}
# unlike other services which just return the list...
try:
@@ -134,7 +153,8 @@ class Manager(object):
except (KeyError, TypeError):
pass
- return [obj_class(self, res, loaded=True) for res in data if res]
+ objects = [obj_class(self, res, loaded=True) for res in data if res]
+ return KeystoneReturnedList(objects, truncated=truncated)
def _get(self, url, response_key, **kwargs):
"""Get an object from collection.