Skip to content

Commit

Permalink
ssh: Spell out the full name of node properties
Browse files Browse the repository at this point in the history
Update the node property variable names by spelling them out and in
lower-case to match the style of other files. This is done to not
confuse them with environment variables that traditionally are in
upper-case. There is no functional change.

Signed-off-by: Niklas Söderlund <[email protected]>
  • Loading branch information
neg authored and rical committed Sep 12, 2023
1 parent 3d57595 commit baf7ab9
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib_tcl/ssh.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
}
Expand Down

0 comments on commit baf7ab9

Please sign in to comment.