Class: AWS::EC2::Attachment

Inherits:
Object
  • 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

#deviceObject (readonly)

Returns the value of attribute device.



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

def device
  @device
end

#instanceObject (readonly)

Returns the value of attribute instance.



40
41
42
# File 'lib/aws/ec2/attachment.rb', line 40

def instance
  @instance
end

#volumeObject (readonly)

Returns the value of attribute volume.



39
40
41
# File 'lib/aws/ec2/attachment.rb', line 39

def volume
  @volume
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns True if the attachments are the same.

Parameters:

  • other (Object)

    The object to compare with.

Returns:

  • (Boolean)

    True if the attachments are the same.



86
87
88
89
90
91
# File 'lib/aws/ec2/attachment.rb', line 86

def ==(other)
  other.kind_of?(Attachment) and
    other.volume == volume and
    other.instance == instance and
    other.device == device
end

#attach_timeTime

Returns The time at which this attachment was created.

Returns:

  • (Time)

    The time at which this attachment was created.



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

def attach_time
  retrieve_attribute(:attach_time) { describe_call }
end

#delete(opts = {}) ⇒ Object

Detaches the volume from an instance.

Parameters:

  • instance (Instance)

    The instance to detach from.

  • device (String)

    The device name.

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

    Additional options for detaching the volume.

Options Hash (opts):

  • :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.



52
53
54
55
56
# File 'lib/aws/ec2/attachment.rb', line 52

def delete(opts = {})
  client.detach_volume(opts.merge(:volume_id => volume.id,
                                  :instance_id => instance.id,
                                  :device => device))
end

#delete_on_termination?Boolean

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

Returns:

  • (Boolean)

    True if the volume will be deleted on instance termination.



74
75
76
# File 'lib/aws/ec2/attachment.rb', line 74

def delete_on_termination?
  retrieve_attribute(:delete_on_termination?) { describe_call }
end

#exists?Boolean

Returns True if the attachment exists.

Returns:

  • (Boolean)

    True if the attachment exists.



79
80
81
# File 'lib/aws/ec2/attachment.rb', line 79

def exists?
  !describe_attachment.nil?
end

#statusSymbol

Returns The attachment status. Possible values:

  • :attaching

  • :attached

  • :detaching

  • :detached.

Returns:

  • (Symbol)

    The attachment status. Possible values:

    • :attaching

    • :attached

    • :detaching

    • :detached



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

def status
  retrieve_attribute(:status) { describe_call }
end