Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add filters to snapshots #47

Open
wants to merge 3 commits into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 27, 2011
  1. @stw
  2. @stw

    fixed params

    stw authored
  3. @stw

    remove debugging

    stw authored
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +7 −0 lib/AWS/EC2/snapshots.rb
  2. +14 −0 test/test_EC2_snapshots.rb
View
7 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
View
14 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)
Something went wrong with that request. Please try again.