Merge "Support pagination listing in client extension"

This commit is contained in:
Jenkins
2016-01-16 02:40:04 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 6 deletions

View File

@@ -104,6 +104,11 @@ class CLITestV20ExtensionJSON(test_cli20.CLITestV20Base):
cmd = fox_sockets.FoxInSocketsList(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources(resources, cmd, True)
def test_list_fox_pagination(self):
resources = 'fox_sockets'
cmd = fox_sockets.FoxInSocketsList(test_cli20.MyApp(sys.stdout), None)
self._test_list_resources_with_pagination(resources, cmd)
def test_show_fox_socket(self):
# Show fox_socket: --fields id --fields name myid.
resource = 'fox_socket'

View File

@@ -448,9 +448,9 @@ class Client(ClientBase):
}
@APIParamsCall
def list_ext(self, path, **_params):
def list_ext(self, collection, path, retrieve_all, **_params):
"""Client extension hook for lists."""
return self.get(path, params=_params)
return self.list(collection, path, retrieve_all, **_params)
@APIParamsCall
def show_ext(self, path, id, **_params):
@@ -1701,11 +1701,13 @@ class Client(ClientBase):
setattr(self, "show_%s" % resource_singular, fn)
def extend_list(self, resource_plural, path, parent_resource):
def _fx(**_params):
return self.list_ext(path, **_params)
def _fx(retrieve_all=True, **_params):
return self.list_ext(resource_plural, path,
retrieve_all, **_params)
def _parent_fx(parent_id, **_params):
return self.list_ext(path % parent_id, **_params)
def _parent_fx(parent_id, retrieve_all=True, **_params):
return self.list_ext(resource_plural, path % parent_id,
retrieve_all, **_params)
fn = _fx if not parent_resource else _parent_fx
setattr(self, "list_%s" % resource_plural, fn)