From 42b9842b8ed0c92cc4a8fcfa3ec8c7d34bc15574 Mon Sep 17 00:00:00 2001 From: "pu!s@r" Date: Sun, 27 Mar 2022 19:04:14 +0200 Subject: [PATCH] =?UTF-8?q?Ajouter=20l'option=20--move=20pour=20d=C3=A9pla?= =?UTF-8?q?cer=20un=20conteneur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- balance-containers/run.bash | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/balance-containers/run.bash b/balance-containers/run.bash index 9d9d578..10a2f41 100755 --- a/balance-containers/run.bash +++ b/balance-containers/run.bash @@ -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 : move containers on local host to target" + echo " --balance: move containers" + echo " --list: generate list of current balance (used by --balance)" + echo " --migrate : migrate all local containers to target" + echo " --move : 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