58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/lanes.rb', line 58
def sh(lane)
servers = AWS.instance.fetchServers(lane)
servers.sort_by{ |s| s[:ip] }
display_server_table(servers, title: "Available Servers:")
mods = Props.instance.sshMod(lane)
identity = if mods['identity'] then mods['identity'] else '' end
puts "Identity file #{mods['identity']} will be used" if identity
command = options[:cmd].join(' ')
if options[:confirm] then
puts "Confirmed via command line. Moving forward with execution of \"#{command}\" on these machines:"
confirm = 'CONFIRM'
else
confirm = ask "Type CONFIRM to execute \"#{command} \" on these machines:"
end
if confirm == 'CONFIRM' then
servers.each{ |server|
user = if mods['user'] then mods['user'] else 'ec2-user' end
Net::SSH.start( server[:ip], user,
:keys => [identity],
:encryption => "blowfish-cbc",
:compression => "zlib",
:host_key => "ssh-rsa") do |ssh|
puts "Executing on %{name} ( %{ip} ):\t #{command} \n" % server
stdout = ''
ssh.exec!(command) do |channel, stream, data|
stdout << data
end
puts "Completed. %{name}\n\tOutput: #{stdout}\n\n " % server
end
}
confirmPath = options[:urlConfirm]
if confirmPath != nil then
confirmDelay = (options[:urlConfirmDelay] or 5)
confirmTimeout = (options[:urlConfirmTimeout] or 30);
startTime = Time.new.to_i
puts "Sleeping for #{confirmDelay} seconds, then trying the confirmation endpoint for #{confirmTimeout} seconds..."
sleep confirmDelay
while Time.new.to_i - startTime < confirmTimeout && servers.length > 0 do
servers.each_with_index{ |server, index|
begin
res = RestClient.get (confirmPath % server)
if res.code >= 200 && res.code < 300 then
puts "\t => #{server[:ip]} responded with #{res.code}"
servers.delete_at(index)
else
puts "\t XX #{server[:ip]} responded with #{res.code}" if options[:v]
end
rescue => e
puts "\t XX #{server[:ip]} connection failed: #{e}" if options[:v]
end
}
sleep 5 if servers.length > 0
puts "\t => #{servers.length} server(s) remaining..." if servers.length > 0
end
if servers.length == 0 then
puts "Successfully confirmed endpoints responded with a 2XX"
else
puts "The following server(s) did not respond with a 2XX:"
servers.each{ |server|
puts "\t%{name} (%{lane}) \t %{ip} \t %{id} " % server
}
end
end
else
puts 'Aborted!'
exit 1
end
end
|