From 4738e6d4136b154f2c91efd45183f50bef0a8f11 Mon Sep 17 00:00:00 2001 From: Steve Walker Date: Wed, 27 Apr 2011 16:02:19 -0400 Subject: [PATCH 1/3] Added filters to describe snapshots --- lib/AWS/EC2/snapshots.rb | 8 ++++++++ test/test_EC2_snapshots.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/AWS/EC2/snapshots.rb b/lib/AWS/EC2/snapshots.rb index e339517..5bd06d1 100644 --- a/lib/AWS/EC2/snapshots.rb +++ b/lib/AWS/EC2/snapshots.rb @@ -9,12 +9,20 @@ class Base < AWS::Base # @option options [optional,Array] :snapshot_id ([]) The ID of the Amazon EBS snapshot. # @option options [optional,String] :owner ('') Returns snapshots owned by the specified owner. Multiple owners can be specified. Valid values self | amazon | AWS Account ID # @option options [optional,String] :restorable_by ('') Account ID of a user that can create volumes from the snapshot. + # @option options [optional,String] :filter_names ([]) Names of filters you would like to apply + # @option options [optional,Array] :filter_values ([]) Values of filters you would like to apply # def describe_snapshots( options = {} ) params = {} params.merge!(pathlist("SnapshotId", options[:snapshot_id] )) unless options[:snapshot_id].nil? || options[:snapshot_id] == [] params["RestorableBy"] = options[:restorable_by] unless options[:restorable_by].nil? params["Owner"] = options[:owner] unless options[:owner].nil? + + names = options[:filter_names] unless options[:filter_names].nil? + names && names.each_with_index do |name, i| + params["Filter.#{i+1}.Name"] = options[:filter_values][i] if !options[:filter_values][i].nil? + end + return response_generator(:action => "DescribeSnapshots", :params => params) end diff --git a/test/test_EC2_snapshots.rb b/test/test_EC2_snapshots.rb index 1a13513..8315a37 100644 --- a/test/test_EC2_snapshots.rb +++ b/test/test_EC2_snapshots.rb @@ -58,6 +58,19 @@ response.progress.should.equal "80%" end + specify "should be able to be described with describe_snapshots and filters" do + @ec2.stubs(:make_request).with('DescribeSnapshots', {"Filter.1.Name"=>"vol-4d826724"}). + returns stub(:body => @describe_snapshots_response_body, :is_a? => true) + + @ec2.describe_snapshots(:filter_names => ['volume-id'], :filter_values => ['vol-4d826724']).should.be.an.instance_of Hash + + response = @ec2.describe_snapshots(:filter_names => ['volume-id'], :filter_values => ['vol-4d826724']) + response.snapshotId.should.equal "snap-78a54011" + response.volumeId.should.equal "vol-4d826724" + response.status.should.equal "pending" + response.progress.should.equal "80%" + end + specify "should be able to be created with a volume_id" do @ec2.stubs(:make_request).with('CreateSnapshot', {"VolumeId" => "vol-4d826724"}). returns stub(:body => @create_snapshot_response_body, :is_a? => true) From ad4b7e5aea503a72d5da3a1326a56fd6414330c7 Mon Sep 17 00:00:00 2001 From: Steve Walker Date: Wed, 27 Apr 2011 16:13:20 -0400 Subject: [PATCH 2/3] fixed params --- lib/AWS/EC2/snapshots.rb | 5 +++-- test/test_EC2_snapshots.rb | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/AWS/EC2/snapshots.rb b/lib/AWS/EC2/snapshots.rb index 5bd06d1..17cea64 100644 --- a/lib/AWS/EC2/snapshots.rb +++ b/lib/AWS/EC2/snapshots.rb @@ -20,9 +20,10 @@ def describe_snapshots( options = {} ) names = options[:filter_names] unless options[:filter_names].nil? names && names.each_with_index do |name, i| - params["Filter.#{i+1}.Name"] = options[:filter_values][i] if !options[:filter_values][i].nil? + params["Filter.#{i+1}.Name"] = name + params["Filter.#{i+1}.Value"] = options[:filter_values][i] if !options[:filter_values][i].nil? end - + puts "Params: #{params.inspect}" return response_generator(:action => "DescribeSnapshots", :params => params) end diff --git a/test/test_EC2_snapshots.rb b/test/test_EC2_snapshots.rb index 8315a37..7b20368 100644 --- a/test/test_EC2_snapshots.rb +++ b/test/test_EC2_snapshots.rb @@ -59,7 +59,8 @@ end specify "should be able to be described with describe_snapshots and filters" do - @ec2.stubs(:make_request).with('DescribeSnapshots', {"Filter.1.Name"=>"vol-4d826724"}). + @ec2.stubs(:make_request).with('DescribeSnapshots', + {'Filter.1.Name' => 'volume-id', 'Filter.1.Value' => 'vol-4d826724'}). returns stub(:body => @describe_snapshots_response_body, :is_a? => true) @ec2.describe_snapshots(:filter_names => ['volume-id'], :filter_values => ['vol-4d826724']).should.be.an.instance_of Hash From dbd12c1b600ab4fb5da9b9124460cf11bad50465 Mon Sep 17 00:00:00 2001 From: Steve Walker Date: Wed, 27 Apr 2011 16:16:12 -0400 Subject: [PATCH 3/3] remove debugging --- lib/AWS/EC2/snapshots.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/AWS/EC2/snapshots.rb b/lib/AWS/EC2/snapshots.rb index 17cea64..75c1e05 100644 --- a/lib/AWS/EC2/snapshots.rb +++ b/lib/AWS/EC2/snapshots.rb @@ -17,13 +17,11 @@ def describe_snapshots( options = {} ) params.merge!(pathlist("SnapshotId", options[:snapshot_id] )) unless options[:snapshot_id].nil? || options[:snapshot_id] == [] params["RestorableBy"] = options[:restorable_by] unless options[:restorable_by].nil? params["Owner"] = options[:owner] unless options[:owner].nil? - names = options[:filter_names] unless options[:filter_names].nil? names && names.each_with_index do |name, i| params["Filter.#{i+1}.Name"] = name params["Filter.#{i+1}.Value"] = options[:filter_values][i] if !options[:filter_values][i].nil? end - puts "Params: #{params.inspect}" return response_generator(:action => "DescribeSnapshots", :params => params) end