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-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

Instance Method Summary collapse

Instance Attribute Details

#deviceString (readonly)



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

def device
  @device
end

#instanceInstance (readonly)



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

def instance
  @instance
end

#volumeVolume (readonly)



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.



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

attribute :attach_time

#delete(options = {}) ⇒ Object

Detaches the volume from its instance.

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.



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

attribute :delete_on_termination, :boolean => true

#exists?Boolean



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



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

attribute :status, :to_sym => true