Class: AWS::EC2::Snapshot

Inherits:
Resource 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

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from HasPermissions

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

Methods included from TaggedItem

#add_tag, #cached_tags, #clear_tags, #tagging_resource_type, #tags

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(id, options = {}) ⇒ Snapshot

Returns a new instance of Snapshot.



58
59
60
61
# File 'lib/aws/ec2/snapshot.rb', line 58

def initialize id, options = {}
  @id = id
  super(options)
end

Instance Attribute Details

#descriptionString (readonly)

The description of the snapshot provided at snapshot initiation.

Returns:

  • (String)

    the current value of description



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def description
  @description
end

#idString (readonly)

Returns the snapshot’s ID.

Returns:

  • (String)

    Returns the snapshot’s ID.



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

def id
  @id
end

#owner_idString (readonly)

The AWS account ID of the snapshot owner.

Returns:

  • (String)

    the current value of owner_id



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def owner_id
  @owner_id
end

#progressInteger (readonly)

The progress of the snapshot as a percentage.

Returns:

  • (Integer)

    the current value of progress



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def progress
  @progress
end

#start_timeTime (readonly)

The time at which the snapshot was initiated.

Returns:

  • (Time)

    the current value of start_time



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

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



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

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



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

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



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def volume_size
  @volume_size
end

Instance Method Details

#__permissions_attribute__Object



136
137
138
# File 'lib/aws/ec2/snapshot.rb', line 136

def __permissions_attribute__
  "createVolumePermission"
end

#create_volume(availability_zone, options = {}) ⇒ 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.

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

    Additional options for creating the volume

Options Hash (options):

  • size (Integer)

    The desired size (in gigabytes) for the volume.

Returns:

  • (Volume)

    The newly created volume



114
115
116
117
118
119
120
# File 'lib/aws/ec2/snapshot.rb', line 114

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

#deletenil

Deletes the snapshot.

Returns:

  • (nil)


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

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

#exists?Boolean

Returns True if the snapshot exists.

Returns:

  • (Boolean)

    True if the snapshot exists.



123
124
125
126
127
128
# File 'lib/aws/ec2/snapshot.rb', line 123

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.



131
132
133
# File 'lib/aws/ec2/snapshot.rb', line 131

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