libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [2/4] libcloud git commit: Fix IndexError in dimensiondata list_images.
Date Sun, 25 Feb 2018 18:21:44 GMT
Fix IndexError in dimensiondata list_images.

Fix involves filtering out images from locations not returned by the list_locations API.

This is required because the CloudControl API returns all images in the
target geographic region (even ones in datacenters the user's
organisation does not have access to).

We therefore need to filter out those images (since we can't get a
NodeLocation for them).

Signed-off-by: Quentin Pradet <quentinp@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0a502252
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0a502252
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0a502252

Branch: refs/heads/trunk
Commit: 0a502252161f8b8c48aecef5c8be7d300bf00e07
Parents: 85180ab
Author: Adam Friedman <tintoy@tintoy.io>
Authored: Thu Feb 8 10:00:50 2018 +1100
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Sun Feb 25 22:16:15 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0a502252/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 2797f50..2543149 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -4161,8 +4161,18 @@ class DimensionDataNodeDriver(NodeDriver):
         images = []
         locations = self.list_locations()
 
+        # The CloudControl API will return all images
+        # in the current geographic region (even ones in
+        # datacenters the user's organisation does not have access to)
+        #
+        # We therefore need to filter out those images (since we can't
+        # get a NodeLocation for them)
+        location_ids = set(location.id for location in locations)
+
         for element in object.findall(fixxpath(el_name, TYPES_URN)):
-            images.append(self._to_image(element, locations))
+            location_id = element.get('datacenterId')
+            if location_id in location_ids:
+                images.append(self._to_image(element, locations))
 
         return images
 
@@ -4170,9 +4180,8 @@ class DimensionDataNodeDriver(NodeDriver):
         location_id = element.get('datacenterId')
         if locations is None:
             locations = self.list_locations(location_id)
-        location = list(filter(lambda x: x.id == location_id,
-                               locations))[0]
 
+        location = filter(lambda x: x.id == location_id, locations)[0]
         cpu_spec = self._to_cpu_spec(element.find(fixxpath('cpu', TYPES_URN)))
 
         if LooseVersion(self.connection.active_api_version) > LooseVersion(


Mime
View raw message