Class: Ironfan::Provider::Ec2::EbsVolume

Inherits:
Resource show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider/ec2/ebs_volume.rb

Instance Attribute Summary

Attributes inherited from Resource

#owner, #users

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

aggregate!, #bogus?, create!, destroy!, forget, forget!, handle, known, patiently, prepare!, recall, recall?, receive, register, remember, validate_resources!

Methods inherited from Builder

ui, #ui

Class Method Details

.expected_ids(computer) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 27

def self.expected_ids(computer)
  computer.server.volumes.values.map do |volume|
    saved = computer.node[:volumes][volume.name][:volume_id] rescue nil
    ebs_name = "#{computer.server.full_name}-#{volume.name}"
    [ volume.volume_id, saved, ebs_name ]
  end.flatten.compact
end

.load!(cluster = nil) ⇒ Object

Discovery


51
52
53
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 51

def self.load!(cluster = nil)
  load_once!
end

.load_once!Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 55

def self.load_once!
  return if @loaded
  Ec2.connection.volumes.each do |vol|
    next if vol.blank?
    next if %w[deleting deleted error].include?(vol.state.to_s)
    ebs = EbsVolume.new(:adaptee => vol)    # Already have a volume by this name

    if recall? ebs.name
      ebs.bogus <<              :duplicate_volumes
      recall(ebs.name).bogus << :duplicate_volumes
      remember ebs, :append_id => "duplicate:#{ebs.id}"
    else
      remember ebs
    end
  end
  @loaded = true
end

.multiple?Boolean

Returns:

  • (Boolean)

25
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 25

def self.multiple?()    true;   end

.resource_typeObject


26
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 26

def self.resource_type()        :ebs_volume;   end

.save!(computer) ⇒ Object

Manipulation


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 101

def self.save!(computer)
  Ironfan.step(computer.name,"syncing EBS volumes",:blue)
  computer.drives.each do |drive|
    # Only worry about computers with ebs volumes
    ebs = drive.disk or next    # Only attach volumes if they aren't already attached

    if ebs.server_id.nil?
      Ironfan.step(computer.name, "  - attaching #{ebs.name}", :blue)
      Ironfan.safely do
        ebs.device =          drive.volume.device
        ebs.server =          computer.machine.adaptee
      end
    end
  end
end

.shared?Boolean

Returns:

  • (Boolean)

24
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 24

def self.shared?()      true;   end

.validate_computer!(computer) ⇒ Object


85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 85

def self.validate_computer!(computer)
  computer.drives.each do |drive|
    next unless drive.disk.class == EbsVolume
    [ (drive.node['volume_id'] rescue nil),
      (drive.volume.volume_id  rescue nil)
    ].compact.each do |id|
      Chef::Log.debug "checking #{id} against ebs_volume id #{drive.disk.id}"
      id == drive.disk.id or drive.disk.bogus << :volume_id_mismatch
    end
  end
end

Instance Method Details

#drivenameObject


39
40
41
42
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 39

def drivename
  return id unless tags.key? "Name"
  tags["Name"].split('-').pop
end

#ephemeral_device?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 44

def ephemeral_device?
  false
end

#nameObject


35
36
37
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 35

def name
  tags["Name"] || tags["name"] || id
end

#on_correlate(computer) ⇒ Object


78
79
80
81
82
83
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 78

def on_correlate(computer)
  drive = computer.drive(drivename)
  drive.disk = self
  drive.node = computer.node[:volumes][drivename].to_hash rescue {}
  drive
end

#receive_adaptee(obj) ⇒ Object


73
74
75
76
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 73

def receive_adaptee(obj)
  obj = Ec2.connection.volumes.new(obj) if obj.is_a?(Hash)
  super
end

#to_sObject


19
20
21
22
# File 'lib/ironfan/provider/ec2/ebs_volume.rb', line 19

def to_s
  "<%-15s %-12s %-25s %-32s %-10s %-12s %-15s %-5s %s:%s>" % [
    self.class.handle, id, created_at, tags['name'], state, device, tags['mount_point'], size, server_id, attached_at ]
end