summaryrefslogtreecommitdiff
path: root/heatclient/v1/stacks.py
diff options
context:
space:
mode:
authorAnderson Mesquita <andersonvom@gmail.com>2014-01-08 18:47:11 -0600
committerRichard Lee <rblee88@gmail.com>2014-02-05 14:38:30 -0600
commitcda180eed49a70b2645cf5e21b1dfe130d96d957 (patch)
tree4c091b250933570854f70f78f924aa4c7dea14b1 /heatclient/v1/stacks.py
parentbb754dc8f2af71b0c4f1d0853f18fd5428d1866e (diff)
downloadpython-heatclient-cda180eed49a70b2645cf5e21b1dfe130d96d957.tar.gz
Add pagination (limit and marker) to stack-list
Add support for ``limit`` and ``marker`` on stack-list and remove unnecessary ``page_size`` parameter. When using ``limit`` and/or ``marker``, stack-list will keep previous behavior and list all stacks starting from ``marker`` up to ``limit``, even if limit exceeds API limit restrictions, by using multiple calls to /stacks endpoint. Partial-Bug: 1268816 Change-Id: Ifb08c1aadd3629d60ddc56ffc507c99b9dba80ce
Diffstat (limited to 'heatclient/v1/stacks.py')
-rw-r--r--heatclient/v1/stacks.py35
1 files changed, 14 insertions, 21 deletions
diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py
index 258d313..d6d2737 100644
--- a/heatclient/v1/stacks.py
+++ b/heatclient/v1/stacks.py
@@ -67,7 +67,6 @@ class StackManager(base.BaseManager):
def list(self, **kwargs):
"""Get a list of stacks.
- :param page_size: number of items to request in each paginated request
:param limit: maximum number of stacks to return
:param marker: begin returning stacks that appear later in the stack
list than that represented by this stack id
@@ -75,32 +74,26 @@ class StackManager(base.BaseManager):
structure of a stack object
:rtype: list of :class:`Stack`
"""
- absolute_limit = kwargs.get('limit')
-
- def paginate(qp, seen=0):
- sort_qp = sorted(qp.items(), key=lambda x: x[0])
- url = '/stacks?%s' % urlutils.urlencode(sort_qp)
-
- stacks = self._list(url, "stacks")
+ def paginate(params):
+ '''Paginate stacks, even if more than API limit.'''
+ current_limit = int(params.get('limit') or 0)
+ url = '/stacks?%s' % urlutils.urlencode(params)
+ stacks = self._list(url, 'stacks')
for stack in stacks:
- seen += 1
- if absolute_limit is not None and seen > absolute_limit:
- return
yield stack
- page_size = qp.get('limit')
- if (page_size and len(stacks) == page_size and
- (absolute_limit is None or 0 < seen < absolute_limit)):
- qp['marker'] = stack.id
- for stack in paginate(qp, seen):
+ num_stacks = len(stacks)
+ remaining_limit = current_limit - num_stacks
+ if remaining_limit > 0 and num_stacks > 0:
+ params['limit'] = remaining_limit
+ params['marker'] = stack.id
+ for stack in paginate(params):
yield stack
params = {}
- if 'page_size' in kwargs:
- params['limit'] = kwargs['page_size']
-
- if 'marker' in kwargs:
- params['marker'] = kwargs['marker']
+ for key, value in kwargs.iteritems():
+ if value:
+ params[key] = value
filters = kwargs.get('filters', {})
properties = filters.pop('properties', {})