Skip to content

Commit 212472f

Browse files
committed
improve gather list of locations
1 parent 953ce15 commit 212472f

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

SoftLayer/managers/image.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,17 @@ def add_locations(self, image_id, location_names):
195195
:param int image_id: The ID of the image
196196
:param location_names: Locations for the Image.
197197
"""
198-
locations = self.get_locations_id_list(image_id, location_names)
199-
locations_ids = [{'id': location_id} for location_id in locations]
200-
return self.vgbdtg.addLocations(locations_ids, id=image_id)
198+
locations = self.get_locations_list(image_id, location_names)
199+
return self.vgbdtg.addLocations(locations, id=image_id)
201200

202201
def remove_locations(self, image_id, location_names):
203202
"""Remove available locations from an archive image template.
204203
205204
:param int image_id: The ID of the image
206205
:param location_names: Locations for the Image.
207206
"""
208-
locations = self.get_locations_id_list(image_id, location_names)
209-
locations_ids = [{'id': location_id} for location_id in locations]
210-
return self.vgbdtg.removeLocations(locations_ids, id=image_id)
207+
locations = self.get_locations_list(image_id, location_names)
208+
return self.vgbdtg.removeLocations(locations, id=image_id)
211209

212210
def get_storage_locations(self, image_id):
213211
"""Get available locations for public image storage.
@@ -216,13 +214,12 @@ def get_storage_locations(self, image_id):
216214
"""
217215
return self.vgbdtg.getStorageLocations(id=image_id)
218216

219-
def get_locations_id_list(self, image_id, location_names):
220-
"""Converts a list of location names to a list of location IDs.
217+
def get_locations_list(self, image_id, location_names):
218+
"""Converts a list of location names to a list of locations.
221219
222220
:param int image_id: The ID of the image.
223221
:param list location_names: A list of location names strings.
224-
:returns: A list of locations IDs associated with the given location
225-
keynames in the image id.
222+
:returns: A list of locations associated with the given location names in the image.
226223
"""
227224
locations = self.get_storage_locations(image_id)
228225
locations_ids = []
@@ -235,10 +232,8 @@ def get_locations_id_list(self, image_id, location_names):
235232
matching_location = location
236233
break
237234
if matching_location.get('id') is None:
238-
raise exceptions.SoftLayerError(
239-
output_error.format(location_name, image_id)
240-
)
235+
raise exceptions.SoftLayerError(output_error.format(location_name, image_id))
241236

242-
locations_ids.append(matching_location.get('id'))
237+
locations_ids.append(matching_location)
243238

244239
return locations_ids

tests/managers/image_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_get_locations_id_fails(self):
219219
locations = ['test']
220220
self.assertRaises(
221221
exceptions.SoftLayerError,
222-
self.image.get_locations_id_list,
222+
self.image.get_locations_list,
223223
100,
224224
locations
225225
)

0 commit comments

Comments
 (0)