eole-one-master/scripts/onehost_create_all

149 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
# Register all Hâpy Cluster Nodes
#
. /usr/lib/eole/ihm.sh
#
2019-02-22 17:05:11 +01:00
# NAME: copy_ssh_id
# AIM: Copy the ssh key on the host
2019-02-22 17:05:11 +01:00
# PARAM: the hostname of the node
#
function copy_ssh_id()
{
2019-02-22 17:05:11 +01:00
local host=${1}
2019-02-22 17:05:11 +01:00
CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub)
ssh ${host} bash -s <<EOF
if ! grep -qs $CLEF ~oneadmin/.ssh/authorized_keys
then
echo $CLEF >> ~oneadmin/.ssh/authorized_keys
chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
fi
EOF
2019-02-22 17:05:11 +01:00
su - oneadmin -c "ssh-keyscan $host"
return ${?}
}
#
# NAME: register_node
# AIM: register the node in OpenNebula master
# PARAM: the node hostname
#
function register_node()
{
cmd="onehost create -i kvm -v kvm -c 0 ${1}"
ret=$(su - ${ONEUSER} -c -- "${cmd}")
return $?
}
2019-02-25 11:52:47 +01:00
# Fix host creation error from 5.6.1 with sync methode rsync
function sync_host()
{
CMD="onehost"
OPT="sync -f --rsync"
2019-02-25 11:56:15 +01:00
res=$(su - oneadmin -c "${CMD} ${OPT}")
2019-02-25 11:52:47 +01:00
if [[ ${?} -ne 0 ]]
then
error "Hosts sync failed"
else
echo "Hosts sync OK"
fi
}
#
# NAME: wait_node_ok
# AIM: Wait until the node is OK or ERROR
2019-02-22 17:05:11 +01:00
# PARAM: The node name
#
function wait_node_ok()
{
local RET=0
local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'"
local spinstr='|/-\'
local delay=0.75
while [ 1 ]
do
st=$(su - ${ONEUSER} -c "${cmd}")
[[ ${st} == "MONITORED" ]] && break
[[ ${st} == '' ]] && break
if [[ ${st} == "ERROR" ]]
then
2019-02-25 11:52:47 +01:00
RET=50
break
fi
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
return ${RET}
}
#
# MAIN
#
HAPY_ACTIF=$(echo $(CreoleGet activer_onesinglenode))
if [[ $HAPY_ACTIF == "non" ]]
then
EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
exit 1
fi
HAPY_NODE_SUPPORT=$(echo $(CreoleGet activer_multinode))
if [[ $HAPY_NODE_SUPPORT == "non" ]]
then
EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
exit 1
fi
declare -a HAPY_SLV=('')
ONEUSER=$(CreoleGet virt_user)
HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
echo -e "\n"
EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
EchoBleu "Pour ce faire vous devez vous munir du mot de passe de l'utilisateur 'oneadmin' de chacun des noeuds"
Question_ouinon "Voulez-vous commencer ?" 'True' "oui"
if [[ $? -ne 0 ]]
then
EchoOrange "Abandon de l'enregistrement"
exit 1
fi
if [ "$(CreoleGet activer_one_ha)" = "oui" ] && [ "$(CreoleGet one_ha_server_index)" != "0" ]; then
follower=0
else
follower=1
fi
for host in ${HAPY_SLV}; do
echo -e "\n"
EchoOrange "Traitement du noeud ${host}"
echo
EchoVert " * Gestion des clés SSH"
echo
copy_ssh_id ${host}
[[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${host}"
if [ $follower = 0 ]; then
continue
fi
EchoVert " * Enregistrement du noeud"
register_node ${host}
2019-02-25 11:52:47 +01:00
sync_host ${host}
wait_node_ok ${host}
if [[ ${?} -ne 0 ]]
then
EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !"
fi
done
echo -e "\n"
EchoVert "Enregistrement des noeuds terminé"