Class: Standup::EC2::Volume

Inherits:
Base
  • Object
show all
Defined in:
lib/standup/ec2/volume.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#exists?, info_reader

Constructor Details

#initialize(id, info = false) ⇒ Volume

Returns a new instance of Volume.



4
5
6
7
# File 'lib/standup/ec2/volume.rb', line 4

def initialize id, info = false
  @id = id
  super info
end

Class Method Details

.create(size) ⇒ Object



25
26
27
28
29
# File 'lib/standup/ec2/volume.rb', line 25

def self.create size
  response = api.create_volume :size => size.to_s,
                               :availability_zone => Settings.aws.availability_zone
  list[response.volumeId] = Volume.new response.volumeId
end

.list(reload = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/standup/ec2/volume.rb', line 11

def self.list reload = false
  if !class_variable_defined?(:@@list) || reload
    @@list = {}
    response = api.describe_volumes
    response.volumeSet.item.each do |item|
      instance = item.attachmentSet ? Instance.new(item.attachmentSet.item[0].instanceId) : nil
      @@list[item.volumeId] = Volume.new item.volumeId,
                                          :status => item.status.to_sym,
                                          :attached_to => instance
    end if response.volumeSet
  end
  @@list
end

Instance Method Details

#attach_to(instance, device) ⇒ Object



36
37
38
39
40
41
# File 'lib/standup/ec2/volume.rb', line 36

def attach_to instance, device
  api.attach_volume :volume_id => @id,
                    :instance_id => instance.id,
                    :device => device
  @attached_to = instance
end

#destroyObject



31
32
33
34
# File 'lib/standup/ec2/volume.rb', line 31

def destroy
  api.delete_volume :volume_id => @id
  list.delete @id
end

#detachObject



43
44
45
46
47
# File 'lib/standup/ec2/volume.rb', line 43

def detach
  api.detach_volume :volume_id => @id,
                    :force => 'true'
  @attached_to = nil
end

#load_infoObject



49
50
51
52
53
54
# File 'lib/standup/ec2/volume.rb', line 49

def load_info
  response = api.describe_volumes :volume_id => @id
  item = response.volumeSet.item[0]
  @status = item.status.to_sym
  @attached_to = item.attachmentSet ? Instance.new(item.attachmentSet.item[0].instanceId) : nil
end