Implement ImageId parameter in DescribeImages

This commit is contained in:
Ilya Sukhanov 2013-08-29 23:06:11 -04:00
parent b5a454e0da
commit a63601e481
3 changed files with 17 additions and 4 deletions

View File

@ -215,8 +215,12 @@ class AmiBackend(object):
self.amis[ami_id] = ami
return ami
def describe_images(self):
return self.amis.values()
def describe_images(self, ami_ids=None):
if ami_ids:
images = [image for image in self.amis.values() if image.id in ami_ids]
else:
images = self.amis.values()
return images
def deregister_image(self, ami_id):
if ami_id in self.amis:

View File

@ -1,7 +1,7 @@
from jinja2 import Template
from moto.ec2.models import ec2_backend
from moto.ec2.utils import instance_ids_from_querystring
from moto.ec2.utils import instance_ids_from_querystring, image_ids_from_querystring
class AmisResponse(object):
@ -33,7 +33,8 @@ class AmisResponse(object):
raise NotImplementedError('AMIs.describe_image_attribute is not yet implemented')
def describe_images(self):
images = ec2_backend.describe_images()
ami_ids = image_ids_from_querystring(self.querystring)
images = ec2_backend.describe_images(ami_ids=ami_ids)
template = Template(DESCRIBE_IMAGES_RESPONSE)
return template.render(images=images)

View File

@ -54,6 +54,14 @@ def instance_ids_from_querystring(querystring_dict):
return instance_ids
def image_ids_from_querystring(querystring_dict):
image_ids = []
for key, value in querystring_dict.iteritems():
if 'ImageId' in key:
image_ids.append(value[0])
return image_ids
def resource_ids_from_querystring(querystring_dict):
prefix = 'ResourceId'
response_values = {}