vdloo commented on a change in pull request #1467:
URL: https://github.com/apache/libcloud/pull/1467#discussion_r439445328



##########
File path: libcloud/compute/drivers/openstack.py
##########
@@ -2862,10 +2862,14 @@ def list_images(self, location=None, 
ex_only_active=True):
             raise NotImplementedError(
                 "ex_only_active in list_images is not implemented "
                 "in the OpenStack_2_NodeDriver")
-        response = self.image_connection.request('/v2/images')
         images = []
-        for image in response.object['images']:
-            images.append(self._to_image(image))
+        path = '/v2/images'
+        while path:

Review comment:
       yes I do, but _paginated_request works slightly different though (would 
expect images_links, see my comment 
[here](https://github.com/apache/libcloud/issues/1466) and 
[here](https://github.com/apache/libcloud/pull/1263))
   
   a version like
   ```python
       def list_images(self, location=None, ex_only_active=True):
           """
           Lists all active images using the V2 Glance API
   
           @inherits: :class:`NodeDriver.list_images`
   
           :param location: Which data center to list the images in. If
                                  empty, undefined behavior will be selected.
                                  (optional)
           :type location: :class:`.NodeLocation`
   
           :param ex_only_active: True if list only active (optional)
           :type ex_only_active: ``bool``
           """
           if location is not None:
               raise NotImplementedError(
                   "location in list_images is not implemented "
                   "in the OpenStack_2_NodeDriver")
           if not ex_only_active:
               raise NotImplementedError(
                   "ex_only_active in list_images is not implemented "
                   "in the OpenStack_2_NodeDriver")
   
           response = self._paginated_request(
               '/v2/images', 'images', self.network_connection)
           return [self._to_image(port) for image in response['images']]
   ```
   would result in:
   
   ```python
   ----> 1 conn.list_images()
   
   
~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/compute/drivers/openstack.py
 in list_images(self, location, ex_only_active)
      2846 
      2847         response = self._paginated_request(
   -> 2848             '/v2/images', 'images', self.network_connection)
      2849         return [self._to_image(port) for image in response['images']]
      2850 
   
   
~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/compute/drivers/openstack.py
 in _paginated_request(url, obj, connection, params)
       198         loop_count = 0
       199         while True:
   --> 200             data = connection.request(url, params=params)
       201             values = data.object.get(obj, list())
       202             objects.extend(values)
   
   ~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/common/openstack.py 
in request(self, action, params, data, headers, method, raw) 
       223                                                             
method=method,
       224                                                             
headers=headers,
   --> 225                                                             raw=raw)
       226 
       227     def _get_auth_url(self):
   
   ~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/common/base.py in 
request(self, action, params, data, headers, method, raw, stream)
       636
       637         try:
   --> 638             response = responseCls(**kwargs)
       639         finally:
       640             # Always reset the context after the request has 
completed
   
   
~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/compute/drivers/openstack.py
 in __init__(self, *args, **kwargs)
      1122         # NodeDriver -> Connection -> Response
      1123         self.node_driver = OpenStack_1_1_NodeDriver
   -> 1124         super(OpenStack_1_1_Response, self).__init__(*args, **kwargs)
      1125
      1126 
   
   ~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/common/base.py in 
__init__(self, response, connection)
       149         if not self.success():
       150             raise exception_from_message(code=self.status,
   --> 151                                          message=self.parse_error(),
       152                                          headers=self.headers)
       153 
   
   ~/.virtualenvs/libcloudtest/src/apache-libcloud/libcloud/common/openstack.py 
in parse_error(self)
       392             key_pair_name = context.get('key_pair_name', None)
       393 
   --> 394             if len(values) > 0 and 'code' in values[0] and \
       395                     values[0]['code'] == 404 and key_pair_name:
       396                 raise KeyPairDoesNotExistError(name=key_pair_name,
   
   TypeError: argument of type 'int' is not iterable
   ```
   but perhaps modifying _paginated_request to also take into account this 
'next' attribute would be a better solution than having this loop in the 
list_images method indeed




----------------------------------------------------------------
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