Class: AWS::EC2::Attachment

Inherits:
Resource
  • Object
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-west-2a")
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

Instance Method Summary collapse

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.



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

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.



99
100
101
# File 'lib/aws/ec2/attachment.rb', line 99

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.



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

attribute :delete_on_termination, :boolean => true

#exists?Boolean

Returns true if the attachment exists.

Returns:

  • (Boolean)

    Returns true if the attachment exists.



85
86
87
# File 'lib/aws/ec2/attachment.rb', line 85

def exists?
  !describe_attachment.nil?
end

#statusSymbol

Returns the attachment status. Possible values are:

  • :attaching
  • :attached
  • :detaching
  • :detached

Returns:

  • (Symbol)

    Returns the attachment status.



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

attribute :status, :to_sym => true