diff --git a/lib/AWS/EC2/snapshots.rb b/lib/AWS/EC2/snapshots.rb index e339517..75c1e05 100644 --- a/lib/AWS/EC2/snapshots.rb +++ b/lib/AWS/EC2/snapshots.rb @@ -9,12 +9,19 @@ 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"] = name + params["Filter.#{i+1}.Value"] = 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..7b20368 100644 --- a/test/test_EC2_snapshots.rb +++ b/test/test_EC2_snapshots.rb @@ -58,6 +58,20 @@ 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' => '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 + + 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)