class AWS::EC2::SnapshotCollection

Represents a collection of Amazon EBS snapshots. Typically you should get an instance of this class by calling {AWS::EC2#snapshots}.

@example Create a snapshot from a volume

ec2.snapshots.create(:volume => ec2.volumes["vol-123"],
                     :description => "my snapshot")
# or:
ec2.volumes["vol-123"].create_snapshot("my snapshot")

@example Get a snapshot by ID

snapshot = ec2.snapshots["vol-123"]
snapshot.exists?

@example Get a map of snapshot IDs to snapshot status

ec2.snapshots.inject({}) { |m, s| m[i.id] = s.status; m }
# => { "snap-12345678" => :pending, "snap-87654321" => :completed }

Public Class Methods

new(options = {}) click to toggle source

@private

# File lib/aws/ec2/snapshot_collection.rb, line 39
def initialize(options = {})
  @owners = options[:owners] || []
  @restorable_by = options[:restorable_by] || []
  super(options)
end

Public Instance Methods

create(opts = {}) click to toggle source

Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to make identical copies of instance devices, and to save data before shutting down an instance. For more information about Amazon EBS, go to the Amazon Elastic Compute Cloud User Guide.

@return [Snapshot] An object representing the new snapshot.

@param [Hash] opts Options for creating the snapshot.

Either +:volume+ or +:volume_id+ is required.

@param opts [Volume] :volume The Amazon EBS volume of which

to take a snapshot.

@param opts [String] :volume_id The ID of the Amazon EBS

volume of which to take a snapshot.

@param opts [String] :description An optional description of

the snapshot.  May contain up to 255 characters.
# File lib/aws/ec2/snapshot_collection.rb, line 105
def create opts = {}
  if volume = opts.delete(:volume)
    opts[:volume_id] = volume.id
  end
  resp = client.create_snapshot(opts)
  Snapshot.new(resp.snapshot_id, :config => config)
end
each() { |snapshot| ... } click to toggle source

@yield [Instance] Yields each volume in the collection. @return [nil]

# File lib/aws/ec2/snapshot_collection.rb, line 47
def each(&block)
  opts = {}
  opts[:owner_ids] = @owners.map { |id| id.to_s } unless @owners.empty?
  opts[:restorable_by_user_ids] = @restorable_by.map { |id| id.to_s } unless
    @restorable_by.empty?
  resp = filtered_request(:describe_snapshots, opts)
  resp.snapshot_set.each do |v|
    snapshot = Snapshot.new(v.snapshot_id, :config => config)
    yield(snapshot)
  end
  nil
end
restorable_by(*users) click to toggle source

@return [ImageCollection] A new collection that only includes

images for which the specified user ID has explicit launch
permissions. The user ID can be an AWS account ID, +:self+
to return AMIs for which the sender of the request has
explicit launch permissions, or +:all+ to return AMIs with
public launch permissions.

@param [Array of Strings] users The AWS account IDs by which

the new collection should be filtered.
# File lib/aws/ec2/snapshot_collection.rb, line 81
def restorable_by(*users)
  collection_with(:restorable_by => @restorable_by + users)
end
with_owner(*owners) click to toggle source

@return [SnapshotCollection] A new collection that only

includes snapshots owned by one or more of the specified AWS
accounts.  The IDs +:amazon+ and +:self+ can be used to
include snapshots owned by Amazon or AMIs owned by you,
respectively.

@param [Array of Strings] owners The AWS account IDs by

which the new collection should be filtered.
# File lib/aws/ec2/snapshot_collection.rb, line 68
def with_owner(*owners)
  collection_with(:owners => @owners + owners)
end

Protected Instance Methods

member_class() click to toggle source

@private

# File lib/aws/ec2/snapshot_collection.rb, line 115
def member_class
  Snapshot
end
preserved_options() click to toggle source

@private

# File lib/aws/ec2/snapshot_collection.rb, line 121
def preserved_options
  super.merge(:owners => @owners, :restorable_by => @restorable_by)
end