1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/compute/requests/aws/describe_images.rb

115 lines
4.8 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module Compute
class AWS
2010-03-16 18:46:21 -04:00
class Real
2009-09-12 14:58:05 -04:00
2011-01-07 19:52:09 -05:00
require 'fog/compute/parsers/aws/describe_images'
2010-06-12 18:31:17 -04:00
2009-09-12 14:58:05 -04:00
# Describe all or specified images.
#
# ==== Params
# * filters<~Hash> - List of filters to limit results with
# * filters and/or the following
2009-09-12 14:58:05 -04:00
# * 'ExecutableBy'<~String> - Only return images that the executable_by
# user has explicit permission to launch
# * 'ImageId'<~Array> - Ids of images to describe
# * 'Owner'<~String> - Only return images belonging to owner.
#
# ==== Returns
# * response<~Excon::Response>:
2009-09-12 14:58:05 -04:00
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'imagesSet'<~Array>:
# * 'architecture'<~String> - Architecture of the image
# * 'blockDeviceMapping'<~Array> - An array of mapped block devices
# * 'description'<~String> - Description of image
2009-09-12 14:58:05 -04:00
# * 'imageId'<~String> - Id of the image
# * 'imageLocation'<~String> - Location of the image
# * 'imageOwnerId'<~String> - Id of the owner of the image
# * 'imageState'<~String> - State of the image
# * 'imageType'<~String> - Type of the image
# * 'isPublic'<~Boolean> - Whether or not the image is public
# * 'kernelId'<~String> - Kernel id associated with image, if any
# * 'platform'<~String> - Operating platform of the image
# * 'productCodes'<~Array> - Product codes for the image
# * 'ramdiskId'<~String> - Ramdisk id associated with image, if any
# * 'rootDeviceName'<~String> - Root device name, e.g. /dev/sda1
# * 'rootDeviceType'<~String> - Root device type, ebs or instance-store
# * 'virtualizationType'<~String> - Type of virtualization
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html]
def describe_images(filters = {})
options = {}
for key in ['ExecutableBy', 'ImageId', 'Owner']
2010-10-12 14:00:59 -04:00
if filters.is_a?(Hash) && filters.key?(key)
options[key] = filters.delete(key)
end
2009-09-12 14:58:05 -04:00
end
params = Fog::AWS.indexed_filters(filters).merge!(options)
2009-09-12 14:58:05 -04:00
request({
'Action' => 'DescribeImages',
:idempotent => true,
:parser => Fog::Parsers::Compute::AWS::DescribeImages.new
}.merge!(params))
end
2009-09-12 14:58:05 -04:00
end
2009-09-12 14:58:05 -04:00
2010-03-16 18:46:21 -04:00
class Mock
def describe_images(filters = {})
unless filters.is_a?(Hash)
Formatador.display_line("[yellow][WARN] describe_images with #{filters.class} param is deprecated, use describe_snapshots('snapshot-id' => []) instead[/] [light_black](#{caller.first})[/]")
filters = {'snapshot-id' => [*filters]}
end
if filters.keys.any? {|key| key =~ /^block-device/}
Formatador.display_line("[yellow][WARN] describe_images block-device-mapping filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_images tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
response = Excon::Response.new
aliases = {
'architecture' => 'architecture',
'description' => 'description',
'hypervisor' => 'hypervisor',
'image-id' => 'imageId',
'image-type' => 'imageType',
'is-public' => 'isPublic',
'kernel-id' => 'kernelId',
'manifest-location' => 'manifestLocation',
'name' => 'name',
'owner-id' => 'imageOwnerId',
'ramdisk-id' => 'ramdiskId',
'root-device-name' => 'rootDeviceName',
'root-device-type' => 'rootDeviceType',
'state' => 'imageState',
'virtualization-type' => 'virtualizationType'
}
2011-05-19 18:35:33 -04:00
image_set = self.data[:images].values
for filter_key, filter_value in filters
aliased_key = aliases[filter_key]
image_set = image_set.reject{|image| ![*filter_value].include?(image[aliased_key])}
end
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'imagesSet' => image_set
}
response
2009-09-12 14:58:05 -04:00
end
end
end
end
end