Implement ImageId parameter in DescribeImages
This commit is contained in:
		
							parent
							
								
									b5a454e0da
								
							
						
					
					
						commit
						a63601e481
					
				@ -215,8 +215,12 @@ class AmiBackend(object):
 | 
				
			|||||||
        self.amis[ami_id] = ami
 | 
					        self.amis[ami_id] = ami
 | 
				
			||||||
        return ami
 | 
					        return ami
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def describe_images(self):
 | 
					    def describe_images(self, ami_ids=None):
 | 
				
			||||||
        return self.amis.values()
 | 
					        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):
 | 
					    def deregister_image(self, ami_id):
 | 
				
			||||||
        if ami_id in self.amis:
 | 
					        if ami_id in self.amis:
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
from jinja2 import Template
 | 
					from jinja2 import Template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from moto.ec2.models import ec2_backend
 | 
					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):
 | 
					class AmisResponse(object):
 | 
				
			||||||
@ -33,7 +33,8 @@ class AmisResponse(object):
 | 
				
			|||||||
        raise NotImplementedError('AMIs.describe_image_attribute is not yet implemented')
 | 
					        raise NotImplementedError('AMIs.describe_image_attribute is not yet implemented')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def describe_images(self):
 | 
					    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)
 | 
					        template = Template(DESCRIBE_IMAGES_RESPONSE)
 | 
				
			||||||
        return template.render(images=images)
 | 
					        return template.render(images=images)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -54,6 +54,14 @@ def instance_ids_from_querystring(querystring_dict):
 | 
				
			|||||||
    return instance_ids
 | 
					    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):
 | 
					def resource_ids_from_querystring(querystring_dict):
 | 
				
			||||||
    prefix = 'ResourceId'
 | 
					    prefix = 'ResourceId'
 | 
				
			||||||
    response_values = {}
 | 
					    response_values = {}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user