Class: Rig::Model::Balancer

Inherits:
Object
  • Object
show all
Defined in:
lib/rig/model/balancer.rb

Class Method Summary collapse

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

.allObject



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