orrery edited a comment on issue #1573:
URL: https://github.com/apache/libcloud/issues/1573#issuecomment-824463659


   so I tried pagination on list_images and it doesn't work as expected.
   ```
   params, more_results = {'maxResults': 10}, True
           while more_results:
               self.raw_driver.connection.gce_params=params
               self.raw_driver.list_images()
               more_results = 'pageToken' in params
   ```
   
   if you look at responses from `ex_list_project_images`  
self.connection.request(request, method='GET').object
   you will see the item list in the response maxing out at 500. Note that 
`pageToken` is being set, but it appears that it is not effecting pagination at 
`ex_list_project_images` function.
   
   I noticed that the request/response handles pagination in 
`request_aggregated_items` which is called by `list_nodes`, but doesn't appear 
to be addressed in `ex_list_project_images`. 
   
   I monkey patched the following into `ex_list_project_images` and verified I 
can now return the correct Ubuntu 20.04 LTS image
   ```
           list_images = []
           request = '/global/images'
           if ex_project is None:
               params = {'maxResults': 100}
               more_results = True
               while more_results:
                   self.connection.gce_params = params
                   response = self.connection.request(request, 
method='GET').object
                   for img in response.get('items', []):
                       if 'deprecated' not in img:
                           list_images.append(self._to_node_image(img))
                       else:
                           if ex_include_deprecated:
                               list_images.append(self._to_node_image(img))
                   more_results = 'pageToken' in params
                   print(len(response.get('items')), more_results)
   
           else:
               list_images = []
               # Save the connection request_path
               save_request_path = self.connection.request_path
               if isinstance(ex_project, str):
                   ex_project = [ex_project]
               for proj in ex_project:
                   # Override the connection request path
                   new_request_path = save_request_path.replace(self.project,
                                                                proj)
                   self.connection.request_path = new_request_path
                   try:
                       params = {'maxResults': 100}
                       more_results = True
                       while more_results:
                           self.connection.gce_params = params
                           response = self.connection.request(request,
                                                              
method='GET').object
                           for img in response.get('items', []):
                               if 'deprecated' not in img:
                                   list_images.append(self._to_node_image(img))
                               else:
                                   if ex_include_deprecated:
                                       
list_images.append(self._to_node_image(img))
                           more_results = 'pageToken' in params
                           print(len(response.get('items')), more_results)
   
                   except Exception:
                       raise
                   finally:
                       # Restore the connection request_path
                       self.connection.request_path = save_request_path
           return list_images
   ```        
   
   Related to https://github.com/apache/libcloud/pull/1409
   
   Note, I am unable to re-open this ticket
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to