Class: Awsum::Ec2::Volume

Inherits:
Object show all
Defined in:
lib/awsum/ec2/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, id, instance_id, size, status, create_time, snapshot_id, device, attach_time, availability_zone, attachment_status) ⇒ Volume

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/awsum/ec2/volume.rb', line 8

def initialize(ec2, id, instance_id, size, status, create_time, snapshot_id, device, attach_time, availability_zone, attachment_status) #:nodoc:
  @ec2 = ec2
  @id = id
  @instance_id = instance_id
  @size = size
  @status = status
  @create_time = create_time
  @snapshot_id = snapshot_id
  @device = device
  @attach_time = attach_time
  @availability_zone = availability_zone
  @attachment_status = attachment_status
end

Instance Attribute Details

#attach_timeObject (readonly)

Returns the value of attribute attach_time.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def attach_time
  @attach_time
end

#attachment_statusObject (readonly)

Returns the value of attribute attachment_status.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def attachment_status
  @attachment_status
end

#availability_zoneObject (readonly)

Returns the value of attribute availability_zone.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def availability_zone
  @availability_zone
end

#create_timeObject (readonly)

Returns the value of attribute create_time.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def create_time
  @create_time
end

#deviceObject (readonly)

Returns the value of attribute device.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def device
  @device
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def id
  @id
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def instance_id
  @instance_id
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def size
  @size
end

#snapshot_idObject (readonly)

Returns the value of attribute snapshot_id.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def snapshot_id
  @snapshot_id
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/awsum/ec2/volume.rb', line 6

def status
  @status
end

Instance Method Details

#create_snapshot(options = {}) ⇒ Object

Creates a Snapshot of this Volume



64
65
66
# File 'lib/awsum/ec2/volume.rb', line 64

def create_snapshot(options = {})
  @ec2.create_snapshot id, options
end

#deleteObject

Delete this volume



49
50
51
# File 'lib/awsum/ec2/volume.rb', line 49

def delete
  @ec2.delete_volume id
end

#delete!Object

Force delete this volume will detach it first



55
56
57
58
59
60
61
# File 'lib/awsum/ec2/volume.rb', line 55

def delete!
  detach true
  while status != 'available'
    reload
  end
  @ec2.delete_volume id
end

#detach(force = false) ⇒ Object

Detach this volume



44
45
46
# File 'lib/awsum/ec2/volume.rb', line 44

def detach(force = false)
  @ec2.detach_volume id, :force => force
end

#reloadObject

Will reload the information about this Volume

Useful for when a volume has just been created but is not yet available

while volume.status != 'available'
  volume.reload
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/awsum/ec2/volume.rb', line 28

def reload
  reloaded_volume = @ec2.volume id

  @id = id
  @instance_id = reloaded_volume.instance_id
  @size = reloaded_volume.size
  @status = reloaded_volume.status
  @create_time = reloaded_volume.create_time
  @snapshot_id = reloaded_volume.snapshot_id
  @device = reloaded_volume.device
  @attach_time = reloaded_volume.attach_time
  @availability_zone = reloaded_volume.availability_zone
  @attachment_status = reloaded_volume.attachment_status
end

#snapshotsObject

Lists the Snapshot(s) of this Volume



69
70
71
72
# File 'lib/awsum/ec2/volume.rb', line 69

def snapshots
  snapshots = @ec2.snapshots
  snapshots.delete_if {|s| s.volume_id != id}
end