Class: Rig::Model::Balancer
- Inherits:
-
Object
- Object
- Rig::Model::Balancer
- Defined in:
- lib/rig/model/balancer.rb
Class Method Summary collapse
- .add_listener(name, from, to, cert, policy_list) ⇒ Object
- .all ⇒ Object
- .create(name, listeners = [], zones = []) ⇒ Object
- .destroy(list) ⇒ Object
- .destroy_listener(name, from) ⇒ Object
- .find(name) ⇒ Object
- .find_by_environment(name) ⇒ Object
- .new(name, listeners = [], zones = []) ⇒ Object
- .new_listener(from, to, cert = nil, policy_names = nil) ⇒ Object
- .sticky(balancer_name, type, expires_or_cookie, listener = "443", policy_name = 'RigLbCookiePolicy') ⇒ Object
- .unsticky(balancer_name, type, expires_or_cookie, listener = "443", policy_name = 'RigLbCookiePolicy') ⇒ Object
Class Method Details
.add_listener(name, from, to, cert, policy_list) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rig/model/balancer.rb', line 49 def add_listener(name, from, to, cert, policy_list) elb = find(name) (from_proto, from_port) = from.split(':') (to_proto, to_port) = to.split(':') sslcert = cert || nil policy_names = policy_list || [] new_listener = elb.listeners.new( :policy_names => policy_names, :instance_port => to_port, :instance_protocol => to_proto, :lb_port => from_port, :protocol => from_proto, :ssl_id => sslcert, :load_balancer => elb ) new_listener.save end |
.all ⇒ Object
6 7 8 |
# File 'lib/rig/model/balancer.rb', line 6 def all Rig::Connection.balancer.load_balancers.all end |
.create(name, listeners = [], zones = []) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rig/model/balancer.rb', line 21 def create(name, listeners=[], zones=[]) b = self.new(name, listeners, zones) b.save if b Rig::Log.info ".. created: #{name}" b end |
.destroy(list) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/rig/model/balancer.rb', line 36 def destroy(list) list = [*list] lbs = list.map { |e| e.kind_of?(String) ? self.find(e) : e } lbs.each do |lb| Rig::Log.info ".. destroying: #{lb.id}" lb.destroy if lb end end |
.destroy_listener(name, from) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rig/model/balancer.rb', line 67 def destroy_listener(name, from) elb = find(name) (from_proto, from_port) = from.split(':') match = elb.listeners.select {|l| l.protocol == from_proto && l.lb_port == from_port.to_i } #TODO: handle output in command, not here if match.count > 1 Rig::Log.info "more than one listener matched" match.each do |l| ap l.attributes end return end match.first.destroy end |
.find(name) ⇒ Object
28 29 30 |
# File 'lib/rig/model/balancer.rb', line 28 def find(name) Rig::Connection.balancer.load_balancers.get(name) end |
.find_by_environment(name) ⇒ Object
32 33 34 |
# File 'lib/rig/model/balancer.rb', line 32 def find_by_environment(name) self.all.select { |e| e.id =~ /^#{name}/ } end |
.new(name, listeners = [], zones = []) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rig/model/balancer.rb', line 10 def new(name, listeners=[], zones=[]) fog = Rig::Connection.balancer listeners.map! do |listener| ld = new_listener_description(listener) #ap ld ld end #ap listeners fog.load_balancers.new({ :id => name, "ListenerDescriptions" => listeners, :availability_zones => zones }) end |
.new_listener(from, to, cert = nil, policy_names = nil) ⇒ Object
45 46 47 |
# File 'lib/rig/model/balancer.rb', line 45 def new_listener(from, to, cert=nil, policy_names=nil) new_listener_description({ :from => from, :to => to, :cert => cert, :policy_names => policy_names }) end |
.sticky(balancer_name, type, expires_or_cookie, listener = "443", policy_name = 'RigLbCookiePolicy') ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rig/model/balancer.rb', line 82 def sticky(balancer_name, type, , listener="443", policy_name='RigLbCookiePolicy') elb = find(balancer_name) raise "balancer #{balancer_name} not found" unless elb case type.to_sym when :app, :application Rig::Connection.balancer.(balancer_name, policy_name, ) Rig::Connection.balancer.set_load_balancer_policies_of_listener(balancer_name, listener.to_i, [policy_name]) when :lb, :load_balancer Rig::Connection.balancer.(balancer_name, policy_name, .to_i) Rig::Connection.balancer.set_load_balancer_policies_of_listener(balancer_name, listener.to_i, [policy_name]) else raise "unknown sticky type #{type}" end end |
.unsticky(balancer_name, type, expires_or_cookie, listener = "443", policy_name = 'RigLbCookiePolicy') ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rig/model/balancer.rb', line 98 def unsticky(balancer_name, type, , listener="443", policy_name='RigLbCookiePolicy') elb = find(balancer_name) raise "balancer #{balancer_name} not found" unless elb case type.to_sym when :app, :application Rig::Connection.balancer.set_load_balancer_policies_of_listener(balancer_name, listener.to_i, []) Rig::Connection.balancer.delete_load_balancer_policy(balancer_name, policy_name) when :lb, :load_balancer Rig::Connection.balancer.set_load_balancer_policies_of_listener(balancer_name, listener.to_i, []) Rig::Connection.balancer.delete_load_balancer_policy(balancer_name, policy_name) else raise "unknown sticky type #{type}" end end |