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
|
#!/usr/bin/expect --
#******************************************************************************
# Alpha Library Functions (ALF)
#******************************************************************************
# $Id: alpha.exp 1003 2011-01-26 18:26:06Z chris.m.dunlap $
#******************************************************************************
# Written by Chris Dunlap <cdunlap@llnl.gov>.
# Copyright (C) 2007-2011 Lawrence Livermore National Security, LLC.
# Copyright (C) 2001-2007 The Regents of the University of California.
# UCRL-CODE-2002-009.
#
# This file is part of ConMan: The Console Manager.
# For details, see <http://conman.googlecode.com/>.
#
# ConMan is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# ConMan is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with ConMan. If not, see <http://www.gnu.org/licenses/>.
#******************************************************************************
proc alpha_do_rmc_cmd {spawn_id output_id console echo cmd {tmout 10}} {
#
# Executes the RMC 'cmd' on the console session associated with 'spawn_id'.
# If 'echo' is non-zero, output will be sent to the user via 'output_id'.
# Returns 1 if the RMC cmd is successful; o/w, returns 0.
#
# Commands tested: power on, power off, halt in, halt out, reset, status.
#
# NOTE: Does not work on ds20.
#
set send_slow {1 0.25}
exp_send -s "\033\033rmc"
set timeout 2
expect -gl "^RMC>\$" {
;# exp_break
} -gl "\r\n" {
exp_continue -continue_timer
} eof {
return 0
} timeout {
if {$timeout == 2} { ;# already at RMC?
exp_send "\r"
set timeout 1
exp_continue
} else { ;# no RMC? i'm outta here!
return 0
}
}
set status 1
set timeout $tmout
exp_send -- "$cmd\r"
expect -gl "^$cmd\r\n" {
exp_continue -continue_timer ;# expect the cmd just sent
} -nocase -re "(^\[^\r]*(unknown command|power is off)\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
set status 0
exp_continue -continue_timer
} -gl "^RMC>\$" {
set echo 0
exp_send "quit\r"
exp_continue -continue_timer
} -gl "^Returning to COM port\r\n" {
;# exp_break
} -re "(^\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
exp_continue -continue_timer
} eof {
return 0
} timeout {
return 0
}
return $status
}
proc alpha_is_at_srm {spawn_id output_id console {tmout 3}} {
#
# Checks whether the console session associated with 'spawn_id' is at SRM.
# Times-out after approx 'tmout' secs; if you are waiting for the SRM prompt
# following a reset, you will want to specify a longer timeout (eg, 120secs).
# Returns 1 if the console is at SRM; o/w, returns 0.
#
set again 1 ;# sometimes the first \r gets lost
set timeout 1 ;# so try again in a second
exp_send "\r"
expect -re "\nCPU \[0-9]+ booting" {
exp_send "\003"
exp_continue -continue_timer
} -gl ">>>\$" {
return 1
} -gl "\r" {
exp_continue -continue_timer
} eof {
return 0
} timeout {
if {$again > 0} {
incr again -1
set timeout $tmout
exp_send "\r"
exp_continue
} else {
return 0
}
}
}
proc alpha_do_srm_cmd {spawn_id output_id console echo cmd {tmout 10}} {
#
# Executes the SRM 'cmd' on the console session associated with 'spawn_id'.
# If 'echo' is non-zero, output will be sent to the user via 'output_id'.
# Returns 1 if the SRM cmd is successful; o/w, returns 0.
#
if {! [alpha_is_at_srm $spawn_id $output_id $console]} {
return 0
}
set status 1
set timeout $tmout
exp_send -- "$cmd\r"
expect -gl "^$cmd\r\n" {
exp_continue -continue_timer ;# expect the cmd just sent
} -nocase -re "(^\[^\r]*jumping to bootstrap code\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
return 1 ;# success for "boot" cmd
} -nocase -re "(^\[^\r]*bootstrap code read in\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
return 1 ;# success for "boot" cmd via BOOTP
} -nocase -re "(^\[^\r]*(bad value|invalid|no such command)\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
set status 0
exp_continue -continue_timer
} -re "^\[^\r]*>>>\$" {
;# exp_break
} -re "(^\[^\r]*)\r\n" {
if {$echo} {exp_send -i $output_id "$expect_out(1,string)\n"}
exp_continue -continue_timer
} eof {
return 0
} timeout {
return 0
}
return $status
}
proc alpha_get_mac_addrs {spawn_id output_id console {errmsg_r {}}} {
#
# Queries SRM on the console associated with 'spawn_id' via "show dev".
# Returns a list of MAC addresses.
# On error, a message is written to the 'errmsg_r' var reference if present.
#
upvar $errmsg_r errmsg
set errmsg "Undefined"
set macs {}
if {! [alpha_is_at_srm $spawn_id $output_id $console]} {
set errmsg "Not at SRM prompt"
return
}
set word "\[^ \t\r\n]+"
set x "\[0-9A-Fa-f]"
set addr "$x$x-$x$x-$x$x-$x$x-$x$x-$x$x"
exp_send "show dev\r"
set timeout 10
expect -gl "No such command" {
set errmsg "No such command"
return
} -re "\n($word) +($word) +($addr) *\r" {
lappend macs \
[list $expect_out(1,string) $expect_out(2,string) $expect_out(3,string)]
exp_continue -continue_timer
} -gl ">>>\$" {
;# exp_break
} -gl "\r" {
exp_continue -continue_timer
} eof {
set errmsg "Exited"
return
} timeout {
set errmsg "Timed-out"
return
}
return $macs
}
|