Skip to content
Permalink
Browse files
Clean volumes.py
  • Loading branch information
brogand93 committed Mar 8, 2014
1 parent 87386ed commit e6750b741b33cd8b94467f1a69bded17fc56c38c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
@@ -186,6 +186,19 @@ def invalid_permission():
)


def invalid_request(message):
"""
Invalid Request.
@raise Ec2stackError: Defining a bad request and message.
"""
raise Ec2stackError(
'400',
'InvalidRequest',
message
)


def missing_parameter(parameter):
"""
Missing Parameter.
@@ -91,19 +91,6 @@ def require_atleast_one_parameter(parameters):
errors.missing_parameter(parameter)


def error_to_aws(response, error_map):
# TODO @BroganD1993 not a clue what this does. its all yours.
"""
@param response:
@param error_map:
"""
for errortext, error_function in error_map.iteritems():
if errortext in response['errortext']:
error_function()


def contains_parameter(parameter, data=None):
"""
Checks if the parameter is contained within the given data.
@@ -11,16 +11,6 @@
from ec2stack.providers.cloudstack import requester, disk_offerings, zones


volume_error_to_aws = {
'unable to find a snapshot': errors.invalid_snapshot_id,
'Unable to aquire volume with ID': errors.invalid_volume_id,
'Please specify a volume that is not attached': errors.invalid_volume_attached,
'The specified volume is not attached': errors.invalid_volume_detached,
'Invalid parameter virtualmachineid': errors.invalid_instance_id,
'Invalid parameter id': errors.invalid_volume_id
}


@helpers.authentication_required
def attach_volume():
"""
@@ -62,7 +52,12 @@ def _attach_volume_response(response):
@return:
"""
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)
if 'specify a volume that is not attached' in response['errortext']:
errors.invalid_volume_attached()
if 'Invalid parameter virtualmachineid' in response['errortext']:
errors.invalid_instance_id()
if 'Invalid parameter id' in response['errortext']:
errors.invalid_volume_id()

response = response['volume']
return {
@@ -79,7 +74,6 @@ def create_volume():
@return:
"""
helpers.require_atleast_one_parameter(['SnapshotId', 'Size'])
response = _create_volume_request()
return _create_volume_response(response)

@@ -120,7 +114,10 @@ def _create_volume_response(response):
@return:
"""
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)
if 'Invalid parameter snapshotid' in response['errortext']:
errors.invalid_snapshot_id()
if 'unable to find a snapshot with id' in response['errortext']:
errors.invalid_snapshot_id()

response = response['volume']
return {
@@ -164,7 +161,9 @@ def _delete_volume_response(response):
@return:
"""
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)
if 'Unable to aquire volume' in response['errortext']:
errors.invalid_volume_id()


return {
'template_name_or_list': 'status.xml',
@@ -245,7 +244,13 @@ def _detach_volume_response(response):
@return:
"""
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)
if 'specified volume is not attached' in response['errortext']:
errors.invalid_volume_detached()
if 'Invalid parameter virtualmachineid' in response['errortext']:
errors.invalid_instance_id()
if 'Invalid parameter id' in response['errortext']:
errors.invalid_volume_id()


response = response['volume']
return {

0 comments on commit e6750b7

Please sign in to comment.