diff --git a/lib_tcl/ssh.tcl b/lib_tcl/ssh.tcl index 98e4d6b..33f5692 100644 --- a/lib_tcl/ssh.tcl +++ b/lib_tcl/ssh.tcl @@ -8,50 +8,50 @@ if {[catch {package require Expect} result]} { namespace eval ::9pm::ssh { proc connect {node args} { - set IP [::9pm::misc::dict::require $node hostname] - set PROMPT [::9pm::misc::dict::require $node prompt] - set PORT [::9pm::misc::dict::get $node port] - set USER [::9pm::misc::dict::get $node username] - set PASS [::9pm::misc::dict::get $node password] - set KEYFILE [::9pm::misc::dict::get $node keyfile] + set hostname [::9pm::misc::dict::require $node hostname] + set prompt [::9pm::misc::dict::require $node prompt] + set port [::9pm::misc::dict::get $node port] + set username [::9pm::misc::dict::get $node username] + set password [::9pm::misc::dict::get $node password] + set keyfile [::9pm::misc::dict::get $node keyfile] set opts [dict get $::9pm::core::rc "ssh_opts"] - set ssh_cmd "ssh $opts $IP" - if {$USER != ""} { - append ssh_cmd " -l $USER" + set ssh_cmd "ssh $opts $hostname" + if {$username != ""} { + append ssh_cmd " -l $username" } - if {$PORT != ""} { - append ssh_cmd " -p $PORT" + if {$port != ""} { + append ssh_cmd " -p $port" } - if {$KEYFILE != ""} { - append ssh_cmd " -i $KEYFILE" + if {$keyfile != ""} { + append ssh_cmd " -i $keyfile" } if {$args != ""} { append ssh_cmd " $args" } - ::9pm::output::debug "Connecting to \"$IP\"" + ::9pm::output::debug "Connecting to \"$hostname\"" expect * send "$ssh_cmd\n" expect { - $PROMPT { - ::9pm::output::debug "Connected to \"$IP\"" + $prompt { + ::9pm::output::debug "Connected to \"$hostname\"" } -nocase "password" { - if {$PASS == ""} { + if {$password == ""} { ::9pm::fatal ::9pm::output::fail \ "SSH got password prompt but no password is provided in config" } - send "$PASS\n" + send "$password\n" exp_continue -continue_timer } timeout { - ::9pm::fatal ::9pm::output::fail "SSH connection to \"$IP\" failed (timeout)" + ::9pm::fatal ::9pm::output::fail "SSH connection to \"$hostname\" failed (timeout)" } eof { - ::9pm::fatal ::9pm::output::fail "SSH connection to \"$IP\" failed (eof)" + ::9pm::fatal ::9pm::output::fail "SSH connection to \"$hostname\" failed (eof)" } } }