This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Using proper volume size for volume creating #162
Closed
zhiyanliu
wants to merge
5
commits into
softlayer:master
from
zhiyanliu:using-proper-size-for-volume-creating
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4323d56
Merge pull request #1 from softlayer/master
zhiyanliu 84f600e
Merge pull request #2 from softlayer/master
zhiyanliu f6988c8
Merge pull request #3 from softlayer/master
zhiyanliu 616e1fd
Merge pull request #4 from softlayer/master
zhiyanliu 6d28dc9
Using proper volume size for volume creating
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this try/except shouldn't wrap only the code at lines 317-318, rather than the whole if/else block? Looks like that is the only code here that should raise this exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L317/8 can raise this exception as well. |
||
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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious -- does this 400 response match upstream behavior if I were to give normal Cinder some absurd value for volume size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For cinder volume create, there are different sources for volume create, such as image, snapshot, volume,.... The case
jumpgate volume can handle is only the plain volume create from the backend. In such case, cinder volume API will return 202 upon the REST api, the scheduler and volume driver will find the host, check the quota, and create the volume. If everything goes well, the volume status will be 'active'. Otherwise, it will be marked as 'error'. So most of the
volume create error is reflected via the volume status instead of REST API return code since it is asynchronous call.
For jumpgate volume driver, it is using the synchronous way to simulate the cinder API. The BadRequest is closest
option, which is similar to the validation code does in the cinder volume api code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, +1, it was the reason I thought. Thanks for the explanation, ajiang38740.