1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
module Fog
module AWS
class Compute
class Real
require 'fog/aws/parsers/compute/describe_image_attribute'
# Describes an image attribute value
#
# ==== Parameters
# * image_id<~String> - The ID of the image you want to describe an attribute of
# * attribute<~String> - The attribute to describe, must be one of the following:
# -'description'
# -'kernel'
# -'ramdisk'
# -'launchPermission'
# -'productCodes'
# -'blockDeviceMapping'
# -'sriovNetSupport'
#
# === Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'description'<~String> - The description for the AMI
# * 'imageId'<~String> - The ID of the image
# * 'kernelId'<~String> - The kernel ID
# * 'ramdiskId'<~String> - The RAM disk ID
# * 'blockDeviceMapping'<~List> - The block device mapping of the image
# * 'productCodes'<~List> - A list of product codes
# * 'sriovNetSupport'<~String> - The value to use for a resource attribute
# (Amazon API Reference)[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImageAttribute.html]
def describe_image_attribute(image_id, attribute)
request(
'Action' => 'DescribeImageAttribute',
'ImageId' => image_id,
'Attribute' => attribute,
:parser => Fog::Parsers::AWS::Compute::DescribeImageAttribute.new
)
end
end
class Mock
def describe_image_attribute(image_id, attribute)
response = Excon::Response.new
if image = self.data[:images].values.find{ |i| i['imageId'] == image_id }
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'imageId' => image_id
}
case attribute
when 'kernel'
response.body[attribute] = image["kernelId"]
when 'ramdisk'
response.body[attribute] = image["ramdiskId"]
when 'sriovNetSupport'
response.body[attribute] = 'simple'
when 'launchPermission'
if image_launch_permissions = self.data[:image_launch_permissions][image_id]
response.body[attribute] = image_launch_permissions[:users]
else
response.body[attribute] = []
end
else
response.body[attribute] = image[attribute]
end
response
else
raise Fog::AWS::Compute::NotFound.new("The Image '#{image_id}' does not exist")
end
end
end
end
end
end
|