-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreplace_ip.rb
More file actions
39 lines (34 loc) · 922 Bytes
/
replace_ip.rb
File metadata and controls
39 lines (34 loc) · 922 Bytes
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
cmd = "chassis identify 2"
username = "admin"
passwd = "admin"
sleeptime = 0.01
require 'open3'
report = {}
threads = []
IO.readlines("ip.txt").each do |str|
t = Thread.new do
orig, repl = str.split(" ")
ip_orig = "10.0.0.#{orig}"
ip_repl = "10.0.0.#{repl}"
command = "ipmitool -I lanplus -H #{ip_orig} -U #{username} -P #{passwd} lan set 1 ipaddr #{ip_repl}"
puts command
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
status = $?.to_i
status = wait_thr.value
report[orig] = [ip_orig, status, command, stdout.readlines, stderr.readlines]
puts "#{ip}: (#{status}) #{stdout}"
end
p command
end
threads << t
sleep(sleeptime)
end
sleep(200) # successful threads will hang anyways, no need to wait more.
#threads.each do |t|
#t.join(120)
#p t
#end
puts "Failed On Nodes:"
report.sort.reject {|k, v| v[1] == 0}.each do |k, v|
p v
end