function for the logs
This commit is contained in:
parent
b8c91f737b
commit
754ad90003
|
@ -10,6 +10,13 @@
|
|||
# - LOG_PLACE
|
||||
# - 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
|
||||
if [ -f creds ]; then
|
||||
source creds
|
||||
|
@ -41,16 +48,16 @@ BOOL_V6=0
|
|||
LOG_PLACE='./vm_id_log/'
|
||||
if [ ! -d "${LOG_PLACE}" ];then
|
||||
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
|
||||
|
||||
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_CACHE='./vm_id_cache/'
|
||||
if [ ! -d "${CHEMIN_CACHE}" ];then
|
||||
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
|
||||
|
||||
# Fonction d'aide
|
||||
|
@ -130,7 +137,7 @@ if [ ${CODE_RETOUR_RES_AUTHENT} -eq 200 ] ;then
|
|||
if [ -n "${VM_IPV4}" ]; then
|
||||
# Ajout de la route associée
|
||||
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
|
||||
BOOL_V4=1
|
||||
else
|
||||
|
@ -162,7 +169,7 @@ if [ ${CODE_RETOUR_RES_AUTHENT} -eq 200 ] ;then
|
|||
if [ -n "${VM_IPV6}" ]; then
|
||||
# Ajout de la route associée
|
||||
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
|
||||
BOOL_V6=1
|
||||
else
|
||||
|
@ -192,7 +199,7 @@ else
|
|||
if [ -n "${VM_IPV4}" ]; then
|
||||
# Ajout de la route associée
|
||||
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
|
||||
BOOL_V4=1
|
||||
else
|
||||
|
@ -221,7 +228,7 @@ else
|
|||
if [ -n "${VM_IPV6}" ]; then
|
||||
# Ajout de la route associée
|
||||
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
|
||||
BOOL_V6=1
|
||||
else
|
||||
|
@ -237,5 +244,5 @@ else
|
|||
fi
|
||||
done
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue