-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_handler.rb
49 lines (36 loc) · 1.17 KB
/
vm_handler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'net/ssh'
class VMHandler
def self.yaim_terminated_in_each_host?(ip_addresses)
if ScalerConfig.debug
p "Checking if YAIM is terminated in:"
p ip_addresses
end
host_finished = 0
while host_finished < ip_addresses.count
host_finished = 0
ip_addresses.each do |ip_address|
retryable(:tries => 5, :sleep => 5, :on => [Errno::ECONNREFUSED, Errno::EHOSTUNREACH]) do
host_finished += yaim_terminated?(ip_address)
end
end
if ScalerConfig.debug
p "Number of finished hosts is:"
p host_finished
end
sleep(5)
end
end
def self.yaim_terminated?(ip_address)
last_line = ""
Net::SSH.start( ip_address, 'root', :paranoid => false ) do |session|
last_line = session.exec!('tail -n1 /opt/glite/yaim/log/yaimlog')
if last_line == nil then last_line = "" end
end
if ScalerConfig.debug
p "Last line in #{ip_address} is:"
p last_line
end
# last_line = %x[ssh ansible@#{ip_address} tail -n1 /opt/glite/yaim/log/yaimlog]
last_line.strip.include?("terminated succesfully") ? 1 : 0
end
end