Class: RodeoClown::ELB
- Inherits:
-
Struct
- Object
- Struct
- RodeoClown::ELB
- Extended by:
- Forwardable
- Defined in:
- lib/rodeo_clown/elb.rb
Instance Attribute Summary collapse
-
#elb ⇒ Object
Returns the value of attribute elb.
Class Method Summary collapse
Instance Method Summary collapse
- #deregister(ary_instances) ⇒ Object
- #register_and_wait(new_instances) ⇒ Object
-
#rotate(hsh) ⇒ Object
Rotate servers given.
- #timeout ⇒ Object
-
#wait_for_state(instances, exp_state) ⇒ Object
Wait for all the instances to become InService.
Instance Attribute Details
#elb ⇒ Object
Returns the value of attribute elb
3 4 5 |
# File 'lib/rodeo_clown/elb.rb', line 3 def elb @elb end |
Class Method Details
.by_name(name) ⇒ Object
12 13 14 |
# File 'lib/rodeo_clown/elb.rb', line 12 def self.by_name(name) new load_balancers[name] end |
.load_balancers ⇒ Object
16 17 18 |
# File 'lib/rodeo_clown/elb.rb', line 16 def self.load_balancers AWS::ELB.new.load_balancers end |
Instance Method Details
#deregister(ary_instances) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rodeo_clown/elb.rb', line 33 def deregister(ary_instances) ary_instances.each do |i| begin puts "...deregistering: #{i.id}" instances.deregister(i.id) rescue AWS::ELB::Errors::InvalidInstance puts "Instance #{i.id} currently not registered to load balancer" end end end |
#register_and_wait(new_instances) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rodeo_clown/elb.rb', line 20 def register_and_wait(new_instances) new_instances.each do |i| begin puts "...registering: #{i.id}" instances.register(i.id) rescue AWS::ELB::Errors::InvalidInstance puts "Instance #{i.id} could not be registered to load balancer" end end wait_for_state(instances, "InService") end |
#rotate(hsh) ⇒ Object
Rotate servers given
47 48 49 50 51 52 53 54 55 |
# File 'lib/rodeo_clown/elb.rb', line 47 def rotate(hsh) current_ec2, new_ec2 = hsh.first cur_instances = EC2.("Name" => current_ec2.to_s) new_instances = EC2.("Name" => new_ec2.to_s) register_and_wait new_instances deregister cur_instances end |
#timeout ⇒ Object
5 6 7 |
# File 'lib/rodeo_clown/elb.rb', line 5 def timeout @timeout ||= (ENV["TIMEOUT"] || 60).to_i end |
#wait_for_state(instances, exp_state) ⇒ Object
Wait for all the instances to become InService
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rodeo_clown/elb.rb', line 60 def wait_for_state(instances, exp_state) time = 0 all_good = false loop do all_good = instances.all? do |i| state = i.elb_health[:state] puts "#{i.id}: #{state}" exp_state == state end break if all_good || time > timeout sleep 1 time += 1 end # If timeout before all inservice, deregister and raise error unless all_good raise "Instances are out of service" end end |