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-west-2a") 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.
@api 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 99 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 85 def exists? !describe_attachment.nil? end
# File lib/aws/ec2/attachment.rb, line 113 def describe_call client.describe_volumes(:volume_ids => [self.volume.id]) end
# File lib/aws/ec2/attachment.rb, line 104 def resource_identifiers [ [:volume_id, volume.id], [:instance_id, instance.id], [:device, device], ] end
# File lib/aws/ec2/attachment.rb, line 118 def describe_attachment find_attachment(describe_call) end
# File lib/aws/ec2/attachment.rb, line 122 def find_attachment(resp) vol = resp.volume_index[volume.id] and attachments = vol.attachment_set and attachments.find do |att| att.instance_id == instance.id && att.volume_id == volume.id && att.device == device end end