Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Using proper volume size for volume creating #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions jumpgate/volume/drivers/sl/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def on_post(self, req, resp, tenant_id):
"SoftLayerAPIError",
e.faultString,
code=e.faultCode)
except IndexError as e:
return error_handling.bad_request(resp, str(e))
except Exception as e:
return error_handling.volume_fault(resp, str(e))

Expand Down Expand Up @@ -295,25 +297,31 @@ def _match_portable_storage_prices(packageId, size, exact_capacity):
price_matrix = {}
for x in price_list:
price_matrix.update({int(x['capacity']): x['prices']})
# find the closet capacity to the requested size
if exact_capacity:
ret = False
for x in price_matrix:
if size == x:
ret = True
capacity_idx = x
break
if not ret:
raise SoftLayer.SoftLayerAPIError(
HTTP.BAD_REQUEST,
'volume_types: extra_specs: '
'drivers:exact_capacity is set to'
' True and there is no volume with'
' matching capacity')
else:
capacity_idx = min(price_matrix, key=lambda x: abs(x - size))

return price_matrix[capacity_idx]
try:
# find the closest capacity to the requested size
if exact_capacity:
ret = False
for x in price_matrix:
if size == x:
ret = True
capacity_idx = x
break
if not ret:
raise SoftLayer.SoftLayerAPIError(
HTTP.BAD_REQUEST,
'volume_types: extra_specs: '
'drivers:exact_capacity is set to'
' True and there is no volume with'
' matching capacity')
else:
capacity_idx = sorted([cap for cap in price_matrix
if cap >= size])[0]

return price_matrix[capacity_idx]
except IndexError:
msg = "Unsupported volume size: %d" % size
LOG.error(msg)
raise IndexError(msg)

def _find_availibility_zone_location(zone):
# make sure there is an availability_zone selected
Expand Down