Skip to content
Permalink
Browse files
Merge branch 'master' of github.com:imduffy15/ec2stack
* 'master' of github.com:imduffy15/ec2stack:
  Complete volume attachment / detachment
  Add broken implementation
  • Loading branch information
imduffy15 committed Mar 3, 2014
2 parents 2f597a0 + aee26ef commit 923896b0c72e77dcf2de738a4a275e6a58470a84
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
@@ -25,6 +25,7 @@ def index():

def _get_action(action):
actions = {
'AttachVolume': volumes.attach_volume,
'AuthorizeSecurityGroupEgress':
security_groups.authenticate_security_group_egress,
'AuthorizeSecurityGroupIngress':
@@ -43,6 +44,7 @@ def _get_action(action):
'DescribeKeyPairs': keypairs.describe_keypairs,
'DescribeSecurityGroups': security_groups.describe_security_groups,
'DescribeVolumes': volumes.describe_volumes,
'DetachVolume': volumes.detach_volume,
'GetPasswordData': passwords.get_password_data,
'ImportKeyPair': keypairs.import_keypair,
'RebootInstances': instances.reboot_instance,
@@ -44,6 +44,22 @@ def invalid_volume_id():
)


def volume_attached():
raise Ec2stackError(
'400',
'InvalidVolume.Attached',
'The specified Volume is already attached.'
)


def volume_detached():
raise Ec2stackError(
'400',
'InvalidVolume.Detached',
'The specified Volume isn\'t attached.'
)


def invalid_disk_offering_name():
raise Ec2stackError(
'400',
@@ -11,7 +11,11 @@

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


@@ -77,6 +81,79 @@ def _create_volume_response(response):
}


@helpers.authentication_required
def attach_volume():
helpers.require_parameters(['VolumeId', 'InstanceId', 'Device'])
response = _attach_volume_request()
return _attach_volume_response(response)


def _attach_volume_request():
args = {}

volume_id = helpers.get('VolumeId')
instance_id = helpers.get('InstanceId')
device = helpers.get('Device')

args['id'] = volume_id
args['command'] = 'attachVolume'
args['virtualmachineid'] = instance_id
args['device'] = device

response = requester.make_request_async(args)

return response


def _attach_volume_response(response):
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)

response = response['volume']
return {
'template_name_or_list': 'volume_attachment.xml',
'response_type': 'AttachVolumeResponse',
'response': response
}


@helpers.authentication_required
def detach_volume():
helpers.require_parameters(['VolumeId'])
response = _detach_volume_request()
return _detach_volume_response(response)


def _detach_volume_request():
args = {}

volume_id = helpers.get('VolumeId')

if helpers.contains_parameter('InstanceId'):
args['virtualmachineid'] = helpers.get('InstanceId')
if helpers.contains_parameter('Device'):
args['deviceid'] = helpers.get('Device')

args['id'] = volume_id
args['command'] = 'detachVolume'

response = requester.make_request_async(args)

return response


def _detach_volume_response(response):
if 'errortext' in response:
helpers.error_to_aws(response, volume_error_to_aws)

response = response['volume']
return {
'template_name_or_list': 'volume_attachment.xml',
'response_type': 'DetachVolumeResponse',
'response': response
}


@helpers.authentication_required
def delete_volume():
helpers.require_parameters(['VolumeId'])
@@ -0,0 +1,13 @@
{% extends "response.xml" %}
{% block response_content %}
<volumeId>
{{ response.id }}
</volumeId>
{% if response.virtualmachineid %}
<instanceId>
{{ response.virtualmachineid }}
</instanceId>
{% endif %}
<status>{{ response.state }}</status>
<attachTime>{{ response.created }}</attachTime>
{% endblock %}

0 comments on commit 923896b

Please sign in to comment.