Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Add filters to snapshots #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/AWS/EC2/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions test/test_EC2_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down