Class: Etoro::Utility::MCollective::HAProxy
- Inherits:
-
RPC
- Object
- RPC
- Etoro::Utility::MCollective::HAProxy
show all
- Defined in:
- lib/etoro/utility/mcollective/haproxy.rb
Instance Attribute Summary
Attributes inherited from RPC
#current_host, #post_execute, #pre_execute
Instance Method Summary
collapse
Methods inherited from RPC
#class_filter, #fact_filter, #identity_filter, #initialize, #logging, #run, #sequential=, #sequential?
Instance Method Details
#check_run_status ⇒ Object
47
48
49
50
51
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
77
|
# File 'lib/etoro/utility/mcollective/haproxy.rb', line 47
def check_run_status
@logger.info("Checking HAProxy for completion")
begin
timeout(@config[:timeout]) do
if @haproxy_status.length == 0
@logger.error('No HAProxy or HAProxy Entry Found')
raise 'No HAProxy or HAProxy Entry Found'
end
until @haproxy_status == {}
@haproxy_status.each do |host, status|
run = rpcclient(self.class.name.downcase.split('::').last, :chomp => true)
run.identity_filter host
run.progress = false
results = run.status
results.each do |result|
if result[:data][:msg] == @state
@logger.info("#{host} - HAProxy: #{result[:data][:msg]}")
@haproxy_status.delete(host)
else
@logger.info("#{host} - HAProxy action not complete")
end
end
end
sleep @config[:wait_between_checks]
end
end
rescue Timeout::Error
@logger.error("HAProxy run timed out. Took more than #{@config[:timeout]} seconds")
end
end
|
#execute ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/etoro/utility/mcollective/haproxy.rb', line 16
def execute
@state = ''
case @config[:action]
when 'enable'
@state = 'UP'
when 'maintenance'
@state = 'DOWN'
end
@logger.info("HAProxy - Bringing #{@state}")
@mc.send @config[:action]
sleep @config[:wait_for_status]
self.check_run_status
end
|
#hosts ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/etoro/utility/mcollective/haproxy.rb', line 39
def hosts
hosts = []
@haproxy_status.each_key do |host|
hosts.push host
end
hosts
end
|
#status ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/etoro/utility/mcollective/haproxy.rb', line 30
def status
@haproxy_status = {}
@logger.info("Getting HAProxy status")
@mc.status.each do |result|
@haproxy_status[result[:sender]] = result[:data][:msg]
@logger.info("#{result[:sender]} - HAProxy #{result[:data][:msg]}")
end
end
|
#validate(config) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/etoro/utility/mcollective/haproxy.rb', line 6
def validate(config)
super
unless config.has_key?(:action)
raise RuntimeError, "config[:action] must be defined"
end
unless ['enable','maintenance'].include? config[:action]
raise RuntimeError, "Haproxy service value must be either enable or maintenance"
end
end
|