Merge pull request #1891 from jbeda/vagrant-bash-fix

Make vagrant scripts work with bash 3
pull/6/head
Joe Beda 2014-10-20 14:52:12 -07:00
commit 60a8249bdf
2 changed files with 17 additions and 6 deletions

View File

@ -31,13 +31,9 @@ MINION_TAG="${INSTANCE_PREFIX}-minion"
# IP LOCATIONS FOR INTERACTING WITH THE MINIONS
MINION_IP_BASE="10.245.2."
declare -A VAGRANT_MINION_NAMES_BY_IP
for (( i=0; i <${NUM_MINIONS}; i++)) do
for ((i=0; i < NUM_MINIONS; i++)) do
KUBE_MINION_IP_ADDRESSES[$i]="${MINION_IP_BASE}$[$i+2]"
MINION_IP[$i]="${MINION_IP_BASE}$[$i+2]"
MINION_NAMES[$i]="${MINION_IP[$i]}"
VAGRANT_MINION_NAMES[$i]="minion-$[$i+1]"
VAGRANT_MINION_NAMES_BY_IP["${MINION_IP[$i]}"]="${VAGRANT_MINION_NAMES[$i]}"
done

View File

@ -144,11 +144,26 @@ function get-password {
echo "Using credentials: $KUBE_USER:$KUBE_PASSWORD"
}
# Find the minion name based on the IP address
function find-minion-by-ip {
local ip="$1"
local ip_pattern="${MINION_IP_BASE}(.*)"
# This is subtle. We map 10.245.2.2 -> minion-1. We do this by matching a
# regexp and using the capture to construct the name.
[[ $ip =~ $ip_pattern ]] || {
return 1
}
echo "minion-$((${BASH_REMATCH[1]} - 1))"
}
# SSH to a node by name ($1) and run a command ($2).
function ssh-to-node {
local node="$1"
local cmd="$2"
local machine="${VAGRANT_MINION_NAMES_BY_IP[${node}]}"
local machine
machine=$(find-minion-by-ip $node)
vagrant ssh "${machine}" -c "${cmd}" | grep -v "Connection to.*closed"
}