Class: AWS::EC2::SnapshotCollection

Inherits:
Collection
  • Object
show all
Defined in:
lib/aws/ec2/snapshot_collection.rb

Overview

Represents a collection of Amazon EBS snapshots. Typically you should get an instance of this class by calling #snapshots.

Examples:

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")

Get a snapshot by ID

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

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 }

Instance Method Summary collapse

Instance Method Details

#create(opts = {}) ⇒ Snapshot

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.

Parameters:

  • opts (Hash) (defaults to: {})

    Options for creating the snapshot. Either :volume or :volume_id is required.

  • opts (Volume) (defaults to: {})

    :volume The Amazon EBS volume of which to take a snapshot.

  • opts (String) (defaults to: {})

    :volume_id The ID of the Amazon EBS volume of which to take a snapshot.

  • opts (String) (defaults to: {})

    :description An optional description of the snapshot. May contain up to 255 characters.

Returns:

  • (Snapshot)

    An object representing the new snapshot.



73
74
75
76
77
78
79
# File 'lib/aws/ec2/snapshot_collection.rb', line 73

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 {|Instance| ... } ⇒ nil

Yields:

  • (Instance)

    Yields each volume in the collection.

Returns:

  • (nil)


44
45
46
47
48
49
50
51
# File 'lib/aws/ec2/snapshot_collection.rb', line 44

def each(&block)
  resp = filtered_request(:describe_snapshots)
  resp.snapshot_set.each do |v|
    snapshot = Snapshot.new(v.snapshot_id, :config => config)
    yield(snapshot)
  end
  nil
end