Class: AWS::EC2::VolumeCollection

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

Overview

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

Examples:

Create an empty 15GiB volume

ec2.volumes.create(:size => 15,
                   :availability_zone => "us-east-1a")

Get a volume by ID

volume = ec2.volumes["vol-123"]
volume.exists?

Get a map of volume IDs to volume status

ec2.volumes.inject({}) { |m, v| m[i.id] = v.status; m }
# => { "vol-12345678" => :available, "vol-87654321" => :in_use }

Instance Method Summary collapse

Instance Method Details

#create(opts = {}) ⇒ Volume

Creates a new Amazon EBS volume that any Amazon EC2 instance in the same Availability Zone can attach to. For more information about Amazon EBS, go to the Amazon Elastic Compute Cloud User Guide.

Parameters:

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

    Options for creating the volume. :availability_zone and one of :size, :snapshot, or :snapshot_id is required.

Options Hash (opts):

  • :size (Integer)

    The size of the volume, in GiBs. Valid values: 1 - 1024. If :snapshot or :snapshot_id is specified, this defaults to the size of the specified snapshot.

  • :snapshot (Snapshot)

    The snapshot from which to create the new volume.

  • :snapshot_id (String)

    The ID of the snapshot from which to create the new volume.

  • :availability_zone (String, AvailabilityZone)

    The Availability Zone in which to create the new volume. To get a list of the availability zones you can use, see AWS::EC2#availability_zones.

Returns:

  • (Volume)

    An object representing the new volume.

  • (Volume)


78
79
80
81
82
83
84
# File 'lib/aws/ec2/volume_collection.rb', line 78

def create(opts = {})
  if snapshot = opts.delete(:snapshot)
    opts[:snapshot_id] = snapshot.id
  end
  resp = client.create_volume(opts)
  Volume.new(resp.volume_id, :config => config)
end

#each {|Instance| ... } ⇒ nil

Yields:

  • (Instance)

    Yields each volume in the collection.

Returns:

  • (nil)


41
42
43
44
45
46
47
48
# File 'lib/aws/ec2/volume_collection.rb', line 41

def each(&block)
  resp = filtered_request(:describe_volumes)
  resp.volume_set.each do |v|
    volume = Volume.new(v.volume_id, :config => config)
    yield(volume)
  end
  nil
end