From 4357e9b15425926f12da87d892eb77efc4b58ca7 Mon Sep 17 00:00:00 2001 From: Joe Beda Date: Tue, 20 Jan 2015 16:47:51 -0800 Subject: [PATCH] Fix SSH for vagrant. This is used as part of the services.sh test. --- cluster/vagrant/util.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index 25cf5358b8e..ca72fa3b690 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -240,7 +240,7 @@ function get-password { } # Find the minion name based on the IP address -function find-minion-by-ip { +function find-vagrant-name-by-ip { local ip="$1" local ip_pattern="${MINION_IP_BASE}(.*)" @@ -253,12 +253,32 @@ function find-minion-by-ip { echo "minion-$((${BASH_REMATCH[1]} - 1))" } -# SSH to a node by name ($1) and run a command ($2). +# Find the vagrant machien name based on the host name of the minion +function find-vagrant-name-by-minion-name { + local ip="$1" + local ip_pattern="${INSTANCE_PREFIX}-minion-(.*)" + + [[ $ip =~ $ip_pattern ]] || { + return 1 + } + + echo "minion-${BASH_REMATCH[1]}" +} + + +# SSH to a node by name or IP ($1) and run a command ($2). function ssh-to-node { local node="$1" local cmd="$2" local machine - machine=$(find-minion-by-ip $node) + + machine=$(find-vagrant-name-by-ip $node) || true + [[ -n ${machine-} ]] || machine=$(find-vagrant-name-by-minion-name $node) || true + [[ -n ${machine-} ]] || { + echo "Cannot find machine to ssh to: $1" + return 1 + } + vagrant ssh "${machine}" -c "${cmd}" | grep -v "Connection to.*closed" }