1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

simple describe_images mock

This commit is contained in:
Wesley Beary 2009-09-12 11:58:05 -07:00
parent a25d38851e
commit d7aab6fe2a
2 changed files with 93 additions and 40 deletions

View file

@ -37,6 +37,29 @@ module Fog
hex(32)
end
def self.image
path = []
(rand(3) + 2).times do
path << letters(rand(9) + 8)
end
{
"imageOwnerId" => letters(rand(5) + 4),
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine"
}
end
def self.image_id
"ami-#{hex(8)}"
end
def self.key_fingerprint
fingerprint = []
20.times do
@ -79,6 +102,10 @@ module Fog
numbers(12)
end
def self.ramdisk_id
"ari-#{hex(8)}"
end
def self.request_id
request_id = []
request_id << hex(8)
@ -89,10 +116,6 @@ module Fog
request_id.join('-')
end
def self.ramdisk_id
"ari-#{hex(8)}"
end
def self.reservation_id
"r-#{hex(8)}"
end
@ -139,7 +162,7 @@ module Fog
def self.base64(length)
random_selection(
"ABCDEFGHIJKLMNOP QRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
length
)
end

View file

@ -1,41 +1,71 @@
module Fog
module AWS
class EC2
unless Fog.mocking?
# Describe all or specified images.
#
# ==== Params
# * options<~Hash> - Optional params
# * '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<~Fog::AWS::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'imagesSet'<~Array>:
# * 'architecture'<~String> - Architecture of the image
# * '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
def describe_images(options = {})
if image_id = options.delete('ImageId')
options.merge!(indexed_params('ImageId', image_id))
module Fog
module AWS
class EC2
# Describe all or specified images.
#
# ==== Params
# * options<~Hash> - Optional params
# * '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<~Fog::AWS::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'imagesSet'<~Array>:
# * 'architecture'<~String> - Architecture of the image
# * '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
def describe_images(options = {})
if image_id = options.delete('ImageId')
options.merge!(indexed_params('ImageId', image_id))
end
request({
'Action' => 'DescribeImages'
}.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
end
request({
'Action' => 'DescribeImages'
}.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
end
end
end
end
else
module Fog
module AWS
class EC2
def describe_images(options = {})
response = Fog::Response.new
images = []
(rand(101 + 100)).times do
images << Fog::AWS::Mock.image
end
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'imagesSet' => images
}
response
end
end
end
end
end