1
0

Ajouter l'option --move pour déplacer un conteneur

This commit is contained in:
pulsar89.5 2022-03-27 19:04:14 +02:00
parent bad78bb572
commit 42b9842b8e

View File

@ -14,9 +14,10 @@ show_usage() {
echo "Usage: ${currentPath}/${scriptName} [options [parameters]]"
echo
echo "Options:"
echo " -b or --balance: move containers"
echo " -l or --list: generate list of current balance (used by --balance)"
echo " -m or --migrate <target>: move containers on local host to target"
echo " --balance: move containers"
echo " --list: generate list of current balance (used by --balance)"
echo " --migrate <target>: migrate all local containers to target"
echo " --move <target> <container>: move container to target"
}
move_ct() {
@ -26,8 +27,8 @@ move_ct() {
}
migrate_ct() {
echo "- $ct:"
echo " target: $ct:"
echo "- container: $ct"
echo " target: $target"
echo " processing:"
# SI le conteneur est démarré
@ -53,10 +54,10 @@ migrate_ct() {
# Boucler sur les arguments
case "${1}" in
-l|--list)
--list)
lxc list --columns Ln --format csv 2> /dev/null | tee $containersList
;;
-b|--balance)
--balance)
while read line; do
# Découper les informations
target=$(echo $line | awk -F',' '{print $1}')
@ -71,7 +72,7 @@ case "${1}" in
fi
done < $containersList
;;
-m|--migrate)
--migrate)
# Vérifier la présence d'une cible
[[ -z "${2}" ]] && show_usage && exit
@ -84,6 +85,22 @@ case "${1}" in
migrate_ct
done
;;
--move)
# Vérifier la présence d'une cible
[[ -z "${2}" ]] && show_usage && exit
# Stocker la cible
target="${2}"
# Vérifier la présence d'un conteneur
[[ -z "${3}" ]] && show_usage && exit
# Stocker le conteneur
ct="${3}"
# Effectuer la migration
migrate_ct
;;
*)
show_usage;
esac