Represents an attachment of an Amazon EBS volume to an instance.
@example 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
@example 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
@return [String] Returns how the device is exposed to the instance
(e.g. '/dev/sdh')
@return [Instance] Returns the EC2 instance the volume is attached to.
@return [Volume] Returns the volume that is attached.
@private
# File lib/aws/ec2/attachment.rb, line 34 def initialize volume, instance, device, options = {} @volume = volume @instance = instance @device = device super end
Detaches the volume from its instance. @option options [Boolean] :force 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.
# File lib/aws/ec2/attachment.rb, line 107 def delete options = {} client.detach_volume(options.merge(resource_options)) end
@return [Boolean] Returns true if the attachment exists.
# File lib/aws/ec2/attachment.rb, line 93 def exists? !describe_attachment.nil? end
# File lib/aws/ec2/attachment.rb, line 121 def describe_call client.describe_volumes(:volume_ids => [self.volume.id]) end
# File lib/aws/ec2/attachment.rb, line 112 def resource_identifiers [ [:volume_id, volume.id], [:instance_id, instance.id], [:device, device], ] end