From e6ae357838416ddc6ab54d270373d1ce9294760d Mon Sep 17 00:00:00 2001 From: gyptazy Date: Tue, 13 Jan 2026 08:14:24 +0100 Subject: [PATCH] fix(calculations): Fix PSI based balancing which resulted in a Python KeyError Fixes: #420 --- .changelogs/1.1.12/420_fix_psi_based_balancing_key_error.yml | 2 ++ proxlb/models/calculations.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .changelogs/1.1.12/420_fix_psi_based_balancing_key_error.yml diff --git a/.changelogs/1.1.12/420_fix_psi_based_balancing_key_error.yml b/.changelogs/1.1.12/420_fix_psi_based_balancing_key_error.yml new file mode 100644 index 0000000..9f90ae2 --- /dev/null +++ b/.changelogs/1.1.12/420_fix_psi_based_balancing_key_error.yml @@ -0,0 +1,2 @@ +fixed: + - Fix PSI based balancing which resulted in a Python KeyError (@gyptazy). [#420] diff --git a/proxlb/models/calculations.py b/proxlb/models/calculations.py index a475ab8..0703ff7 100644 --- a/proxlb/models/calculations.py +++ b/proxlb/models/calculations.py @@ -418,11 +418,12 @@ class Calculations: break for guest_name in proxlb_data["groups"]["affinity"][group_name]["guests"]: + # Stop moving guests if the source node is no longer the most loaded source_node = proxlb_data["guests"][guest_name]["node_current"] method = proxlb_data["meta"]["balancing"].get("method", "memory") mode = proxlb_data["meta"]["balancing"].get("mode", "used") - highest_node = max(proxlb_data["nodes"].values(), key=lambda n: n[f"{method}_{mode}_percent"]) + highest_node = max(proxlb_data["nodes"].values(), key=lambda n: n[f"{method}_used_percent"]) if highest_node["name"] != source_node: logger.debug(f"Stopping relocation for guest {guest_name}: source node {source_node} is no longer the most loaded node.")