Replaced direct querystring access with inherited _get_param

This commit is contained in:
Nuwan Goonasekera 2017-09-16 18:31:30 +05:30
commit 7ed1036ba8
18 changed files with 215 additions and 262 deletions

View file

@ -6,9 +6,9 @@ from moto.ec2.utils import filters_from_querystring
class ElasticBlockStore(BaseResponse):
def attach_volume(self):
volume_id = self.querystring.get('VolumeId')[0]
instance_id = self.querystring.get('InstanceId')[0]
device_path = self.querystring.get('Device')[0]
volume_id = self._get_param('VolumeId')
instance_id = self._get_param('InstanceId')
device_path = self._get_param('Device')
if self.is_not_dryrun('AttachVolume'):
attachment = self.ec2_backend.attach_volume(
volume_id, instance_id, device_path)
@ -21,18 +21,18 @@ class ElasticBlockStore(BaseResponse):
'ElasticBlockStore.copy_snapshot is not yet implemented')
def create_snapshot(self):
description = self.querystring.get('Description', [None])[0]
volume_id = self.querystring.get('VolumeId')[0]
volume_id = self._get_param('VolumeId')
description = self._get_param('Description')
if self.is_not_dryrun('CreateSnapshot'):
snapshot = self.ec2_backend.create_snapshot(volume_id, description)
template = self.response_template(CREATE_SNAPSHOT_RESPONSE)
return template.render(snapshot=snapshot)
def create_volume(self):
size = self.querystring.get('Size', [None])[0]
zone = self.querystring.get('AvailabilityZone', [None])[0]
snapshot_id = self.querystring.get('SnapshotId', [None])[0]
encrypted = self.querystring.get('Encrypted', ['false'])[0]
size = self._get_param('Size')
zone = self._get_param('AvailabilityZone')
snapshot_id = self._get_param('SnapshotId')
encrypted = self._get_param('Encrypted', if_none=False)
if self.is_not_dryrun('CreateVolume'):
volume = self.ec2_backend.create_volume(
size, zone, snapshot_id, encrypted)
@ -40,23 +40,20 @@ class ElasticBlockStore(BaseResponse):
return template.render(volume=volume)
def delete_snapshot(self):
snapshot_id = self.querystring.get('SnapshotId')[0]
snapshot_id = self._get_param('SnapshotId')
if self.is_not_dryrun('DeleteSnapshot'):
self.ec2_backend.delete_snapshot(snapshot_id)
return DELETE_SNAPSHOT_RESPONSE
def delete_volume(self):
volume_id = self.querystring.get('VolumeId')[0]
volume_id = self._get_param('VolumeId')
if self.is_not_dryrun('DeleteVolume'):
self.ec2_backend.delete_volume(volume_id)
return DELETE_VOLUME_RESPONSE
def describe_snapshots(self):
filters = filters_from_querystring(self.querystring)
# querystring for multiple snapshotids results in SnapshotId.1,
# SnapshotId.2 etc
snapshot_ids = ','.join(
[','.join(s[1]) for s in self.querystring.items() if 'SnapshotId' in s[0]])
snapshot_ids = self._get_multi_param('SnapshotId')
snapshots = self.ec2_backend.describe_snapshots(filters=filters)
# Describe snapshots to handle filter on snapshot_ids
snapshots = [
@ -66,10 +63,7 @@ class ElasticBlockStore(BaseResponse):
def describe_volumes(self):
filters = filters_from_querystring(self.querystring)
# querystring for multiple volumeids results in VolumeId.1, VolumeId.2
# etc
volume_ids = ','.join(
[','.join(v[1]) for v in self.querystring.items() if 'VolumeId' in v[0]])
volume_ids = self._get_multi_param('VolumeId')
volumes = self.ec2_backend.describe_volumes(filters=filters)
# Describe volumes to handle filter on volume_ids
volumes = [
@ -86,9 +80,9 @@ class ElasticBlockStore(BaseResponse):
'ElasticBlockStore.describe_volume_status is not yet implemented')
def detach_volume(self):
volume_id = self.querystring.get('VolumeId')[0]
instance_id = self.querystring.get('InstanceId')[0]
device_path = self.querystring.get('Device')[0]
volume_id = self._get_param('VolumeId')
instance_id = self._get_param('InstanceId')
device_path = self._get_param('Device')
if self.is_not_dryrun('DetachVolume'):
attachment = self.ec2_backend.detach_volume(
volume_id, instance_id, device_path)
@ -106,7 +100,7 @@ class ElasticBlockStore(BaseResponse):
'ElasticBlockStore.import_volume is not yet implemented')
def describe_snapshot_attribute(self):
snapshot_id = self.querystring.get('SnapshotId')[0]
snapshot_id = self._get_param('SnapshotId')
groups = self.ec2_backend.get_create_volume_permission_groups(
snapshot_id)
template = self.response_template(
@ -114,10 +108,10 @@ class ElasticBlockStore(BaseResponse):
return template.render(snapshot_id=snapshot_id, groups=groups)
def modify_snapshot_attribute(self):
snapshot_id = self.querystring.get('SnapshotId')[0]
operation_type = self.querystring.get('OperationType')[0]
group = self.querystring.get('UserGroup.1', [None])[0]
user_id = self.querystring.get('UserId.1', [None])[0]
snapshot_id = self._get_param('SnapshotId')
operation_type = self._get_param('OperationType')
group = self._get_param('UserGroup.1')
user_id = self._get_param('UserId.1')
if self.is_not_dryrun('ModifySnapshotAttribute'):
if (operation_type == 'add'):
self.ec2_backend.add_create_volume_permission(