def _fetch_images(self, fetch_func, **kwargs): """Paginate through results from glance server""" images = fetch_func(**kwargs) if not images: # break out of recursive loop to end pagination return for image in images: yield image try: # attempt to advance the marker in order to fetch next page kwargs['marker'] = images[-1]['id'] except KeyError: raise exception.ImagePaginationFailed() try: kwargs['limit'] = kwargs['limit'] - len(images) # break if we have reached a provided limit if kwargs['limit'] <= 0: return except KeyError: # ignore missing limit, just proceed without it pass for image in self._fetch_images(fetch_func, **kwargs): yield image
def _fetch_images(self, fetch_func, **kwargs): """Paginate through results from glance server""" images = fetch_func(**kwargs) for image in images: yield image else: # break out of recursive loop to end pagination return try: # attempt to advance the marker in order to fetch next page kwargs['marker'] = images[-1]['id'] except KeyError: raise exception.ImagePaginationFailed() self._fetch_images(fetch_func, **kwargs)