Implement ec2.register_image() (#3177)
* implement register_image * format code
This commit is contained in:
parent
936c7c80f1
commit
2504a398f9
@ -1516,6 +1516,19 @@ class AmiBackend(object):
|
||||
|
||||
return True
|
||||
|
||||
def register_image(self, name=None, description=None):
|
||||
ami_id = random_ami_id()
|
||||
ami = Ami(
|
||||
self,
|
||||
ami_id,
|
||||
instance=None,
|
||||
source_ami=None,
|
||||
name=name,
|
||||
description=description,
|
||||
)
|
||||
self.amis[ami_id] = ami
|
||||
return ami
|
||||
|
||||
def remove_launch_permission(self, ami_id, user_ids=None, group=None):
|
||||
ami = self.describe_images(ami_ids=[ami_id])[0]
|
||||
self.validate_permission_targets(user_ids=user_ids, group=group)
|
||||
|
@ -73,8 +73,12 @@ class AmisResponse(BaseResponse):
|
||||
return MODIFY_IMAGE_ATTRIBUTE_RESPONSE
|
||||
|
||||
def register_image(self):
|
||||
name = self.querystring.get("Name")[0]
|
||||
description = self._get_param("Description", if_none="")
|
||||
if self.is_not_dryrun("RegisterImage"):
|
||||
raise NotImplementedError("AMIs.register_image is not yet implemented")
|
||||
image = self.ec2_backend.register_image(name, description)
|
||||
template = self.response_template(REGISTER_IMAGE_RESPONSE)
|
||||
return template.render(image=image)
|
||||
|
||||
def reset_image_attribute(self):
|
||||
if self.is_not_dryrun("ResetImageAttribute"):
|
||||
@ -190,3 +194,8 @@ MODIFY_IMAGE_ATTRIBUTE_RESPONSE = """
|
||||
<return>true</return>
|
||||
</ModifyImageAttributeResponse>
|
||||
"""
|
||||
|
||||
REGISTER_IMAGE_RESPONSE = """<RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<imageId>{{ image.id }}</imageId>
|
||||
</RegisterImageResponse>"""
|
||||
|
@ -773,6 +773,16 @@ def test_ami_describe_non_existent():
|
||||
img.load()
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_ami_registration():
|
||||
ec2 = boto3.client("ec2", region_name="us-east-1")
|
||||
image_id = ec2.register_image(Name="test-register-image").get("ImageId", "")
|
||||
images = ec2.describe_images(ImageIds=[image_id]).get("Images", [])
|
||||
assert images[0]["Name"] == "test-register-image", "No image was registered."
|
||||
assert images[0]["RootDeviceName"] == "/dev/sda1", "Wrong root device name."
|
||||
assert images[0]["State"] == "available", "State should be available."
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_ami_filter_wildcard():
|
||||
ec2_resource = boto3.resource("ec2", region_name="us-west-1")
|
||||
|
Loading…
Reference in New Issue
Block a user