Class: AWS::EC2::Attachment

Inherits:
Resource show all
Defined in:
lib/aws/ec2/attachment.rb

Overview

Represents an attachment of an Amazon EBS volume to an instance.

Examples:

Create an empty 15GiB volume and attach it to an instance

volume = ec2.volumes.create(:size => 15,
                            :availability_zone => "us-east-1a")
attachment = volume.attach_to(ec2.instances["i-123"], "/dev/sdf")
sleep 1 until attachment.status != :attaching

Remove all attachments from a volume and then delete it

volume.attachments.each do |attachment|
  attachment.delete(:force => true)
end
sleep 1 until volume.status == :available
volume.delete

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

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(volume, instance, device, options = {}) ⇒ Attachment

Returns a new instance of Attachment.


34
35
36
37
38
39
# File 'lib/aws/ec2/attachment.rb', line 34

def initialize volume, instance, device, options = {}
  @volume = volume
  @instance = instance
  @device = device
  super
end

Instance Attribute Details

#deviceString (readonly)

Returns how the device is exposed to the instance (e.g. '/dev/sdh')

Returns:

  • (String)

    Returns how the device is exposed to the instance (e.g. '/dev/sdh')


49
50
51
# File 'lib/aws/ec2/attachment.rb', line 49

def device
  @device
end

#instanceInstance (readonly)

Returns the EC2 instance the volume is attached to.

Returns:

  • (Instance)

    Returns the EC2 instance the volume is attached to.


45
46
47
# File 'lib/aws/ec2/attachment.rb', line 45

def instance
  @instance
end

#volumeVolume (readonly)

Returns the volume that is attached.

Returns:

  • (Volume)

    Returns the volume that is attached.


42
43
44
# File 'lib/aws/ec2/attachment.rb', line 42

def volume
  @volume
end

Instance Method Details

#attach_timeTime

Returns the time at which this attachment was created.

Returns:

  • (Time)

    Returns the time at which this attachment was created.


62
# File 'lib/aws/ec2/attachment.rb', line 62

attribute :attach_time

#delete(options = {}) ⇒ Object

Detaches the volume from its instance.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :force (Boolean)

    Forces detachment if the previous detachment attempt did not occur cleanly (logging into an instance, unmounting the volume, and detaching normally). This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.


107
108
109
# File 'lib/aws/ec2/attachment.rb', line 107

def delete options = {}
  client.detach_volume(options.merge(resource_options))
end

#delete_on_termination?Boolean

Returns true if the volume will be deleted on instance termination.

Returns:

  • (Boolean)

    Returns true if the volume will be deleted on instance termination.


67
# File 'lib/aws/ec2/attachment.rb', line 67

attribute :delete_on_termination, :boolean => true

#exists?Boolean

Returns true if the attachment exists.

Returns:

  • (Boolean)

    Returns true if the attachment exists.


93
94
95
# File 'lib/aws/ec2/attachment.rb', line 93

def exists?
  !describe_attachment.nil?
end

#statusSymbol

Returns the attachment status. Possible values are:

  • :attaching

  • :attached

  • :detaching

  • :detached

Returns:

  • (Symbol)

    Returns the attachment status.


58
# File 'lib/aws/ec2/attachment.rb', line 58

attribute :status, :to_sym => true