-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodeman_util.bash
284 lines (251 loc) · 6.39 KB
/
nodeman_util.bash
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
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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Copyright 2025, Battelle Energy Alliance, LLC
#
# Author:
# Scott Serr
#
# Description:
# Basic utility functions that should work on all systems
# Common parallel switches see usages in code
# -j --delay --timeout --tagstring --line-buffer
# default output grouping vs --line-buffer
# default grouping will emit output as soon as a job is done
# --line-buffer will emit output all the while the job is working
# #echo -e "foo\nbar" | parallel "for f in 1 2 3; do echo $f {}; sleep 1; done"
# echo -e "foo\nbar" | parallel "for f in 1 2 3; do if [[ "{}" == "foo" ]]; then sleep 1; fi; echo $f {}; sleep 1; done"
nm.net.healthy () {
single () {
h=$1
ping -c 2 $h.ib > /dev/null 2>&1
ib=$?
ping -c 2 $h.eth > /dev/null 2>&1
eth=$?
ping -c 2 $h.bmc > /dev/null 2>&1
bmc=$?
if [[ $ib == 0 && $eth == 0 && $bmc == 0 ]]; then
echo "healthy" > /dev/stdout
else
echo "ping failed: ib=$ib eth=$eth bmc=$bmc" > /dev/stderr
fi
}
export -f single
nm._parallel -j200 --delay .01 single
}
nm.net.sick () {
single () {
h=$1
ping -c 1 $h.ib > /dev/null 2>&1
ib=$?
sleep .1
ping -c 1 $h.eth > /dev/null 2>&1
sleep .1
ping -c 1 $h.eth > /dev/null 2>&1
eth=$?
sleep .1
ping -c 1 $h.bmc > /dev/null 2>&1
bmc=$?
if [[ $ib == 0 && $eth == 0 && $bmc == 0 ]]; then
# do nothing?
echo $h > /dev/null
else
echo "sick" > /dev/stdout
echo "ping failed: ib=$ib eth=$eth bmc=$bmc" > /dev/stderr
fi
}
export -f single
nm._parallel -j200 --delay .01 single
}
nm.uptime () {
single () {
OUT=$(ssh $1 uptime)
echo $OUT
}
export -f single
nm._parallel -j0 --delay .02 single
}
nm.ssh () {
single () {
ssh $*
}
export -f single
nm._parallel -j200 --timeout 30 --line-buffer single {} $*
}
nm.sel () {
nm._parallel -j100 --timeout 1m $NM_IPMI -H {}.bmc sel elist
}
nm.bmc.reset () {
nm._parallel -j100 --timeout 1m $NM_IPMI -H {}.bmc mc reset cold
}
nm.power.status () {
single () {
h=$1
$NM_IPMI -H $h.bmc chassis power status
}
export -f single
nm._parallel -j50 --tagstring "{}: " single
}
nm.reboot () {
nm._parallel -j0 --delay .2 'sudo ssh {} "reboot" < /dev/null; sleep 5; echo {};'
}
nm.reboot.slow () {
nm._parallel -j0 --delay 2 'sudo ssh {} "reboot" < /dev/null; sleep 5; echo {};'
}
nm.poweroff () {
nm._parallel -j0 --delay .1 'sudo ssh {} "poweroff" < /dev/null; sleep 5; echo {};'
}
nm.power.cycle () {
single () {
h=$1
$NM_IPMI -H $h.bmc chassis power cycle > /dev/null
sleep 2
$NM_IPMI -H $h.bmc chassis power on > /dev/null 2>&1
# sleep 8
# echo "$h $($NM_IPMI -H $h.bmc chassis power status)"
echo $h
}
export -f single
nm._parallel -j50 --timeout 1m single
}
nm.power.cycle.slow () {
single () {
h=$1
$NM_IPMI -H $h.bmc chassis power cycle > /dev/null
sleep 2
$NM_IPMI -H $h.bmc chassis power on > /dev/null 2>&1
# sleep 8
# echo "$h $($NM_IPMI -H $h.bmc chassis power status)"
echo $h
}
export -f single
nm._parallel --delay 1 --timeout 1m single
}
nm.power.on.slow () {
nm._parallel --delay 1.2 --timeout 10s $NM_IPMI -H {}.bmc chassis power on > /dev/null
}
nm.power.on.slow.visual () {
nm._parallel --delay 3 --timeout 10s $NM_IPMI -H {}.bmc chassis power on > /dev/null
}
nm.power.on () {
nm._parallel --delay .1 --timeout 10s $NM_IPMI -H {}.bmc chassis power on > /dev/null
}
nm.power.off () {
nm._parallel -j10 --timeout 10s $NM_IPMI -H {}.bmc chassis power off > /dev/null
}
nm.power.off.slow () {
nm._parallel --delay .08 --timeout 10s $NM_IPMI -H {}.bmc chassis power off > /dev/null
}
nm.dmesg () {
single () {
h=$1
ssh $h 'dmesg -T | tail -10' < /dev/null
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}
nm.reading.power () {
single () {
h=$1
OUT=$($NM_IPMI -H $h.bmc dcmi power reading)
PWR=$(echo "$OUT" | grep Inst | awk '{ print $4 }')
echo "$PWR"
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}
nm.sensors () {
single () {
h=$1
OUT=$($NM_IPMI -H $h.bmc sensor)
CPU1_TEMP=$(echo "$OUT" | grep "^Temp" | head -1 | awk '{ print $3 }')
echo "CPU1_TEMP $CPU1_TEMP"
CPU2_TEMP=$(echo "$OUT" | grep "^Temp" | tail -1 | awk '{ print $3 }')
echo "CPU2_TEMP $CPU2_TEMP"
INLET_TEMP=$(echo "$OUT" | grep "^Inlet Temp" | awk '{ print $4 }')
echo "INLET_TEMP $INLET_TEMP"
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}
nm.sdr.power () {
single () {
h=$1
$NM_IPMI -H $h.bmc sdr type 0x03 | grep "Pwr Consumption" | awk '{ print $10 }'
}
export -f single
nm._parallel -j100 single
}
nm.fanload () {
single () {
h=$1
OUT=$($NM_IPMI -H $h.bmc sdr list | grep "RPM")
MAX=$(echo "$OUT" | awk 'max<$3 || NR==1{ max=$3 } END{ print max }')
LOAD=$(ssh $h "cat /proc/loadavg" | cut -d" " -f1)
echo "$MAX $LOAD"
}
export -f single
nm._parallel -j0 --delay .05 --timeout 20 single
}
nm.fan () {
single () {
h=$1
OUT=$($NM_IPMI -H $h.bmc sdr list | grep "RPM")
MAX=$(echo "$OUT" | awk 'max<$3 || NR==1{ max=$3 } END{ print max }')
echo "$MAX"
}
export -f single
nm._parallel -j0 --delay .05 --timeout 20 single
}
nm.identify.on () {
single () {
h=$1
$NM_IPMI -H $h.bmc chassis identify force
}
if [[ "$1" != "" ]]; then
single $1
else
export -f single
nm._parallel --line-buffer -j200 --timeout 30 single {} $*
fi
}
nm.identify.off () {
single () {
h=$1
$NM_IPMI -H $h.bmc chassis identify 0
}
if [[ "$1" != "" ]]; then
single $1
else
export -f single
nm._parallel --line-buffer -j200 --timeout 30 single {} $*
fi
}
nm.stat.mem () {
single () {
h=$1
OUT=$(ssh $h "cat /proc/meminfo" 2> /dev/null)
MT=$(echo "$OUT" | grep "MemTotal" | tr -s " ")
MF=$(echo "$OUT" | grep "MemFree" | tr -s " ")
MA=$(echo "$OUT" | grep "MemAvailable" | tr -s " ")
echo "$MT $MF $MA"
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}
nm.service.tag () {
single () {
h=$1
$NM_IPMI -H $h.bmc fru | grep "Product Serial" | awk '{ print $4 }'
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}
nm.thermalthrottles () {
single () {
h=$1
THERMS=$(ssh $h 'dmesg | grep "CPU0: Package temperature above threshold" | wc -l')
OUT=$(ssh $h 'dmesg -T | grep "Package temperature above" | tail -1' < /dev/null)
echo "$THERMS $OUT"
}
export -f single
nm._parallel -j200 --timeout 30 single {} $*
}