Ajout de l'utilisation des options --user --password dans le script d'init

ref #17203 @1h
This commit is contained in:
Philippe Caseiro 2016-09-23 14:08:39 +02:00
parent 5fea856bec
commit 33209a8fae
1 changed files with 48 additions and 12 deletions

View File

@ -2,6 +2,38 @@
[ $(CreoleGet hapy_init_master) == non ] && exit 0
function error()
{
MSG=${1}
echo "[ERROR][${MSG}]"
exit 1
}
function get_user_home()
{
HOMEDIR=$(getent passwd ${1} | cut -d ':' -f 6)
echo ${HOMEDIR}
}
function get_one_auth()
{
CMD="cat"
HOME=$(get_user_home oneadmin)
FILE="${HOME}/.one/one_auth"
${CMD} ${FILE}
}
function runOneCmd()
{
local cmd=${1}
local opt=${2}
local auth=$(get_one_auth)
echo "$cmd ${opt} --user ${auth%:*} --password ${auth#*:}"
$cmd ${opt} --user ${auth%:*} --password ${auth#*:}
return ${?}
}
DISKSIZE=$(CreoleGet hapy_init_master_disk_size)
DISKNAME="DSK-${DISKSIZE}-Go"
DISKDESC="Disque vide de ${DISKSIZE} Go"
@ -10,6 +42,7 @@ VERSIONISO=$(CreoleGet hapy_init_master_iso_version)
MAJORVERSION=${VERSIONISO:0:3}
ISONAME="ISO-Eole-${VERSIONISO}-amd64"
ISODESC="Image ISO EOLE Stable ${VERSIONISO} 64 bits"
ISOURL="http://eole.ac-dijon.fr/pub/iso/EOLE-${MAJORVERSION}/${VERSIONISO}/eole-${VERSIONISO}-alternate-amd64.iso"
TMPLNAME="InstallEole-${VERSIONISO}-amd64"
TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 bits (non persistente)"
@ -27,11 +60,17 @@ TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 b
#*****************************************************
# DISQUE VIDE
#*****************************************************
if ! oneimage show "${DISKNAME}" &>/dev/null
if ! runOneCmd "oneimage" "show ${DISKNAME}" &>/dev/null
then
echo "***** Création de ${DISKNAME} *****"
oneimage create -d $(CreoleGet one_ds_image_name) --name "${DISKNAME}" --type DATABLOCK --description "${DISKDESC}" --size $((${DISKSIZE}*1024)) --prefix vd --driver qcow2
oneimage chtype "${DISKNAME}" OS
## Attention oneimage create --datastore ne fonctionne pas dans runOneCmd ...
auth=$(get_one_auth)
oneimage create --datastore $(CreoleGet one_ds_image_name) \
--name ${DISKNAME} --type DATABLOCK --description "${DISKDESC}" \
--size $((${DISKSIZE}*1024)) --prefix vd --driver qcow2 --user ${auth%:*} --password ${auth#*:}
runOneCmd "oneimage" "chtype ${DISKNAME} OS"
else
echo "***** ${DISKNAME} existe déjà *****"
fi
@ -40,10 +79,10 @@ echo
#*****************************************************
# Image ISO EOLE Latest Stable
#*****************************************************
if ! oneimage show "${ISONAME}" &>/dev/null
if ! runOneCmd "oneimage" "show ${ISONAME}" &>/dev/null
then
echo "***** Téléchargement de ${ISONAME} *****"
wget --output-document "/tmp/eole-${VERSIONISO}-alternate-amd64.iso" "http://eole.ac-dijon.fr/pub/iso/EOLE-${MAJORVERSION}/${VERSIONISO}/eole-${VERSIONISO}-alternate-amd64.iso"
wget --output-document "/tmp/eole-${VERSIONISO}-alternate-amd64.iso" ${ISOURL}
echo "***** Création de ${ISONAME} *****"
if [ $? -ne 0 ]; then
echo "Erreur lors du téléchargement, Abandon"
@ -59,15 +98,15 @@ DEV_PREFIX="hd"
PATH="/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
PERSISTENT="No"
EOF
oneimage create -d $(CreoleGet one_ds_iso_name) ${FILE}
runOneCmd "oneimage" "create -d $(CreoleGet one_ds_iso_name) ${FILE}"
/bin/rm -f ${FILE}
for i in `seq 60`
do
sleep 1
#oneimage show ${ISONAME} | grep STATE | grep rdy &>/dev/null && break
oneimage show ${ISONAME} | grep STATE | grep lock &>/dev/null || break
runOneCmd "oneimage" "show ${ISONAME}" | grep STATE | grep lock &>/dev/null || break
echo -n "Attente : "
oneimage show ${ISONAME} | grep STATE
runOneCmd "oneimage" "show ${ISONAME}" | grep STATE
done
rm -f "/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
else
@ -98,11 +137,8 @@ MEMORY="1024"
EOF
#NIC=[MODEL="virtio",NETWORK="CR_eole"]
onetemplate create ${FILE}
runOneCmd "onetemplate" "create ${FILE}"
/bin/rm -f ${FILE}
else