airship-in-a-bottle/tools/multi_nodes_gate/airship_gate/lib/ssh.sh
Scott Hussey 4624804f80 Definition for virtual site deployment
- Create a site definition to support a full site deployment
  workflow using VMs

Multi-Nodes Gate

Enable multi-node gate for Airship using core Airship
components.

Deployment will be driven by Shipyard.

We will re-use and adapt the source codes from the Promenade
g2 Gate [1].

[1] https://github.com/openstack/airship-promenade/tree/master/tools/g2

Change-Id: I41e79f5f26311fa179a2e5c121aa815caa05cfcd
2018-07-30 14:12:54 +00:00

61 lines
1.5 KiB
Bash

rsync_cmd() {
rsync -e "ssh -F ${SSH_CONFIG_DIR}/config" "${@}"
}
ssh_cmd() {
HOST=${1}
shift
args=$(shell-quote -- "${@}")
if [[ -v GATE_DEBUG && ${GATE_DEBUG} = "1" ]]; then
ssh -F "${SSH_CONFIG_DIR}/config" -v "${HOST}" "${args}"
else
ssh -F "${SSH_CONFIG_DIR}/config" "${HOST}" "${args}"
fi
}
ssh_config_declare() {
log Creating SSH config
env -i \
"SSH_CONFIG_DIR=${SSH_CONFIG_DIR}" \
envsubst < "${TEMPLATE_DIR}/ssh-config-global.sub" > "${SSH_CONFIG_DIR}/config"
for n in $(config_vm_names)
do
env -i \
"SSH_CONFIG_DIR=${SSH_CONFIG_DIR}" \
"SSH_NODE_HOSTNAME=${n}" \
"SSH_NODE_IP=$(config_vm_ip ${n})" \
envsubst < "${TEMPLATE_DIR}/ssh-config-node.sub" >> "${SSH_CONFIG_DIR}/config"
if [[ "$(config_vm_bootstrap ${n})" == "true" ]]
then
echo " User root" >> "${SSH_CONFIG_DIR}/config"
else
echo " User ubuntu" >> "${SSH_CONFIG_DIR}/config"
fi
done
}
ssh_keypair_declare() {
log Validating SSH keypair exists
if [ ! -s "${SSH_CONFIG_DIR}/id_rsa" ]; then
log Generating SSH keypair
ssh-keygen -N '' -f "${SSH_CONFIG_DIR}/id_rsa" &>> "${LOG_FILE}"
fi
}
ssh_load_pubkey() {
cat "${SSH_CONFIG_DIR}/id_rsa.pub"
}
ssh_setup_declare() {
mkdir -p "${SSH_CONFIG_DIR}"
ssh_keypair_declare
ssh_config_declare
}
ssh_wait() {
NAME=${1}
while ! ssh_cmd "${NAME}" /bin/true; do
sleep 0.5
done
}