From 08ecf371e139583eda18f851fa5f1d0433cb031f Mon Sep 17 00:00:00 2001 From: Pin-Shao Chen Date: Tue, 14 May 2024 08:21:11 +0000 Subject: [PATCH] Add dry run setting --- config.yaml | 1 + plb.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/config.yaml b/config.yaml index 247aba8..b0085a9 100644 --- a/config.yaml +++ b/config.yaml @@ -15,6 +15,7 @@ parameters: lxc_migration: OFF # Container migration (LXCs are rebooted during migration!!!) migration_timeout: 1000 # For the future only_on_master: OFF # Only run PLB on the current cluster master + dry_run: OFF # Dry run (don't balance) # List of exclusions exclusions: diff --git a/plb.py b/plb.py index b816edc..a9a995e 100644 --- a/plb.py +++ b/plb.py @@ -32,6 +32,7 @@ LXC_MIGRATION = cfg["parameters"]["lxc_migration"] MIGRATION_TIMEOUT = cfg["parameters"]["migration_timeout"] ONLY_ON_MASTER = cfg["parameters"].get("only_on_master", False) +DRY_RUN = cfg["parameters"]["dry_run"] """Exclusions""" excluded_vms = [] @@ -372,6 +373,10 @@ def vm_migration(variants: list, cluster_obj: object) -> None: sys.exit(1) donor, recipient, vm = variant[:3] logger.debug(f'VM:{vm} migration from {donor} to {recipient}') + if DRY_RUN: + logger.info('DRY RUN, stop here.') + break + if vm in cluster_obj.cl_lxcs: options = {'target': recipient, 'restart': 1} url = f'{cluster_obj.server}/api2/json/nodes/{donor}/lxc/{vm}/migrate'