Class: AWS::EC2::Snapshot

Inherits:
Resource
  • Object
show all
Includes:
HasPermissions, TaggedItem
Defined in:
lib/aws/ec2/snapshot.rb

Overview

Represents an Amazon EBS snapshot.

Examples:

Taking a snapshot from a volume

snapshot = volume.create_snapshot("Database Backup 12/21/2010")
sleep 1 until [:completed, :error].include?(snapshot.status)

Managing snapshot permissions

unless snapshot.public?
  snapshot.permissions.add("12345678901")
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #clear_tags, #tags

Methods included from HasPermissions

#permissions, #private?, #public=, #public?

Instance Attribute Details

#descriptionString (readonly)

The description of the snapshot provided at snapshot initiation.

Returns:

  • (String)

    the current value of description



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def description
  @description
end

#idObject (readonly)

The snapshot ID



63
64
65
# File 'lib/aws/ec2/snapshot.rb', line 63

def id
  @id
end

#owner_idString (readonly)

The AWS account ID of the snapshot owner.

Returns:

  • (String)

    the current value of owner_id



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def owner_id
  @owner_id
end

#progressInteger (readonly)

The progress of the snapshot as a percentage.

Returns:

  • (Integer)

    the current value of progress



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def progress
  @progress
end

#start_timeTime (readonly)

The time at which the snapshot was initiated.

Returns:

  • (Time)

    the current value of start_time



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def start_time
  @start_time
end

#statusSymbol (readonly)

The status of the snapshot. Possible values:

  • :pending

  • :completed

  • :error

Returns:

  • (Symbol)

    the current value of status



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def status
  @status
end

#volume_idString (readonly)

The ID of the volume this snapshot was created from.

Returns:

  • (String)

    the current value of volume_id



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def volume_id
  @volume_id
end

#volume_sizeInteger (readonly)

The size of the volume from which the snapshot was created.

Returns:

  • (Integer)

    the current value of volume_size



56
57
58
# File 'lib/aws/ec2/snapshot.rb', line 56

def volume_size
  @volume_size
end

Instance Method Details

#create_volume(availability_zone, opts = {}) ⇒ Volume

Creates a volume from the snapshot.

Parameters:

  • availability_zone (AvailabilityZone or String)

    The Availability Zone in which to create the new volume. See AWS::EC2#availability_zones for how to get a list of availability zones.

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

    Additional options for creating the volume

Options Hash (opts):

  • size (Integer)

    The desired size (in gigabytes) for the volume.

Returns:

  • (Volume)

    The newly created volume



89
90
91
92
93
# File 'lib/aws/ec2/snapshot.rb', line 89

def create_volume(availability_zone, opts = {})
  VolumeCollection.new(:config => config).
    create(opts.merge(:snapshot => self,
                      :availability_zone => availability_zone))
end

#deleteObject

Deletes the snapshot.



72
73
74
# File 'lib/aws/ec2/snapshot.rb', line 72

def delete
  client.delete_snapshot(:snapshot_id => id)
end

#exists?Boolean

Returns True if the snapshot exists.

Returns:

  • (Boolean)

    True if the snapshot exists.



96
97
98
99
100
101
# File 'lib/aws/ec2/snapshot.rb', line 96

def exists?
  resp =
    client.describe_snapshots(:filters => [{ :name => 'snapshot-id',
                                             :values => [id] }]) and
    !resp.snapshot_set.empty?
end

#volumeVolume

Returns The volume this snapshot was created from.

Returns:

  • (Volume)

    The volume this snapshot was created from.



106
107
108
# File 'lib/aws/ec2/snapshot.rb', line 106

def volume
  Volume.new(volume_id, :config => config) if volume_id
end