cvk98 / Proxmox-load-balancer

Designed to constantly maintain the Proxmox cluster in balance
GNU General Public License v3.0
171 stars 20 forks source link

Trivial patch to disable looping (for crond) #35

Open kjj2 opened 1 month ago

kjj2 commented 1 month ago

This patch adds loop to the parameters section of the config file. If this is not set, or set to Off, the script will exit at the end of a balancing run. This is useful if you want to avoid having the load balancer run while (for example) backups are running.

--- plb.py      2024-05-21 04:56:39.802275066 -0500
+++ plb-loop_option.py   2024-05-21 04:52:25.979306790 -0500
@@ -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)
+LOOP = cfg["parameters"].get("loop", False)

 """Exclusions"""
 excluded_vms = []
@@ -485,9 +574,13 @@
             sleep(60)
             pass  # TODO Aggressive algorithm
     else:
-        logger.info('The cluster is balanced. Waiting 300 seconds.')
-        iteration += 1
-        sleep(300)
+        if LOOP:
+            logger.info('The cluster is balanced. Waiting 300 seconds.')
+            iteration += 1
+            sleep(300)
+        else:
+            logger.info('Looping not enabled.  exiting.')
+            sys.exit(0)

 while True: