Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

View file

@ -4,76 +4,83 @@ from moto.ec2.utils import filters_from_querystring
class AmisResponse(BaseResponse):
def create_image(self):
name = self.querystring.get('Name')[0]
description = self._get_param('Description', if_none='')
instance_id = self._get_param('InstanceId')
if self.is_not_dryrun('CreateImage'):
name = self.querystring.get("Name")[0]
description = self._get_param("Description", if_none="")
instance_id = self._get_param("InstanceId")
if self.is_not_dryrun("CreateImage"):
image = self.ec2_backend.create_image(
instance_id, name, description, context=self)
instance_id, name, description, context=self
)
template = self.response_template(CREATE_IMAGE_RESPONSE)
return template.render(image=image)
def copy_image(self):
source_image_id = self._get_param('SourceImageId')
source_region = self._get_param('SourceRegion')
name = self._get_param('Name')
description = self._get_param('Description')
if self.is_not_dryrun('CopyImage'):
source_image_id = self._get_param("SourceImageId")
source_region = self._get_param("SourceRegion")
name = self._get_param("Name")
description = self._get_param("Description")
if self.is_not_dryrun("CopyImage"):
image = self.ec2_backend.copy_image(
source_image_id, source_region, name, description)
source_image_id, source_region, name, description
)
template = self.response_template(COPY_IMAGE_RESPONSE)
return template.render(image=image)
def deregister_image(self):
ami_id = self._get_param('ImageId')
if self.is_not_dryrun('DeregisterImage'):
ami_id = self._get_param("ImageId")
if self.is_not_dryrun("DeregisterImage"):
success = self.ec2_backend.deregister_image(ami_id)
template = self.response_template(DEREGISTER_IMAGE_RESPONSE)
return template.render(success=str(success).lower())
def describe_images(self):
ami_ids = self._get_multi_param('ImageId')
ami_ids = self._get_multi_param("ImageId")
filters = filters_from_querystring(self.querystring)
owners = self._get_multi_param('Owner')
exec_users = self._get_multi_param('ExecutableBy')
owners = self._get_multi_param("Owner")
exec_users = self._get_multi_param("ExecutableBy")
images = self.ec2_backend.describe_images(
ami_ids=ami_ids, filters=filters, exec_users=exec_users,
owners=owners, context=self)
ami_ids=ami_ids,
filters=filters,
exec_users=exec_users,
owners=owners,
context=self,
)
template = self.response_template(DESCRIBE_IMAGES_RESPONSE)
return template.render(images=images)
def describe_image_attribute(self):
ami_id = self._get_param('ImageId')
ami_id = self._get_param("ImageId")
groups = self.ec2_backend.get_launch_permission_groups(ami_id)
users = self.ec2_backend.get_launch_permission_users(ami_id)
template = self.response_template(DESCRIBE_IMAGE_ATTRIBUTES_RESPONSE)
return template.render(ami_id=ami_id, groups=groups, users=users)
def modify_image_attribute(self):
ami_id = self._get_param('ImageId')
operation_type = self._get_param('OperationType')
group = self._get_param('UserGroup.1')
user_ids = self._get_multi_param('UserId')
if self.is_not_dryrun('ModifyImageAttribute'):
if (operation_type == 'add'):
ami_id = self._get_param("ImageId")
operation_type = self._get_param("OperationType")
group = self._get_param("UserGroup.1")
user_ids = self._get_multi_param("UserId")
if self.is_not_dryrun("ModifyImageAttribute"):
if operation_type == "add":
self.ec2_backend.add_launch_permission(
ami_id, user_ids=user_ids, group=group)
elif (operation_type == 'remove'):
ami_id, user_ids=user_ids, group=group
)
elif operation_type == "remove":
self.ec2_backend.remove_launch_permission(
ami_id, user_ids=user_ids, group=group)
ami_id, user_ids=user_ids, group=group
)
return MODIFY_IMAGE_ATTRIBUTE_RESPONSE
def register_image(self):
if self.is_not_dryrun('RegisterImage'):
raise NotImplementedError(
'AMIs.register_image is not yet implemented')
if self.is_not_dryrun("RegisterImage"):
raise NotImplementedError("AMIs.register_image is not yet implemented")
def reset_image_attribute(self):
if self.is_not_dryrun('ResetImageAttribute'):
if self.is_not_dryrun("ResetImageAttribute"):
raise NotImplementedError(
'AMIs.reset_image_attribute is not yet implemented')
"AMIs.reset_image_attribute is not yet implemented"
)
CREATE_IMAGE_RESPONSE = """<CreateImageResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">