class RodeoClown::ELB
Public Class Methods
by_name(name)
click to toggle source
# File lib/rodeo_clown/elb.rb, line 12 def self.by_name(name) new load_balancers[name] end
load_balancers()
click to toggle source
# File lib/rodeo_clown/elb.rb, line 16 def self.load_balancers AWS::ELB.new.load_balancers end
Public Instance Methods
deregister(ary_instances)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Rotate servers given
# File lib/rodeo_clown/elb.rb, line 47 def rotate(hsh) current_ec2, new_ec2 = hsh.first cur_instances = EC2.by_tags("Name" => current_ec2.to_s) new_instances = EC2.by_tags("Name" => new_ec2.to_s) register_and_wait new_instances deregister cur_instances end
timeout()
click to toggle source
# File lib/rodeo_clown/elb.rb, line 5 def timeout @timeout ||= (ENV["TIMEOUT"] || 60).to_i end
wait_for_state(instances, exp_state)
click to toggle source
Wait for all the instances to become InService
# 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