From bea9a82d7524745cb2c8b5209ad93cd5a0c9b536 Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Thu, 30 Jul 2026 01:08:13 -0400 Subject: [PATCH] =?UTF-8?q?[IMP]=20script=20todo:=20redimension=20?= =?UTF-8?q?=E2=80=94=20avertir=20de=20la=20taille=20max=20soutenable=20(h?= =?UTF-8?q?=C3=B4te)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit À l'agrandissement, on indique désormais l'espace libre de l'hôte et la taille virtuelle MAX « soutenable » ≈ (taille réelle actuelle + libre hôte) — affichée AVANT la saisie pour guider le choix. Si la cible la dépasse, avertissement NON bloquant : le qcow2 est creux, donc OK tant que la VM ne remplit pas, mais au-delà l'hôte tomberait à court d'espace. Ex. : réel 115G + libre 30G -> max soutenable ~145G ; viser 190G affiche « dépasse de ~45G — surallocation ». L'opération n'est pas bloquée. Co-Authored-By: Claude Opus 4.8 (1M context) --- script/todo/todo.py | 31 +++++++++++++++++++++++++++++++ script/todo/todo_i18n.py | 19 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/script/todo/todo.py b/script/todo/todo.py index a60cdc2..e3c93db 100755 --- a/script/todo/todo.py +++ b/script/todo/todo.py @@ -1656,6 +1656,25 @@ class TODO: print(f"{t('Current virtual size:')} {cur_gb:.1f} G") print(f"{t('VM state:')} {state or '?'}") + # Espace HÔTE : le qcow2 est creux (sparse), donc on PEUT fixer une + # taille virtuelle plus grande que l'espace réel — mais si la VM la + # remplit, l'hôte tombe à court. Max « soutenable » ≈ taille réelle + # actuelle + espace libre de l'hôte. On l'AFFICHE (avertissement, pas + # de blocage) pour guider le choix. + g = 1 << 30 + _virt, actual = self._qemu_disk_sizes(disk) + try: + free = shutil.disk_usage(os.path.dirname(disk)).free + except OSError: + free = 0 + max_safe_gb = (actual + free) / g if free else 0 + if max_safe_gb: + print( + f"{t('Host free space:')} {free / g:.1f} G · " + f"{t('max sustainable total (before host full):')} " + f"~{max_safe_gb:.1f} G" + ) + # 2) Nouvelle taille : +NG (agrandir), -NG (réduire) ou NG (cible). guide = t( "Enter +NG to grow, -NG to shrink, or NG for a target size " @@ -1684,6 +1703,18 @@ class TODO: print( f"\n{t('New virtual size:')} {cur_gb:.1f} G -> {new_gb:.1f} G" ) + # Avertissement (NON bloquant) : agrandir au-delà de ce que l'hôte + # peut soutenir -> surallocation, l'hôte se remplira si la VM utilise + # tout l'espace. + if not shrink and max_safe_gb and new_gb > max_safe_gb: + over = new_gb - max_safe_gb + msg1 = t("Beyond host capacity by ~%.1f G — overcommit.") % over + msg2 = t( + "The qcow2 is thin: fine until the VM fills it, then the " + "host disk runs out. Max sustainable: ~%.1f G." + ) % max_safe_gb + print(f"⚠ {msg1}") + print(f" {msg2}") # 3) Application selon agrandir/réduire et l'état de la VM. was_shut_down = False # la VM a-t-elle été éteinte pour l'occasion ? diff --git a/script/todo/todo_i18n.py b/script/todo/todo_i18n.py index f0ea608..e93d5ef 100644 --- a/script/todo/todo_i18n.py +++ b/script/todo/todo_i18n.py @@ -1424,6 +1424,25 @@ TRANSLATIONS = { "fr": "Impossible de lire la taille actuelle du disque ; abandon.", "en": "Could not read current disk size; aborting.", }, + "Host free space:": { + "fr": "Espace libre hôte :", + "en": "Host free space:", + }, + "max sustainable total (before host full):": { + "fr": "max soutenable au total (avant hôte plein) :", + "en": "max sustainable total (before host full):", + }, + "Beyond host capacity by ~%.1f G — overcommit.": { + "fr": "Dépasse la capacité de l'hôte de ~%.1f G — surallocation.", + "en": "Beyond host capacity by ~%.1f G — overcommit.", + }, + "The qcow2 is thin: fine until the VM fills it, then the " + "host disk runs out. Max sustainable: ~%.1f G.": { + "fr": "Le qcow2 est creux : OK tant que la VM ne remplit pas, sinon " + "l'hôte tombe à court. Max soutenable : ~%.1f G.", + "en": "The qcow2 is thin: fine until the VM fills it, then the " + "host disk runs out. Max sustainable: ~%.1f G.", + }, "Safe shrink needs libguestfs (virt-resize).": { "fr": "La réduction sûre nécessite libguestfs (virt-resize).", "en": "Safe shrink needs libguestfs (virt-resize).",