Functional: Set private key outside of remote_exec

We get priv_key in remote_exec, so every time we call remote_exec, we
need to compute it again, this can be move out.

Closes-Bug: #1552502
Change-Id: Id44cd5e98f070985feef2583162bd21bca44baf2
This commit is contained in:
Eli Qiao 2016-03-03 09:58:22 +08:00
parent 24f1d6f9e2
commit 30a436cf49
1 changed files with 10 additions and 9 deletions

View File

@ -23,20 +23,21 @@ COE=${2-kubernetes}
NODE_TYPE=${3-master}
LOG_PATH=/opt/stack/logs/bay-nodes/${NODE_TYPE}-${SSH_IP}
KEYPAIR=${4-default}
PRIVATE_KEY=
echo "If private key is specified, save to temp and use that; else, use default"
if [[ "$KEYPAIR" == "default" ]]; then
PRIVATE_KEY="~/.ssh/id_rsa"
else
PRIVATE_KEY="$(mktemp id_rsa.$SSH_IP.XXX)"
echo -en "$KEYPAIR" > $PRIVATE_KEY
fi
function remote_exec {
local priv_key
echo "If private key is specified, save to temp and use that; else, use default"
if [[ "$KEYPAIR" == "default" ]]; then
priv_key="~/.ssh/id_rsa"
else
priv_key="$(mktemp id_rsa.$SSH_IP.XXX)"
echo -en "$KEYPAIR" > $priv_key
fi
local ssh_user=$1
local cmd=$2
local logfile=${LOG_PATH}/$3
ssh -i $priv_key -o StrictHostKeyChecking=no ${ssh_user}@${SSH_IP} "${cmd}" > ${logfile} 2>&1
ssh -i $PRIVATE_KEY -o StrictHostKeyChecking=no ${ssh_user}@${SSH_IP} "${cmd}" > ${logfile} 2>&1
}
mkdir -p $LOG_PATH