function for the logs
This commit is contained in:
parent
b8c91f737b
commit
754ad90003
|
@ -10,6 +10,13 @@
|
||||||
# - LOG_PLACE
|
# - LOG_PLACE
|
||||||
# - CHEMIN_CACHE
|
# - CHEMIN_CACHE
|
||||||
|
|
||||||
|
write_log() {
|
||||||
|
# $1: log level (INFO, ERR, etc.)
|
||||||
|
# $2: message
|
||||||
|
printf "$(date -Isecond) - $1: $2\n" >> \
|
||||||
|
${LOG_PLACE}/$(date -Idate)_vm_routing.log
|
||||||
|
}
|
||||||
|
|
||||||
# IPAM creds
|
# IPAM creds
|
||||||
if [ -f creds ]; then
|
if [ -f creds ]; then
|
||||||
source creds
|
source creds
|
||||||
|
@ -41,16 +48,16 @@ BOOL_V6=0
|
||||||
LOG_PLACE='./vm_id_log/'
|
LOG_PLACE='./vm_id_log/'
|
||||||
if [ ! -d "${LOG_PLACE}" ];then
|
if [ ! -d "${LOG_PLACE}" ];then
|
||||||
mkdir -p ${LOG_PLACE}
|
mkdir -p ${LOG_PLACE}
|
||||||
echo "$(date -Isecond) - INFO : Creation du repertoire de logs vm_id" > ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO 'Creation of the log dir'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$(date -Isecond) - INFO : Début de l'exécution du script d'ajout de routes VM" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO 'Beginning of the script execution'
|
||||||
|
|
||||||
# Chemin fichier de CACHE (et création du répertoire s'il n'existe pas)
|
# Chemin fichier de CACHE (et création du répertoire s'il n'existe pas)
|
||||||
CHEMIN_CACHE='./vm_id_cache/'
|
CHEMIN_CACHE='./vm_id_cache/'
|
||||||
if [ ! -d "${CHEMIN_CACHE}" ];then
|
if [ ! -d "${CHEMIN_CACHE}" ];then
|
||||||
mkdir -p ${CHEMIN_CACHE}
|
mkdir -p ${CHEMIN_CACHE}
|
||||||
echo "$(date -Isecond) - INFO : Creation du repertoire de cache vm_id" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO 'Creation of the cache dir'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fonction d'aide
|
# Fonction d'aide
|
||||||
|
@ -64,7 +71,7 @@ if [ $? != 0 ]; then
|
||||||
echo "$(date -Isecond) - ERREUR : probleme au lancement du script" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
echo "$(date -Isecond) - ERREUR : probleme au lancement du script" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# On vérifie la bonne présence d'un paramètre VM_ID
|
# On vérifie la bonne présence d'un paramètre VM_ID
|
||||||
if [ $1 ]; then
|
if [ $1 ]; then
|
||||||
if [ $1 = '-h' ] || [ $1 = '--help' ]; then
|
if [ $1 = '-h' ] || [ $1 = '--help' ]; then
|
||||||
|
@ -130,7 +137,7 @@ if [ ${CODE_RETOUR_RES_AUTHENT} -eq 200 ] ;then
|
||||||
if [ -n "${VM_IPV4}" ]; then
|
if [ -n "${VM_IPV4}" ]; then
|
||||||
# Ajout de la route associée
|
# Ajout de la route associée
|
||||||
echo "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : IPAM)"
|
echo "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : IPAM)"
|
||||||
echo "$(date -Isecond) - INFO : ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : IPAM)" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : IPAM)"
|
||||||
ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0
|
ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0
|
||||||
BOOL_V4=1
|
BOOL_V4=1
|
||||||
else
|
else
|
||||||
|
@ -162,7 +169,7 @@ if [ ${CODE_RETOUR_RES_AUTHENT} -eq 200 ] ;then
|
||||||
if [ -n "${VM_IPV6}" ]; then
|
if [ -n "${VM_IPV6}" ]; then
|
||||||
# Ajout de la route associée
|
# Ajout de la route associée
|
||||||
echo "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source : IPAM)"
|
echo "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source : IPAM)"
|
||||||
echo "$(date -Isecond) - INFO : IPAM : ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source IPAM)"
|
||||||
ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0
|
ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0
|
||||||
BOOL_V6=1
|
BOOL_V6=1
|
||||||
else
|
else
|
||||||
|
@ -192,7 +199,7 @@ else
|
||||||
if [ -n "${VM_IPV4}" ]; then
|
if [ -n "${VM_IPV4}" ]; then
|
||||||
# Ajout de la route associée
|
# Ajout de la route associée
|
||||||
echo "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : CACHE)"
|
echo "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : CACHE)"
|
||||||
echo "$(date -Isecond) - INFO : ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source : CACHE)" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO "ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0 (source: cache)"
|
||||||
ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0
|
ip -4 route add ${VM_IPV4}/32 dev tap${VM_ID}i0
|
||||||
BOOL_V4=1
|
BOOL_V4=1
|
||||||
else
|
else
|
||||||
|
@ -221,7 +228,7 @@ else
|
||||||
if [ -n "${VM_IPV6}" ]; then
|
if [ -n "${VM_IPV6}" ]; then
|
||||||
# Ajout de la route associée
|
# Ajout de la route associée
|
||||||
echo "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source : CACHE)"
|
echo "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source : CACHE)"
|
||||||
echo "$(date -Isecond) - INFO : ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source : CACHE)" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO "ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0 (source: cache)"
|
||||||
ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0
|
ip -6 route add ${VM_IPV6}/48 dev tap${VM_ID}i0
|
||||||
BOOL_V6=1
|
BOOL_V6=1
|
||||||
else
|
else
|
||||||
|
@ -237,5 +244,5 @@ else
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
echo "$(date -Isecond) - INFO : Fin de l'exécution du script d'ajout de routes VM" >> ${LOG_PLACE}/$(date -Idate)_vm_id.log
|
write_log INFO 'Script ended'
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue