This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenstack_v2v_ova_loop.sh
More file actions
executable file
·58 lines (40 loc) · 1.83 KB
/
openstack_v2v_ova_loop.sh
File metadata and controls
executable file
·58 lines (40 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
TARGET_DIR="$1"
CURRENT_DIR=$( dirname $0 )
LOG_DIR=$( readlink -f $CURRENT_DIR/log )
IMPORT_SCRIPT=$CURRENT_DIR/openstack_v2v_ova_import.sh
CMD_ARG_SCRIPT=${0/.sh/.parme}
CMD_ARG_LST=""
_showUsage() {
echo -e "
Syntaxe :
$( basename $0 ) '/path/containing/ova/or/ovf/files/'
Une recherche de fichiers .ova et .ovf recursive sera effectue dans le repertoire cible
suivie par autant de lancements du script _import.sh que d'exports trouves.
la presence d'un fichier '$( basename $CMD_ARG_SCRIPT )' contenant une ligne unique est supportee
afin de permettre l'usage de parametres pour customiser le script _import.sh.
Ces parametres seront ajoutes a la fin de la commande : $( basename $IMPORT_SCRIPT ) --guest /path/to/file.ova
Exemple de ligne attendue : --os-network net-imported-vm --os-flavor-force m4.medium --os-this-vm-name migrate
Note : Un fichier log est genere par VM a traiter sous $LOG_DIR/
"
}
if [ $# -eq 0 ] || echo "$1" |egrep -i -q '\-(h|help|?|aide)$'; then _showUsage; exit 1; fi
if [ $UID -ne 0 ]; then echo "root or sudo required"; exit 1; fi
if [ ! -d "$TARGET_DIR" ]; then echo "Error: directory '$TARGET_DIR' not found"; exit 1; fi
if [ -s $CMD_ARG_SCRIPT ]; then
echo "Fichier de parametres $CMD_ARG_SCRIPT present ..."
CMD_ARG_LST=$( grep -v '^#' "$CMD_ARG_SCRIPT" )
if [ $? -ne 0 ]; then exit 1; fi
CMD_ARG_LST=$( echo "$CMD_ARG_LST" | head -1 )
echo "Parametres recuperes: $CMD_ARG_LST"
fi
while read -r sTargetOva; do
echo ""
LOG_FILE="$LOG_DIR/$( basename $sTargetOva).log.$( date '+%Y%m%d-%H%M%S' )"
if [ ! -d $LOG_DIR ]; then mkdir -p $LOG_DIR || exit 1; fi
$IMPORT_SCRIPT --guest "$sTargetOva" $CMD_ARG_LST 2>&1 | tee -a $LOG_FILE
#TODO: error control
done < <( find "$TARGET_DIR" -iname "*.ova" -o -iname "*.ovf" )
echo ""
echo "Logs are available in : $LOG_DIR/"
echo "Done"