clean up instance attribute modification and add base AMI stuff
This commit is contained in:
parent
301c23a499
commit
351aca3c68
6 changed files with 210 additions and 46 deletions
|
|
@ -1,21 +1,37 @@
|
|||
from jinja2 import Template
|
||||
|
||||
from moto.ec2.models import ec2_backend
|
||||
from moto.ec2.utils import resource_ids_from_querystring
|
||||
from moto.ec2.utils import instance_ids_from_querystring
|
||||
|
||||
|
||||
class AMIs(object):
|
||||
class AmisResponse(object):
|
||||
def __init__(self, querystring):
|
||||
self.querystring = querystring
|
||||
self.instance_ids = instance_ids_from_querystring(querystring)
|
||||
|
||||
def create_image(self):
|
||||
raise NotImplementedError('AMIs.create_image is not yet implemented')
|
||||
name = self.querystring.get('Name')[0]
|
||||
description = self.querystring.get('Description')[0]
|
||||
instance_id = self.instance_ids[0]
|
||||
image = ec2_backend.create_image(instance_id, name, description)
|
||||
if not image:
|
||||
return "There is not instance with id {}".format(instance_id), dict(status=404)
|
||||
template = Template(CREATE_IMAGE_RESPONSE)
|
||||
return template.render(image=image)
|
||||
|
||||
def deregister_image(self):
|
||||
raise NotImplementedError('AMIs.deregister_image is not yet implemented')
|
||||
ami_id = self.querystring.get('ImageId')[0]
|
||||
success = ec2_backend.deregister_image(ami_id)
|
||||
template = Template(DESCRIBE_IMAGES_RESPONSE)
|
||||
return template.render(success=str(success).lower())
|
||||
|
||||
def describe_image_attribute(self):
|
||||
raise NotImplementedError('AMIs.describe_image_attribute is not yet implemented')
|
||||
|
||||
def describe_images(self):
|
||||
raise NotImplementedError('AMIs.describe_images is not yet implemented')
|
||||
images = ec2_backend.describe_images()
|
||||
template = Template(DESCRIBE_IMAGES_RESPONSE)
|
||||
return template.render(images=images)
|
||||
|
||||
def modify_image_attribute(self):
|
||||
raise NotImplementedError('AMIs.modify_image_attribute is not yet implemented')
|
||||
|
|
@ -26,3 +42,61 @@ class AMIs(object):
|
|||
def reset_image_attribute(self):
|
||||
raise NotImplementedError('AMIs.reset_image_attribute is not yet implemented')
|
||||
|
||||
|
||||
CREATE_IMAGE_RESPONSE = """<CreateImageResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<imageId>{{ image.id }}</imageId>
|
||||
</CreateImageResponse>"""
|
||||
|
||||
# TODO almost all of these params should actually be templated based on the ec2 image
|
||||
DESCRIBE_IMAGES_RESPONSE = """<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<imagesSet>
|
||||
{% for image in images %}
|
||||
<item>
|
||||
<imageId>{{ image.id }}</imageId>
|
||||
<imageLocation>amazon/getting-started</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>111122223333</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<architecture>i386</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>{{ image.kernel_id }}</kernelId>
|
||||
<ramdiskId>ari-1a2b3c4d</ramdiskId>
|
||||
<imageOwnerAlias>amazon</imageOwnerAlias>
|
||||
<name>{{ image.name }}</name>
|
||||
<description>{{ image.description }}</description>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda</rootDeviceName>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/sda1</deviceName>
|
||||
<ebs>
|
||||
<snapshotId>snap-1a2b3c4d</snapshotId>
|
||||
<volumeSize>15</volumeSize>
|
||||
<deleteOnTermination>false</deleteOnTermination>
|
||||
<volumeType>standard</volumeType>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<virtualizationType>{{ image.virtualization_type }}</virtualizationType>
|
||||
<tagSet/>
|
||||
<hypervisor>xen</hypervisor>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</imagesSet>
|
||||
</DescribeImagesResponse>"""
|
||||
|
||||
DESCRIBE_IMAGE_RESPONSE = """<DescribeImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<imageId>{{ image.id }}</imageId>
|
||||
<{{ key }}>
|
||||
<value>{{ value }}</value>
|
||||
</{{key }}>
|
||||
</DescribeImageAttributeResponse>"""
|
||||
|
||||
DEREGISTER_IMAGE_RESPONSE = """<DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<return>{{ success }}</return>
|
||||
</DeregisterImageResponse>"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue