Set Resource.page limit to None
Setting the Resource.page limit to None, which is how it gets used by default from Resource.list, allows it to be used directly with the same ease as Resource.list. For APIs which return lists but don't support pagination, this allows us to provide users the same iteration behavior across the board. For an example of where this comes into play, a GET on /types in the volume service returns a list of types in a single response with no pagination support. If we call Types.list(session) it will be an infinite loop. With this change, Types.page(session) allows the Type proxy to yield type objects out of that one page. Change-Id: I242a9fd0cd6d21b891d91e2fe69006a1f0ec3a15
This commit is contained in:
@@ -706,7 +706,7 @@ class Resource(collections.MutableMapping):
|
||||
more_data = False
|
||||
|
||||
@classmethod
|
||||
def page(cls, session, limit, marker=None, path_args=None, **params):
|
||||
def page(cls, session, limit=None, marker=None, path_args=None, **params):
|
||||
"""Get a one page response.
|
||||
|
||||
This method gets starting at ``marker`` with a maximum of ``limit``
|
||||
@@ -714,7 +714,8 @@ class Resource(collections.MutableMapping):
|
||||
|
||||
:param session: The session to use for making this request.
|
||||
:type session: :class:`~openstack.session.Session`
|
||||
:param limit: The maximum amount of results to retrieve.
|
||||
:param limit: The maximum amount of results to retrieve. The default
|
||||
is to retrieve as many results as the service allows.
|
||||
:param marker: The position in the list to begin requests from.
|
||||
The type of value to use for ``marker`` depends on
|
||||
the API being called.
|
||||
@@ -724,7 +725,7 @@ class Resource(collections.MutableMapping):
|
||||
:param dict params: Parameters to be passed into the underlying
|
||||
:meth:`~openstack.session.Session.get` method.
|
||||
|
||||
:return: An array of :class:`Resource` objects.
|
||||
:return: A list of dictionaries returned in the response body.
|
||||
"""
|
||||
|
||||
filters = {}
|
||||
|
||||
@@ -361,7 +361,7 @@ class ResourceTests(base.TestTransportBase):
|
||||
path = fake_path
|
||||
session.get.assert_called_with(path, params={}, service=None)
|
||||
|
||||
objs = FakeResource.page(session, None, None)
|
||||
objs = FakeResource.page(session)
|
||||
|
||||
self.assertEqual(records, objs)
|
||||
path = fake_base_path
|
||||
|
||||
Reference in New Issue
Block a user