Class: Ironfan::Provider::Ec2::ElasticLoadBalancer

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

Instance Attribute Summary

Attributes inherited from Resource

#owner, #users

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

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

Methods inherited from Builder

ui, #ui

Class Method Details

.aggregate!(computers) ⇒ Object

Manipulation


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 52

def self.aggregate!(computers)
  ec2_computers = computers.select { |c| Ec2.applicable c }
  return if ec2_computers.empty?

  load! # Find out which ELBs already exist in EC2

  running_computers = ec2_computers.select { |c| c.running? }
  elbs_for_running_computers = running_computers.map { |c| self.expected_ids(c) }.flatten.uniq
  elbs_for_stopped_computers = ec2_computers.select { |c| not c.running? }.map { |c| self.expected_ids(c) }.flatten.uniq
  elbs_to_start = [ elbs_for_running_computers ].flatten.compact.reject { |elb_name| recall? elb_name }
  elbs_to_stop  = [ elbs_for_stopped_computers - elbs_for_running_computers ].flatten.compact.select { |elb_name| recall? elb_name }

  elbs_to_stop.each do |elb_name|
    Ironfan.step(elb_name, "stopping unused elastic load balancer #{elb_name}", :blue)
    Ec2.elb.delete_load_balancer(elb_name)
    forget elb_name
  end

  [ elbs_to_start, elbs_for_running_computers ].flatten.sort.uniq.each do |elb_name|
    computers_using_this_elb = running_computers.select { |c| self.expected_ids(c).include?(elb_name) }
    self.start_or_sync_elb(elb_name, computers_using_this_elb, elbs_to_start.include?(elb_name))
  end
  load!

end

.expected_ids(computer) ⇒ Object


22
23
24
25
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 22

def self.expected_ids(computer)
  ec2 = computer.server.cloud(:ec2)
  ec2.elastic_load_balancers.values.map { |elb| self.full_name(computer, elb) }.uniq
end

.load!(cluster = nil) ⇒ Object

Discovery


34
35
36
37
38
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 34

def self.load!(cluster=nil)
  Ec2.elb.load_balancers.each do |raw|
    register raw unless raw.blank?
  end
end

.multiple?Boolean

Returns:

  • (Boolean)

20
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 20

def self.multiple?()     true;   end

.resource_typeObject


21
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 21

def self.resource_type() :elastic_load_balancer;   end

.shared?Boolean

Returns:

  • (Boolean)

19
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 19

def self.shared?()       true;   end

Instance Method Details

#nameObject


27
28
29
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 27

def name()
  adaptee.id
end

#receive_adaptee(obj) ⇒ Object


40
41
42
43
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 40

def receive_adaptee(obj)
  obj = Ec2.elb.load_balancer.new(obj) if obj.is_a?(Hash)
  super
end

#to_sObject


45
46
47
# File 'lib/ironfan/provider/ec2/elastic_load_balancer.rb', line 45

def to_s
  "<%-15s>" % name
end