Ajout de 99-init-hapy-master permettant la création d'un disque dur

vierge, l'ajout de l'image ISO EOLE, et l'ajout d'un template pour
installer un module EOLE REF #15946 @4h
This commit is contained in:
Klaas TJEBBES 2016-04-25 15:50:15 +02:00
parent 8563a5d47f
commit 861eb1a3bd
2 changed files with 125 additions and 1 deletions

View File

@ -68,6 +68,15 @@
<variable name='activer_hooks' type='oui/non' description="Utiliser des hook personnalisés" mode='expert'> <variable name='activer_hooks' type='oui/non' description="Utiliser des hook personnalisés" mode='expert'>
<value>non</value> <value>non</value>
</variable> </variable>
<variable name='hapy_init_master' type='oui/non' description="Pré-paramétrer Hapy">
<value>non</value>
</variable>
<variable name='hapy_init_master_disk_size' type='number' description="Taille en Giga-octets du disque dur vierge">
<value>40</value>
</variable>
<variable name='hapy_init_master_iso_version' type='string' description="Version de l'image ISO EOLE à télécharger">
<value>2.5.2</value>
</variable>
</family> </family>
<family name='Hooks'> <family name='Hooks'>
<variable name='hapy_vm_hooks' type='oui/non' description="Hooks sur les VM" mode='expert' mandatory='True'> <variable name='hapy_vm_hooks' type='oui/non' description="Hooks sur les VM" mode='expert' mandatory='True'>
@ -205,7 +214,7 @@
<slave>hapy_vm_hook_state</slave> <slave>hapy_vm_hook_state</slave>
<slave>hapy_vm_hook_lcm_state</slave> <slave>hapy_vm_hook_lcm_state</slave>
</group> </group>
<check name="valid_enum" target="hapy_user_hook_on"> <check name="valid_enum" target="hapy_user_hook_on">
<param>['CREATE','REMOVE']</param> <param>['CREATE','REMOVE']</param>
</check> </check>
@ -219,6 +228,11 @@
<slave>hapy_user_hook_command</slave> <slave>hapy_user_hook_command</slave>
<slave>hapy_user_hook_arguments</slave> <slave>hapy_user_hook_arguments</slave>
</group> </group>
<condition name='hidden_if_in' source='hapy_init_master'>
<param>non</param>
<target type='variable'>hapy_init_master_disk_size</target>
<target type='variable'>hapy_init_master_iso_version</target>
</condition>
</constraints> </constraints>
<help> <help>
@ -236,5 +250,7 @@
<variable name='hapy_user_hook_on'>Déclancheur du Hook (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable> <variable name='hapy_user_hook_on'>Déclancheur du Hook (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable>
<variable name='hapy_user_hook_command'>Script lancé par le Hook (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable> <variable name='hapy_user_hook_command'>Script lancé par le Hook (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable>
<variable name='hapy_user_hook_arguments'>Arguments passés au script lancé par le Hook d'utilisateur (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable> <variable name='hapy_user_hook_arguments'>Arguments passés au script lancé par le Hook d'utilisateur (cf: http://docs.opennebula.org/4.8/integration/infrastructure_integration/hooks.html)</variable>
<variable name='hapy_init_master'>Initialiser Hâpy avec quelques fonctions de bases : ISO EOLE, Disque dur vierge et template d'installation d'EoleBase. ATTENTION, provoque le téléchargement de l'ISO EOLE</variable>
<variable name='hapy_init_master_iso_version'>Version de l'ISO EOLE à télécharger lors de l'initialisation</variable>
</help> </help>
</creole> </creole>

108
postservice/99-init-hapy-master Executable file
View File

@ -0,0 +1,108 @@
#!/bin/bash
[ $(CreoleGet hapy_init_master) == non ] && exit 0
DISKSIZE=$(CreoleGet hapy_init_master_disk_size)
DISKNAME="DSK-${DISKSIZE}-Go"
DISKDESC="Disque vide de ${DISKSIZE} Go"
VERSIONISO=$(CreoleGet hapy_init_master_iso_version)
MAJORVERSION=${VERSIONISO:0:3}
ISONAME="ISO-Eole-${VERSIONISO}-amd64"
ISODESC="Image ISO EOLE Stable ${VERSIONISO} 64 bits"
TMPLNAME="InstallEole-${VERSIONISO}-amd64"
TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 bits (non persistente)"
echo "########### suppr ${DISKNAME} ###############"
oneimage delete ${DISKNAME}
echo
echo "########### suppr ${ISONAME} ###################"
oneimage delete ${ISONAME}
echo
echo "########### suppr ${TMPLNAME} ###################"
onetemplate delete ${TMPLNAME}
echo
#*****************************************************
# DISQUE VIDE
#*****************************************************
if ! 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 --fstype qcow2
oneimage chtype "${DISKNAME}" OS
else
echo "***** ${DISKNAME} existe déjà *****"
fi
echo
#*****************************************************
# Image ISO EOLE Latest Stable
#*****************************************************
if ! 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"
echo "***** Création de ${ISONAME} *****"
if [ $? -ne 0 ]; then
echo "Erreur lors du téléchargement, Abandon"
exit 1
fi
FILE=$(mktemp)
cat > ${FILE} <<EOF
NAME="${ISONAME}"
TYPE="CDROM"
DESCRIPTION="${ISODESC}"
DEV_PREFIX="hd"
PATH="/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
PERSISTENT="No"
EOF
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
echo -n "Attente : "
oneimage show ${ISONAME} | grep STATE
done
rm -f "/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
else
echo "***** ${ISONAME} existe déjà *****"
fi
echo
#*****************************************************
# Template EOLEBASE
#*****************************************************
if ! onetemplate show "${TMPLNAME}" &>/dev/null
then
echo "***** Création de ${TMPLNAME} *****"
FILE=$(mktemp)
cat > ${FILE} <<EOF
NAME="${TMPLNAME}"
DESCRIPTION="${TMPLDESC}"
INPUT=[BUS="usb",TYPE="tablet"]
CPU="0.2"
DISK=[DEV_PREFIX="vd",IMAGE_UNAME="oneadmin",IMAGE="${DISKNAME}",DRIVER="qcow2"]
DISK=[DEV_PREFIX="hd",IMAGE_UNAME="oneadmin",IMAGE="${ISONAME}",DRIVER="raw"]
FEATURES=[ACPI="yes",PAE="no",LOCALTIME="yes"]
VCPU="1"
GRAPHICS=[LISTEN="0.0.0.0",TYPE="vnc",KEYMAP="fr"]
OS=[BOOT="hd,cdrom",ARCH="x86_64"]
MEMORY="1024"
EOF
#NIC=[MODEL="virtio",NETWORK="CR_eole"]
onetemplate create ${FILE}
/bin/rm -f ${FILE}
else
echo "***** ${TMPLNAME} existe déjà *****"
fi
echo
exit 0