| 1 |
#!/usr/bin/expect -- |
| 2 |
# |
| 3 |
# reboot-numaq -- reboot Numa-Q systems connected to a VCS console |
| 4 |
# |
| 5 |
# Use the remote telnet managment interface on the VCS console to |
| 6 |
# hardreset systems. Systems are identified by their system names |
| 7 |
# within VCS. |
| 8 |
# |
| 9 |
# usage: |
| 10 |
# reboot-numaq <type> <console IP> <system> <port> <userid> <password> |
| 11 |
# |
| 12 |
# examples: |
| 13 |
# reboot-numaq vcs 1.2.3.4 hummer 12346 FOO BAR |
| 14 |
# |
| 15 |
# (C) Copyright IBM Corp. 2004, 2005, 2006 |
| 16 |
# Author: Andy Whitcroft <[email protected]> |
| 17 |
# |
| 18 |
# The Console Multiplexor is released under the GNU Public License V2 |
| 19 |
# |
| 20 |
set P "reboot-numaq" |
| 21 |
|
| 22 |
if { [llength $argv] != 6 } { |
| 23 |
puts stderr "Usage: reboot-numaq vcs <console addr> <system> <console port> <userid> <password>" |
| 24 |
exit 1 |
| 25 |
} |
| 26 |
|
| 27 |
log_user 0 |
| 28 |
#stty echo |
| 29 |
set argc [llength $argv] |
| 30 |
set console_ip [lindex $argv 1] |
| 31 |
set system [lindex $argv 2] |
| 32 |
set console_port [lindex $argv 3] |
| 33 |
set username [lindex $argv 4] |
| 34 |
set password [lindex $argv 5] |
| 35 |
|
| 36 |
#log_file -a "$logfile" |
| 37 |
|
| 38 |
set elapsed_time 0 |
| 39 |
set timeout 30 |
| 40 |
|
| 41 |
set command "telnet $console_ip $console_port" |
| 42 |
|
| 43 |
proc note {m} { |
| 44 |
global P |
| 45 |
puts "$P: $m" |
| 46 |
} |
| 47 |
proc warn {m} { |
| 48 |
global P |
| 49 |
puts "$P: WARNING: $m" |
| 50 |
} |
| 51 |
proc winge {m} { |
| 52 |
global P |
| 53 |
puts "$P: MACHINE ERROR: reboot failed - $m" |
| 54 |
} |
| 55 |
|
| 56 |
# CONNECT: connect to the remote console. |
| 57 |
note "Logging into VCS console with command \"$command\" to restart it" |
| 58 |
eval spawn $command |
| 59 |
expect { |
| 60 |
default { |
| 61 |
winge "login prompt not issued" |
| 62 |
exit 2 |
| 63 |
} |
| 64 |
"Connection closed by foreign host." { |
| 65 |
winge "Telnet connection closed." |
| 66 |
exit 1 |
| 67 |
} |
| 68 |
"Unable to connect to remote host:" { |
| 69 |
winge "Connection to remote console failed"; |
| 70 |
exit 2 |
| 71 |
} |
| 72 |
"login:" { |
| 73 |
note "saw login prompt" |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
# AUTHENTICATE: send username and password at the relevant prompts |
| 78 |
note "sending login ..." |
| 79 |
send -- "$username\r" |
| 80 |
expect { |
| 81 |
default { |
| 82 |
winge "password prompt not issued" |
| 83 |
exit 2 |
| 84 |
} |
| 85 |
"password:" { |
| 86 |
note "password prompt found" |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
note "sending password ..." |
| 91 |
send -- "$password\r" |
| 92 |
expect { |
| 93 |
default { |
| 94 |
winge "command prompt not issued" |
| 95 |
exit 2 |
| 96 |
} |
| 97 |
"Authentication Failed" { |
| 98 |
winge "login/password incorrect ... aborting" |
| 99 |
exit 1 |
| 100 |
} |
| 101 |
-- "->" { |
| 102 |
#note "command prompt found" |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
# SYSTEM: try and select the system, if the specified system does not |
| 107 |
# exist get a listing and print that out whilst we are connected. |
| 108 |
note "selecting system '$system' ..." |
| 109 |
send "cd $system\r" |
| 110 |
set found 1 |
| 111 |
expect { |
| 112 |
default { |
| 113 |
winge "command prompt not issued" |
| 114 |
exit 2 |
| 115 |
} |
| 116 |
-re "cd: path '.*' not found" { |
| 117 |
winge "system not defined" |
| 118 |
set found 0 |
| 119 |
exp_continue |
| 120 |
} |
| 121 |
-- "->" { |
| 122 |
#note "command prompt found" |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
proc list_systems {} { |
| 127 |
note "Defined systems:" |
| 128 |
send "sysdef -l\r" |
| 129 |
expect { |
| 130 |
default { |
| 131 |
winge "command prompt not issued" |
| 132 |
exit 2 |
| 133 |
} |
| 134 |
-re "sysdef -l\r\n$" { |
| 135 |
exp_continue |
| 136 |
} |
| 137 |
-- "->" { |
| 138 |
#note "command prompt found" |
| 139 |
} |
| 140 |
"\n$" { |
| 141 |
puts -nonewline "$expect_out(buffer)" |
| 142 |
exp_continue |
| 143 |
} |
| 144 |
} |
| 145 |
note "complete" |
| 146 |
} |
| 147 |
|
| 148 |
# The system the user specified was not found, give them a hand by |
| 149 |
# getting a list of systems. |
| 150 |
if {$found == 0} { |
| 151 |
list_systems |
| 152 |
note "complete ... exiting" |
| 153 |
send "exit\r" |
| 154 |
exit 1 |
| 155 |
} |
| 156 |
|
| 157 |
# DOWN: shut the system down ... hard. Expect to see nothing before the |
| 158 |
# prompt in the case of success. |
| 159 |
set timeout 65 |
| 160 |
set fail 1 |
| 161 |
for {set retry 1} {$fail == 1 && $retry <= 3} {incr retry} { |
| 162 |
note "powering off the system ..." |
| 163 |
send "power -f -t 60000 off\r" |
| 164 |
set fail 0 |
| 165 |
expect { |
| 166 |
default { |
| 167 |
winge "command prompt not issued" |
| 168 |
exit 2 |
| 169 |
} |
| 170 |
-- "->" { |
| 171 |
#note "command prompt found" |
| 172 |
} |
| 173 |
"*E*" { |
| 174 |
warn "power off failed ... attempt $retry" |
| 175 |
puts -nonewline "$expect_out(buffer)" |
| 176 |
set fail 1 |
| 177 |
exp_continue |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
if {$fail == 1} { |
| 182 |
winge "power off failed ... system not rebooted" |
| 183 |
list_systems |
| 184 |
exit 2 |
| 185 |
} |
| 186 |
set timeout 30 |
| 187 |
|
| 188 |
# UP: power the system on ... and then ask it to boot. |
| 189 |
note "powering on the system ..." |
| 190 |
send "power on\r" |
| 191 |
set fail 0 |
| 192 |
expect { |
| 193 |
default { |
| 194 |
winge "command prompt not issued" |
| 195 |
exit 2 |
| 196 |
} |
| 197 |
-- "->" { |
| 198 |
#note "command prompt found" |
| 199 |
} |
| 200 |
"*E*" { |
| 201 |
warn "power on failed ..." |
| 202 |
set fail 1 |
| 203 |
exp_continue |
| 204 |
} |
| 205 |
} |
| 206 |
if {$fail == 1} { |
| 207 |
winge "power on failed ... system not rebooted" |
| 208 |
list_systems |
| 209 |
exit 2 |
| 210 |
} |
| 211 |
|
| 212 |
note "booting the system ..." |
| 213 |
send "boot\r" |
| 214 |
expect { |
| 215 |
default { |
| 216 |
winge "command prompt not issued" |
| 217 |
exit 2 |
| 218 |
} |
| 219 |
-- "->" { |
| 220 |
#note "command prompt found" |
| 221 |
} |
| 222 |
"*E*" { |
| 223 |
warn "boot failed ..." |
| 224 |
set fail 1 |
| 225 |
exp_continue |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
note "complete ... exiting" |
| 230 |
send "exit" |
| 231 |
exit 0 |