From 68209cb97bcacda59a5ed048b1227e3b4ab284ff Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Fri, 3 Jul 2009 12:09:38 -0700 Subject: [PATCH] add describe images spec --- lib/fog/aws/ec2.rb | 25 +++++++++++++++++ lib/fog/aws/ec2/parsers.rb | 41 ++++++++++++++++++++++++++++ spec/aws/ec2/describe_images_spec.rb | 20 ++++++++++++++ spec/aws/simpledb/select_spec.rb | 7 +++++ 4 files changed, 93 insertions(+) create mode 100644 spec/aws/ec2/describe_images_spec.rb create mode 100644 spec/aws/simpledb/select_spec.rb diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index d07b32722..14d5ba652 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -109,6 +109,31 @@ module Fog }.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new) end + # Describe all or specified images. + # + # ==== Params + # :options<~Hash>:: Optional params + # :executable_by<~String>:: Only return images the user specified by + # executable_by has explicit permission to launch + # :image_id<~Array>:: Ids of images to describe + # :owner<~String>:: Only return images belonging to owner. + # + # ==== Returns + def describe_images(options = {}) + params, index = {}, 1 + if options[:image_id] + for image in [*options[:image_id]] + params["ImageId.#{index}"] = image + image += 1 + end + end + request({ + 'Action' => 'DescribeImages', + 'ExecutableBy' => options[:executable_by], + 'Owner' => options[:owner] + }.merge!(params), Fog::Parsers::AWS::EC2::DescribeImages.new) + end + # Describe all or specified volumes. # # ==== Parameters diff --git a/lib/fog/aws/ec2/parsers.rb b/lib/fog/aws/ec2/parsers.rb index da3183aa4..aa2ef01a2 100644 --- a/lib/fog/aws/ec2/parsers.rb +++ b/lib/fog/aws/ec2/parsers.rb @@ -81,6 +81,47 @@ module Fog end + class DescribeImages < Fog::Parsers::Base + + def reset + @image = {} + @response = { :image_set => [] } + end + + def end_element(name) + case name + when 'architecture' + @image[:architecture] = @value + when 'imageId' + @image[:image_id] = @value + when 'imageLocation' + @image[:image_location] = @value + when 'imageOwnerId' + @image[:image_owner_id] = @value + when 'imageState' + @image[:image_state] = @value + when 'imageType' + @image[:image_type] = @value + when 'isPublic' + if @value == 'true' + @image[:is_public] = true + else + @image[:is_public] = false + end + when 'item' + @response[:image_set] << @image + @image = {} + when 'kernelId' + @image[:kernel_id] = @value + when 'ramdiskId' + @image[:ramdisk_id] = @value + when 'requestId' + @response[:request_id] = @value + end + end + + end + class DescribeVolumes < Fog::Parsers::Base def reset diff --git a/spec/aws/ec2/describe_images_spec.rb b/spec/aws/ec2/describe_images_spec.rb new file mode 100644 index 000000000..2a7777553 --- /dev/null +++ b/spec/aws/ec2/describe_images_spec.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.describe_images' do + + it "should return proper attributes with no params" do + actual = ec2.describe_images + actual.body[:request_id].should be_a(String) + image = actual.body[:image_set].first + image[:architecture].should be_a(String) + image[:image_id].should be_a(String) + image[:image_location].should be_a(String) + image[:image_owner_id].should be_a(String) + image[:image_state].should be_a(String) + image[:image_type].should be_a(String) + [false, true].should include(image[:is_public]) + end + + it "should return proper attributes with params" + +end diff --git a/spec/aws/simpledb/select_spec.rb b/spec/aws/simpledb/select_spec.rb new file mode 100644 index 000000000..07e21aa7e --- /dev/null +++ b/spec/aws/simpledb/select_spec.rb @@ -0,0 +1,7 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'SimpleDB.select' do + + it "should have some specs" + +end \ No newline at end of file