Compare commits

..

159 Commits

Author SHA1 Message Date
gyptazy
a8a154abde Merge pull request #316 from gyptazy/fix/missing-1.1.7-version
release: Replace missing 1.1.7 version
2025-09-19 10:12:53 +02:00
Florian Paul Azim Hoberg
554a3eaf72 release: Replace missing 1.1.7 version 2025-09-19 10:11:54 +02:00
gyptazy
0b35987403 Merge pull request #315 from gyptazy/release/create-release-1.7
release: Add release 1.1.7 information
2025-09-19 10:08:42 +02:00
Florian Paul Azim Hoberg
d93048db69 release: Add release 1.1.7 information
Fixes: #314
2025-09-19 07:54:01 +02:00
gyptazy
2aba7dbe23 Merge pull request #313 from gyptazy/adjust-style
fix: Add missing new lines
2025-09-19 07:41:30 +02:00
Florian Paul Azim Hoberg
ba388dfd7c fix: Add missing new lines 2025-09-19 07:39:42 +02:00
gyptazy
5aa8257d40 Merge pull request #311 from gyptazy/fix/310-guest-object-names-not-being-evaluated-in-log
fix: Fix guest object names are not being evaluated in debug log.
2025-09-15 09:53:26 +02:00
Florian Paul Azim Hoberg
99fefe20bf fix: Fix guest object names are not being evaluated in debug log.
Fixes: #310
2025-09-15 09:48:59 +02:00
gyptazy
b9fb3a60e1 Merge pull request #309 from gyptazy/fix/308-fix-validating-migration-job-ids
fix: Fix crash when validating absent migration job ids
2025-09-15 09:29:00 +02:00
Florian Paul Azim Hoberg
88b3288eb7 fix: Fix crash when validating absent migration job ids
Fixes: #308
2025-09-15 09:26:01 +02:00
gyptazy
fa0113f112 Merge pull request #307 from gyptazy/feature/304-catch-keyboard-interrupt
Add graceful shutdown for SIGINT (e.g., CTRL + C abort).
2025-09-15 07:30:30 +02:00
Florian Paul Azim Hoberg
0039ae9093 Add graceful shutdown for SIGINT (e.g., CTRL + C abort).
Fixes: #304
2025-09-15 07:26:03 +02:00
gyptazy
e3bbf31fdd Merge pull request #306 from gyptazy/feature/305-add-conntrack-options-for-migrations
feature: Add conntrack state aware migrations of VMs.
2025-09-15 07:10:30 +02:00
Florian Paul Azim Hoberg
bf393c6bbf feature: Add conntrack state aware migrations of VMs.
Fixes: #305
2025-09-15 06:59:41 +02:00
gyptazy
7e5b72cfc7 docs: Adjust container version to 1.1.6.1 2025-09-04 17:39:43 +02:00
gyptazy
0ba76f80f3 Merge pull request #302 from gyptazy/fix/296-vm
fix: Validate for node presence when pinning VMs to avoid crashing
2025-09-04 17:33:47 +02:00
gyptazy
b48ff9d677 fix: Validate for node presence when pinning VMs to avoid crashing
Fixes: #296
2025-09-04 17:31:24 +02:00
gyptazy
b5c11af474 Merge pull request #301 from gyptazy/gyptazy-patch-1
Set image version to 1.1.6
2025-09-04 08:34:49 +02:00
gyptazy
af2992747d Set image version to 1.1.6 2025-09-04 08:34:23 +02:00
gyptazy
fb8dc40c16 Merge pull request #300 from gyptazy/release/1.1.6
release: Create release 1.1.6
2025-09-04 07:55:38 +02:00
Florian Paul Azim Hoberg
34f1de8367 release: Create release 1.1.6
Fixes: #297
2025-09-04 07:53:29 +02:00
gyptazy
0e992e99de Merge pull request #298 from gyptazy/fix/296-validate-node-presence-when-pinning
fix: Validate for node presence when pinning guests to avoid crashing
2025-08-29 11:33:29 +02:00
gyptazy
f5d073dc02 fix: Validate for node presence when pinning guests to avoid crashing
Fixes: #296
Fixes: #271
2025-08-29 11:26:15 +02:00
gyptazy
70ba1f2dfc Merge pull request #295 from MiBUl-eu/main
fix: overprovisioning first node if anti_affinity group has only one member
2025-08-28 17:16:28 +02:00
MiBUl-eu
c9855f1991 Added changeloge and fixed typo 2025-08-26 10:34:48 +00:00
MiBUl-eu
9bd29158b9 fix: overprovisioning first node if anti_affinity group has only one member 2025-08-25 10:11:45 +02:00
gyptazy
1ff0c5d96e Merge pull request #293 from gyptazy/feature/290-validate-token-input-from-config-file
feature: Add validation for provided API user token id to avoid confusions
2025-08-25 08:11:56 +02:00
Florian Paul Azim Hoberg
3eb4038723 feature: Add validation for provided API user token id to avoid confusions
Fixes: #290
2025-08-25 08:07:44 +02:00
gyptazy
47e7dd3c56 Merge pull request #292 from gyptazy/fix/291-catch-stack-trace-when-user-account-is-not-given-or-wrong
fix(proxmox-api): Fix stacktrace output when validating permissions on non existing users in Proxmox
2025-08-25 07:58:32 +02:00
Florian Paul Azim Hoberg
bb8cf9033d fix(proxmox-api): Fix stacktrace output when validating permissions on non existing users in Proxmox
Fixes: #291
2025-08-25 07:55:02 +02:00
gyptazy
756b4efcbd Merge pull request #288 from gyptazy/feature/281-helm-chart-versioning
feature: Add Helm chart support for ProxLB
2025-08-19 06:28:31 +02:00
gyptazy
8630333e4b feature: Add Helm chart support for ProxLB
Fixes: #281
2025-08-19 06:27:38 +02:00
gyptazy
7bd9a9b038 Merge pull request #282 from MaoMaoCake/main
Feat: Add support for helm
2025-08-18 19:31:14 +02:00
maomaocake
16651351de Implemented changes from comments 2025-08-18 12:46:29 +07:00
maomaocake
63805f1f50 Added support for resource limits and requests 2025-08-17 16:11:18 +07:00
maomaocake
c0ff1b5273 Added support for new user defined labels 2025-08-17 15:59:17 +07:00
maomaocake
07f8596fc5 Helm Chart 2025-08-17 15:41:55 +07:00
Florian
affbe433f9 Merge pull request #280 from gyptazy/docs/fix-ipv6-example-syntax
docs: Fix IPv6 address syntax in given examples
2025-08-06 16:42:13 +02:00
Florian Paul Azim Hoberg
7bda22e754 docs: Fix IPv6 address syntax in given examples 2025-08-06 16:38:23 +02:00
Florian
253dcf8eb9 Merge pull request #274 from gyptazy/docs/273-proxmox-9-compatibility
docs: Add compatibility matrix of tested Proxmox versions
2025-07-20 12:37:20 +02:00
gyptazy
6212d23268 docs: Add compatibility matrix of tested Proxmox versions
Fixes: #273
2025-07-20 12:36:25 +02:00
Florian
cf8c06393f Merge pull request #270 from gyptazy/docs/258-extend-doc-of-cluster-node-names-usage
docs: Adjust docs regarding maintenance node hostnames
2025-07-17 11:53:33 +02:00
Florian Paul Azim Hoberg
5c23fd3433 docs: Adjust docs regarding maintenance node hostnames
Fixes: #258
2025-07-17 11:52:08 +02:00
Florian
0fb732fc8c Merge pull request #269 from gyptazy/fix/268-evaluate-balancing-types
fix: Fix balancing evaluation of guest types (e.g., VM or CT).
2025-07-17 11:44:29 +02:00
Florian Paul Azim Hoberg
f36d96c72a fix: Fix balancing evaluation of guest types (e.g., VM or CT).
Fixes: #268
2025-07-17 11:41:00 +02:00
Florian
9cc03717ef Merge pull request #267 from gyptazy/release/1.1.5
release: Create release 1.1.5
2025-07-14 11:13:12 +02:00
Florian Paul Azim Hoberg
4848887ccc release: Create release 1.1.5
Fixes: #266
2025-07-14 11:08:38 +02:00
Gombócz Márton
04476feeaf Docs/custom api port (#264)
* docs(README.md): added description and examples of port declaration in hosts
* docs(docs/03_configuration): updated hosts description about using ports
2025-07-10 10:33:44 +02:00
Florian
b3765bf0ae Merge pull request #261 from gyptazy/feature/260-custom-api-ports
feature: Allow custom (instead of static tcp/8006) API ports for API hosts
2025-07-10 09:19:34 +02:00
Florian Paul Azim Hoberg
806b728a14 feature: Allow custom (instead of static tcp/8006) API ports for API hosts.
Fixes: #260
2025-07-08 17:39:29 +02:00
Florian
2c34ec91b1 Merge pull request #257 from gyptazy/release/prepare-1.1.5
release: Create release 1.1.5 beta 1
2025-06-29 11:08:15 +02:00
gyptazy
08b746a53b release: Create release 1.1.5 beta 1 2025-06-27 16:50:17 +02:00
Florian
615e2f5608 Merge pull request #256 from gyptazy/release/1.1.4
release: Create release 1.1.4
2025-06-27 16:40:53 +02:00
gyptazy
fa1e1ad8a3 release: Create release 1.1.4
Fixes: #254
2025-06-27 16:23:31 +02:00
pmarasse
c78def3919 Fix loglevels (#255)
* Modified some loglevels to make output lighter at INFO level

Co-authored-by: Philippe MARASSE <philippe@marasse.fr>
2025-06-27 15:10:57 +02:00
Florian
54c53b9860 Merge pull request #253 from gyptazy/feature/245-add-guest-pinning-to-group-of-nodes
feature: Allow pinning of guests to a group of nodes
2025-06-26 13:59:44 +02:00
Florian Paul Azim Hoberg
1fe8f703cc feature: Allow pinning of guests to a group of nodes
* You can now simply define multiple tags with plb_pin_node names
    where nodes are being evaluated and the one with the lowest
    resource usage will be taken.

Fixes: #245
2025-06-26 13:54:05 +02:00
Florian
7ba806abf7 Merge pull request #252 from gyptazy/fix/248-dry-run-with-deactivated-balancing
Fix an issue where balancing was performed in combination of deactivated balancing and dry-run mode
2025-06-24 10:09:10 +02:00
Florian Paul Azim Hoberg
6b2e120739 Fix: Fixed an issue where balancing was performed in combination of deactivated balancing and dry-run mode
Fixes: #248
2025-06-24 10:06:28 +02:00
Florian
e4103df326 Merge pull request #251 from gyptazy/prepare/1.1.4
release: Prepare release 1.1.4 beta
2025-06-24 10:00:27 +02:00
Florian Paul Azim Hoberg
f2acd4efa6 release: Prepare release 1.1.4 beta 2025-06-24 09:56:06 +02:00
Florian
f4ed8d9928 Merge pull request #247 from gyptazy/fix/readme-1.1.3
fix: Adjust readme for Container image version of release 1.1.3.
2025-06-19 09:32:13 +02:00
gyptazy
ba74254b93 fix: Adjust readme for Container image version of release 1.1.3. 2025-06-19 09:31:31 +02:00
Florian
792a0f3820 Merge pull request #246 from gyptazy/release/1.1.3
release: Prepare release 1.1.3
2025-06-19 09:30:31 +02:00
gyptazy
b766041c4c release: Prepare release 1.1.3
Fixes: #242
2025-06-19 09:25:56 +02:00
Florian
a31e41f839 Merge pull request #243 from gyptazy/feature/241-make-amount-of-parallel-migrations-configureable
feature: Make the amount of parallel migrations configurable
2025-06-10 18:46:39 +02:00
gyptazy
7cb5a31b89 feature: Make the amount of parallel migrations configurable
Fixes: #241
2025-06-05 16:12:47 +02:00
Florian
617d0a3ae3 Merge pull request #240 from gyptazy/feature/239-add-optional-wait-time-until-service-starts
feature: Add optional wait time before service action.
2025-06-04 16:49:24 +02:00
gyptazy
db3a3b77fc feature: Add optional wait time before service action.
Fixes: #239
2025-06-01 16:06:42 +02:00
Florian
5a9643275a Merge pull request #237 from gyptazy/feature/94-balance-cpu-by-average-consumption
feature:  Use the average CPU consumption of a guest within the last 60 minutes instead of the current CPU usage
2025-05-29 12:01:13 +02:00
Florian
60d1e333aa Merge pull request #238 from gyptazy/feature/189-add-reload-function
feature: Add relaod (SIGHUP) function to ProxLB to reload the configuration.
2025-05-29 12:00:42 +02:00
gyptazy
96dc435cf6 feature: Add relaod (SIGHUP) function to ProxLB to reload the configuration.
Fixes: #189
2025-05-24 09:56:20 +02:00
gyptazy
263b08b53a feature: Add reload method to ProxLB systemd file
Fixes: #189
2025-05-24 09:19:42 +02:00
gyptazy
89102d517e feature: Use the average CPU consumption of a guest within the last 60 minutes instead of the current CPU usage
- Using the current CPU consumption of a guest object is too volatile and does not represent
    the real usage. Therefore, we use the average consumption of the cpu values within the
    last 60 minutes.

Thanks-to: @philslab-ninja
Fixes: #94
2025-05-24 09:17:14 +02:00
Florian
845af4abc8 Merge pull request #236 from gyptazy/prepare/dev1.1.3beta
development: Adjust beta release 1.1.3
2025-05-22 13:42:05 +02:00
gyptazy
3e02403598 development: Adjust beta release 1.1.3 2025-05-22 06:58:53 +02:00
Florian
0b0d569877 Merge pull request #235 from gyptazy/feature/232-align-proxmox-ha-maintenance-mode
feature: Align maintenance mode with Proxmox HA maintenance mode
2025-05-22 06:55:32 +02:00
Florian Paul Azim Hoberg
1cbda2e2f9 feature: Align maintenance mode with Proxmox HA maintenance mode
Fixes: #232
2025-05-21 18:19:50 +02:00
gyptazy
b6febf1933 feature: Add action to create multiarch container 2025-05-20 19:57:04 +02:00
Florian
53a6d2a459 Merge pull request #233 from gyptazy/feature/231-arm64-container
feature: Add workflows to build container images for AMD64 + ARM64 architecture
2025-05-20 12:11:03 +02:00
Florian Paul Azim Hoberg
6c82ce010b feature: Add workflows to build container images for AMD64 + ARM64 architecture
Fixes: #231
2025-05-20 12:06:22 +02:00
Florian
4b8b73e468 Merge pull request #228 from gyptazy/release/1.1.2-readme
docs: Update readme with new image version
2025-05-13 08:26:48 +02:00
Florian Paul Azim Hoberg
a75729dd6a docs: Update readme with new image version 2025-05-13 08:26:03 +02:00
Florian
b8792a87af Merge pull request #227 from gyptazy/release/1.1.2
release: Create release 1.1.2
2025-05-13 08:18:23 +02:00
Florian Paul Azim Hoberg
c1261a2d3c release: Create release 1.1.2
Fixes: #226
2025-05-13 08:13:43 +02:00
Florian
0035f57738 Merge pull request #223 from gyptazy/fix/222-extend-debug-messages
fix: Force type cast guest cpu count to int where in some corner cases a str got returned.
2025-05-08 16:23:10 +02:00
gyptazy
b372d361e7 fix: Force type cast guest cpu count to int where in some corner cases a str got returned.
Fixes: #222
2025-05-03 08:53:56 +02:00
Florian
1e096e1aae Merge pull request #221 from gyptazy/fix/137-systemd-unit-file
fix: Adjust the systemd unit file to run after the network target on non PVE nodes
2025-04-26 08:43:33 +02:00
gyptazy
420d669236 fix: Adjust the systemd unit file to run after the network target on non PVE nodes
Fixes: #137
2025-04-26 08:42:24 +02:00
Florian
24aa6aabc6 Merge pull request #220 from gyptazy/feature/157-add-retry-proxmox-api
feature: Add a retry mechanism when connecting to the Proxmox API
2025-04-24 13:49:55 +02:00
Florian Paul Azim Hoberg
5a9a4af532 feature: Add a retry mechanism when connecting to the Proxmox API
Fixes: #157
2025-04-24 13:29:41 +02:00
Florian
50f93e5f59 Merge pull request #219 from gyptazy/feature/218-add-1-to-1-relations-guest-hypervisor
feature: Add possibility to pin guests to a specific hypervisor node.
2025-04-24 13:01:44 +02:00
Florian Paul Azim Hoberg
33784f60b4 feature: Add possibility to pin guests to a specific hypervisor node.
Fixes: #218
2025-04-24 08:54:58 +02:00
Florian
9a261aa781 Merge pull request #213 from gyptazy/prepare/release-v1.1.2
release: Prepare release v1.1.2
2025-04-19 20:14:12 +02:00
gyptazy
366d5bc264 release: Prepare release v1.1.2 2025-04-19 20:10:49 +02:00
Florian
96ffa086b1 Merge pull request #212 from gyptazy/release/1.1.1
release: Create release 1.1.1
2025-04-19 19:45:33 +02:00
gyptazy
db005c138e release: Create release 1.1.1
Fixes: #211
2025-04-19 19:43:07 +02:00
Florian
1168f545e5 Merge pull request #210 from gyptazy/docs/209-adjust-options-in-readme
docs: * Fix the rendering of the possible values of the ProxLB option…
2025-04-19 06:50:48 +02:00
gyptazy
cc663c0518 docs: * Fix the rendering of the possible values of the ProxLB options in the README file
* Mention the privilege separation part on the token generation chapter

Fixes: #209
2025-04-19 06:49:04 +02:00
Florian
40de31bc3b Merge pull request #208 from gyptazy/techdebt/fix-code-style
tecdebt: Adjust code style.
2025-04-18 17:07:01 +02:00
gyptazy
5884d76ff4 tecdebt: Adjust code style. 2025-04-18 16:52:59 +02:00
Florian
7cc59eb6fc Merge pull request #202 from glitchvern/fix/200-requery-zero-guest-cpu-used2
fix: Requery a guest if that running guest reports 0 cpu usage
2025-04-18 16:38:17 +02:00
gyptazy
24b3b35640 fix: Fix the guest type relationship in the logs when a migration job failed (by @gyptazy) [#204]
feature: Providing the API upstream error message when migration fails in debug mode (by @gyptazy) [#205]

Fixes: #204
Fixes: #205
2025-04-18 16:35:02 +02:00
Florian
f2b8829299 Merge pull request #204 from sid3windr/patch-1
Fix default configuration file path in README.md
2025-04-18 12:41:22 +02:00
Tom Laermans
4b64a041cc Fix default configuration file path in README.md
With 1.1.0, the default configuration file changed from proxlb.conf to proxlb.yaml but the README was not fully updated.
2025-04-18 11:04:51 +02:00
glitchvern
bd1157127a fix: limit to 10 requerys per a guest 2025-04-17 16:13:28 +00:00
glitchvern
be6e4bbfa0 fix: Requery a guest if that running guest reports 0 cpu usage 2025-04-16 18:42:27 +00:00
Florian
25b631099c Merge pull request #199 from gyptazy/docs/193-add-chapter-ignore-vm
docs: Add documentation about ignore guests such like VMs or CTs.
2025-04-15 19:23:27 +02:00
gyptazy
1d698c5688 docs: Add documentation about ignore guests such like VMs or CTs.
Fixes: #193
2025-04-15 19:22:10 +02:00
Florian
40f848ad7f Merge pull request #198 from glitchvern/fix/197-remove-hard-coded-memory-usage-from-lowest-usage-node
fix: Use method/mode in configuration to calculate lowest_usage_node
2025-04-15 19:08:52 +02:00
Florian
fd2725c878 Merge pull request #196 from glitchvern/fix/195-cpu-used-times-cpu-cores
fix: set cpu_used to be cpu usage times number of cpu cores
2025-04-15 18:36:25 +02:00
glitchvern
34b1d72e40 fix: Use method and mode specified in configuration to calculate lowest_usage_node 2025-04-15 16:27:08 +00:00
glitchvern
ca7db26976 fix: set cpu_used to be cpu usage times number of cpu cores 2025-04-14 21:23:05 +00:00
Florian
94552f9c9e Merge pull request #194 from crandler/main
Main
2025-04-14 12:44:50 +02:00
Sven Eulberg
32c67b9c96 fix: typos 2025-04-14 12:36:28 +02:00
Florian
89f337d8c3 Merge pull request #192 from gyptazy/tecdebt/185-improve-logging-code
tecdebt: Improve logging handler creation
2025-04-14 06:55:51 +02:00
Florian Paul Azim Hoberg (@gyptazy)
8a724400b8 tecdebt: Improve logging handler creation
Fixes: #185
2025-04-14 06:52:04 +02:00
Florian
f96f1d0f64 Merge pull request #186 from glitchvern/fix/185-logging-handler-for-no-systemd-integration
fix: logging handler for no systemd integration
2025-04-14 06:46:58 +02:00
Florian
15398712ee Merge pull request #190 from mika/mika/docs
docs: Fix minor typos
2025-04-13 11:19:18 +02:00
Florian
ddb9963062 Merge pull request #191 from gyptazy/feature/184-validate-user-permissions
Feature: Add validation for the minimum required permissions of a user in Proxmox.
2025-04-13 11:16:09 +02:00
Florian Paul Azim Hoberg (@gyptazy)
f18a9f3d4c Feature: Add validation for the minimum required permissions of a user in Proxmox.
Fixes: #184
2025-04-13 11:12:30 +02:00
Michael Prokop
1402ba9732 Minor typo fixes
s/connectoing/connecting/
s/furhter/further/
s/interating/iterating/
s/ist/is/
s/maintence/maintenance/
s/performt/performed/
s/ressources/resources/
s/sucessfully/successfully/
s/the the/the/
s/timout/timeout/
s/wether/whether/
2025-04-13 10:48:23 +02:00
Florian
af51f53221 Merge pull request #188 from glitchvern/fix/187-allow-use-of-minutes-instead-of-hours
fix: allow use of minutes instead of hours
2025-04-13 08:49:17 +02:00
glitchvern
bce2d640ef fix: allow use of minutes instead of hours 2025-04-11 23:09:00 +00:00
glitchvern
1bb1847e45 fix: logging handler for no systemd integration 2025-04-11 21:55:09 +00:00
Florian
e9543db138 Merge pull request #182 from gyptazy/change/180-switch-default-balancing-to-used-instead-assigned
change: Change the default banalcing mode to used instead of assigned.
2025-04-10 09:34:19 +02:00
gyptazy
a8e8229787 change: Change the default banalcing mode to used instead of assigned.
Fixes: #180
2025-04-10 09:33:17 +02:00
Florian
d1c91c6f2a Merge pull request #179 from gyptazy/docs/164-adjust-api-token-usage
docs: Adjust docs regarding API Token and privilege separation.
2025-04-07 16:14:40 +02:00
gyptazy
843691f8b4 docs: Adjust docs regarding API Token and priviledge separation.
Fixes: #164
2025-04-07 15:51:44 +02:00
Florian
c9f14946d1 Merge pull request #178 from gyptazy/fix/174-honor-balancing-activation-value
fix: Honor the value when balancing should not be performed and stop balancing.
2025-04-07 15:41:02 +02:00
gyptazy
77cd7b5388 fix: Honor the value when balancing should not be performed and stop balancing.
Fixes: #174
2025-04-07 15:38:32 +02:00
Florian
55502f9bed Merge pull request #177 from gyptazy/change/176-change-turn-daemon-mode-on-default
change: Change the default behaviour of the daemon mode to active.
2025-04-07 15:28:12 +02:00
gyptazy
f08b823cc4 change: Change the default behaviour of the daemon mode to active.
Fixes: #176
2025-04-07 15:25:10 +02:00
Florian
f831d4044f Merge pull request #175 from gyptazy/feature/168-add-more-flexible-schedule-timers
feature: Add a more flexible way to define schedules directly in minutes or hours
2025-04-07 15:20:22 +02:00
gyptazy
e8d8d160a7 feature: Add a more flexible way to define schedules directly in minutes or hours. [#168]
Sponsored-by: @gyptazy
Fixes: #168
2025-04-07 15:16:55 +02:00
Florian
dbbd4c0ec8 Merge pull request #172 from gyptazy/changelog/171-set-correct-python-path-docker-image
changelog: Add changelog for: Fix Python 3 path for Docker entrypoint
2025-04-02 07:24:01 +02:00
Florian
fc9a0e2858 Merge pull request #171 from crandler/main
fix: path correction for docker entrypoint
2025-04-02 07:23:48 +02:00
gyptazy
17eb43db94 changelog: Add changelog for: Fix Python 3 path for Docker entrypoint
Sponsored-by: @crandler
Fixes: #170
Fixes: #171
2025-04-02 07:20:15 +02:00
Sven Eulberg
06610e9b9d Path correction 2025-04-01 18:38:58 +02:00
Florian
889b88fd6c Merge pull request #167 from gyptazy/prep/1.1.1
release: Prepare development branch for release 1.1.1
2025-04-01 08:03:36 +02:00
gyptazy
c5ca3e13e0 release: Prepare development branch for release 1.1.1 2025-04-01 08:02:40 +02:00
Florian
c1c524f092 Merge pull request #166 from gyptazy/fix/163-ignore-vm-tag
fix: Fix tag evluation for VMs for being ignored for further balancing
2025-04-01 07:01:14 +02:00
gyptazy
7ea7defa1f fix: Fix tag evluation for VMs for being ignored for further balancing
Fixes: #163
Fixes: #165
2025-04-01 06:51:42 +02:00
Florian
6147c0085b Merge pull request #161 from gyptazy/fix/spell-docs
fix: Adjust spelling in the docs
2025-03-31 07:39:40 +02:00
gyptazy
0b70a9c767 fix: Adjust spelling in the docs 2025-03-31 07:38:04 +02:00
Florian
d6d22c4096 Merge pull request #160 from gyptazy/fix/142-mutal-exclusive-on-pass
fix: Fix mutal exclusive authentication based on secrets.
2025-03-31 06:50:26 +02:00
gyptazy
6da54c1255 fix: Fix mutal exclusive authentication based on secrets.
Fixes: #142
2025-03-31 06:46:31 +02:00
Florian
b55b4ea7a0 Merge pull request #153 from gyptazy/docs/installation
release: Prepare release 1.1.0
2025-03-31 05:15:05 +02:00
Florian
51625fe09e Merge pull request #159 from gyptazy/feature/json-output
fix: Add JSON output again
2025-03-25 09:34:10 +01:00
Florian Paul Azim Hoberg (@gyptazy)
f3b9d33c87 fix: Add JSON output again
Fixes: #158
2025-03-25 09:28:33 +01:00
Florian
8e4326f77a Merge pull request #156 from gyptazy/fix/137-fix-systemd-unit
fix: Fix the systemd unit file to start after the pveproxy daemon
2025-03-24 18:25:10 +01:00
gyptazy
3d642a7404 fix: Fix the systemd unit file to start after the pveproxy daemon
Fixes: #137
2025-03-24 18:15:11 +01:00
gyptazy
552364471d release: Create release 1.1.0
- Create release 1.1.0 content
 - Add documentation for release 1.1.0
 - Adjust changelog

Fixes: #114
Fixes: #154
Sponsored-by: credativ GmbH (https://credativ.de)
2025-03-20 20:19:34 +01:00
Florian
cf15866270 Merge pull request #151 from gyptazy/packaging/container-image
feature: Add Dockerfile to create container image
2025-03-19 14:53:04 +01:00
Florian Paul Azim Hoberg (@gyptazy)
7d4def14b1 feature: Add Dockerfile to create container image
* Also switch from Debian image to Alpine image
2025-03-19 14:48:44 +01:00
Florian
20ad9389d4 Merge pull request #150 from gyptazy/docs/adjust_docs
docs: Add docs for configuration and faq.
2025-03-18 15:09:04 +01:00
Florian Paul Azim Hoberg (@gyptazy)
d73073a187 docs: Add docs for configuration and faq. 2025-03-18 15:05:29 +01:00
Florian
b307d556e5 Merge pull request #149 from gyptazy/packaging/debian
packaging: Add Debian packaging
2025-03-18 09:30:15 +01:00
gyptazy
17c4dc445e packaging: Add Debian packaging
Fixes: #148
2025-03-18 08:40:28 +01:00
89 changed files with 2070 additions and 218 deletions

View File

@@ -1,6 +1,5 @@
fixed:
- Refactored code base for ProxLB [#114]
- Renamed package from `proxlb` to `python3-proxlb` to align with Debian packaging guidelines [#114]
- Switched to `pycodestyle` for linting [#114]
- Package building will be done within GitHub actions pipeline [#114]
- ProxLB now only returns a warning when no guests for further balancing are not present (instead of quitting) [132#]
@@ -9,4 +8,4 @@ fixed:
- Stop balancing when movement would get worste (new force param to enfoce for affinity rules) [#128]
- Added requested documentation regarding Proxmox HA groups [#127]
- Rewrite of the whole affinity/anti-affinity rules evaluation and placement [#123]
- Fixed the `ignore` parameter for nodes where the node and guests on the node will be untouched [#102]
- Fixed the `ignore` parameter for nodes where the node and guests on the node will be untouched [#102]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix the systemd unit file to start ProxLB after pveproxy (by @robertdahlem). [#137]

View File

@@ -1 +1 @@
date: TBD
date: 2025-04-01

View File

@@ -0,0 +1,2 @@
fixed:
- Fix tag evluation for VMs for being ignored for further balancing [#163]

View File

@@ -0,0 +1,2 @@
fixed:
- Improve logging verbosity of messages that had a wrong servity [#165]

View File

@@ -0,0 +1,2 @@
feature:
- Add a more flexible way to define schedules in minutes or hours (by @gyptazy) [#168]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix Python path for Docker entrypoint (by @crandler) [#170]

View File

@@ -0,0 +1,2 @@
fixed:
- Honor the value when balancing should not be performed and stop balancing [#174]

View File

@@ -0,0 +1,2 @@
changed:
- Change the default behaviour of the daemon mode to active [#176]

View File

@@ -0,0 +1,2 @@
changed:
- Change the default banalcing mode to used instead of assigned [#180]

View File

@@ -0,0 +1,2 @@
feature:
- Add validation for the minimum required permissions of a user in Proxmox [#184]

View File

@@ -0,0 +1,2 @@
fix:
- add handler to log messages with severity less than info to the screen when there is no systemd integration, for instance, inside a docker container (by @glitchvern) [#185]

View File

@@ -0,0 +1,2 @@
fixed:
- allow the use of minutes instead of hours and only accept hours or minutes in the format (by @glitchvern) [#187]

View File

@@ -0,0 +1,2 @@
fixed:
- Set cpu_used to the cpu usage, which is a percent, times the total number of cores to get a number where guest cpu_used can be added to nodes cpu_used and be meaningful (by @glitchvern) [#195]

View File

@@ -0,0 +1,2 @@
fixed:
- Remove hard coded memory usage from lowest usage node and use method and mode specified in configuration instead (by @glitchvern) [#197]

View File

@@ -0,0 +1,2 @@
fixed:
- Requery a guest if that running guest reports 0 cpu usage (by @glitchvern) [#200]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix the guest type relationship in the logs when a migration job failed (by @gyptazy) [#204]

View File

@@ -0,0 +1,2 @@
added:
- Providing the API upstream error message when migration fails in debug mode (by @gyptazy) [#205]

View File

@@ -0,0 +1 @@
date: 2025-04-20

View File

@@ -0,0 +1,2 @@
fixed:
- Fix systemd unit file to run after network on non PVE nodes (by @robertdahlem) [#137]

View File

@@ -0,0 +1,2 @@
added:
- Add a configurable retry mechanism when connecting to the Proxmox API (by @gyptazy) [#157]

View File

@@ -0,0 +1,2 @@
added:
- Add 1-to-1 relationships between guest and hypervisor node to ping a guest on a node (by @gyptazy) [#218]

View File

@@ -0,0 +1,2 @@
fixed:
- Force type cast cpu count of guests to int for some corner cases where a str got returned (by @gyptazy). [#222]

View File

@@ -0,0 +1 @@
date: 2025-05-13

View File

@@ -0,0 +1,2 @@
added:
- Add relaod (SIGHUP) function to ProxLB to reload the configuration (by @gyptazy). [#189]

View File

@@ -0,0 +1,2 @@
fixed:
- Align maintenance mode with Proxmox HA maintenance mode (by @gyptazy). [#232]

View File

@@ -0,0 +1,2 @@
added:
- Add optional wait time parameter to delay execution until the service takes action (by @gyptazy). #239

View File

@@ -0,0 +1,2 @@
added:
- Make the amount of parallel migrations configurable (by @gyptazy). [#241]

View File

@@ -0,0 +1,2 @@
changed:
- Use the average CPU consumption of a guest within the last 60 minutes instead of the current CPU usage (by @philslab-ninja & @gyptazy). [#94]

View File

@@ -0,0 +1 @@
date: 2025-06-19

View File

@@ -0,0 +1,2 @@
added:
- Allow pinning of guests to a group of nodes (@gyptazy). [#245]

View File

@@ -0,0 +1,2 @@
fixed:
- Fixed an issue where balancing was performed in combination of deactivated balancing and dry-run mode (@gyptazy). [#248]

View File

@@ -0,0 +1,2 @@
fixed:
- Modified log levels to make output lighter at INFO level (@pmarasse) [#255]

View File

@@ -0,0 +1 @@
date: 2025-06-27

View File

@@ -0,0 +1,2 @@
added:
- Allow custom API ports instead of fixed tcp/8006 (@gyptazy). [#260]

View File

@@ -0,0 +1 @@
date: 2025-07-14

View File

@@ -0,0 +1,2 @@
fixed:
- Fix balancing evaluation of guest types (e.g., VM or CT) (@gyptazy). [#268]

View File

@@ -0,0 +1,2 @@
added:
- Add validation for provided API user token id to avoid confusions (@gyptazy). [#291]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix stacktrace output when validating permissions on non existing users in Proxmox (@gyptazy). [#291]

View File

@@ -0,0 +1,3 @@
fixed:
- Fix Overprovisioning first node if anti_affinity_group has only one member (@MiBUl-eu). [#295]

View File

@@ -0,0 +1,3 @@
fixed:
- Validate for node presence when pinning guests to avoid crashing (@gyptazy). [#296]

View File

@@ -0,0 +1 @@
date: 2025-09-04

View File

@@ -0,0 +1,2 @@
added:
- Add graceful shutdown for SIGINT (e.g., CTRL + C abort). (@gyptazy). [#304]

View File

@@ -0,0 +1,2 @@
added:
- Add conntrack state aware migrations of VMs (@gyptazy). [#305]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix crash when validating absent migration job ids. (@gyptazy). [#308]

View File

@@ -0,0 +1,2 @@
fixed:
- Fix guest object names are not being evaluated in debug log. (@gyptazy). [#310]

View File

@@ -0,0 +1 @@
date: 2025-09-19

View File

@@ -28,7 +28,7 @@ jobs:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: 'development'
ref: ${{ github.ref }}
- name: Set up Docker with Debian image
run: |
@@ -39,9 +39,13 @@ jobs:
docker run --rm -v $(pwd):/workspace -w /workspace debian:latest bash -c "
# Install dependencies
apt-get update && \
apt-get install -y python3 python3-setuptools debhelper dh-python python3-pip python3-stdeb python3-proxmoxer python3-requests python3-urllib3 && \
# Build package
python3 setup.py --command-packages=stdeb.command bdist_deb && \
apt-get install -y python3 python3-setuptools debhelper dh-python python3-pip python3-stdeb python3-proxmoxer python3-requests python3-urllib3 devscripts python3-all && \
# Build package using stdeb / setuptools
# python3 setup.py --command-packages=stdeb.command bdist_deb && \
# Build native package
dpkg-buildpackage -us -uc && \
mkdir package && \
mv ../*.deb package/ && \
echo 'OK: Debian package successfully created.'
"
@@ -49,7 +53,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: debian-package
path: deb_dist/*.deb
path: package/*.deb
integration-test-debian:
needs: build-package-debian
@@ -59,15 +63,16 @@ jobs:
uses: actions/download-artifact@v4
with:
name: debian-package
path: deb_dist/
path: package/
- name: Set up Docker with Debian image
run: docker pull debian:latest
- name: Install and test Debian package in Docker container
run: |
docker run --rm -v $(pwd)/deb_dist:/deb_dist -w /deb_dist debian:latest bash -c "
docker run --rm -v $(pwd)/package:/package -w /package debian:latest bash -c "
apt-get update && \
apt-get install -y ./python3-proxlb*.deb && \
apt-get install -y systemd && \
apt-get install -y ./proxlb*.deb && \
python3 -c 'import proxlb; print(\"OK: Debian package successfully installed.\")'
"

View File

@@ -0,0 +1,26 @@
name: "Build Container Image: AMD64"
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build amd64 image and save as tar
run: |
docker buildx build \
--platform linux/amd64 \
--load \
-t proxlb-image:amd64 \
.
docker save proxlb-image:amd64 -o proxlb_image_amd64.tar
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: proxlb-image-amd64
path: proxlb_image_amd64.tar

View File

@@ -0,0 +1,26 @@
name: "Build Container Image: ARM64"
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build arm64 image and save as tar
run: |
docker buildx build \
--platform linux/arm64 \
--load \
-t proxlb-image:arm64 \
.
docker save proxlb-image:arm64 -o proxlb_image_arm64.tar
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: proxlb-image-arm64
path: proxlb_image_arm64.tar

View File

@@ -0,0 +1,23 @@
name: "Build Container Image: Multiarch"
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build multi-arch image and save as tar
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--output type=tar,dest=proxlb_image_multiarch.tar \
.
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: proxlb-image-multiarch
path: proxlb_image_multiarch.tar

244
CHANGELOG.md Normal file
View File

@@ -0,0 +1,244 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.7] - 2025-09-19
### Added
- Add conntrack state aware migrations of VMs (@gyptazy). [#305]
- Add graceful shutdown for SIGINT (e.g., CTRL + C abort). (@gyptazy). [#304]
### Fixed
- Fix crash when validating absent migration job ids. (@gyptazy). [#308]
- Fix guest object names are not being evaluated in debug log. (@gyptazy). [#310]
## [1.1.6.1] - 2025-09-04
### Fixed
- Validate for node presence when pinning VMs to avoid crashing (@gyptazy). [#296]
## [1.1.6] - 2025-09-04
### Added
- Add validation for provided API user token id to avoid confusions (@gyptazy). [#291]
### Fixed
- Fix stacktrace output when validating permissions on non existing users in Proxmox (@gyptazy). [#291]
- Fix Overprovisioning first node if anti_affinity_group has only one member (@MiBUl-eu). [#295]
- Validate for node presence when pinning guests to avoid crashing (@gyptazy). [#296]
- Fix balancing evaluation of guest types (e.g., VM or CT) (@gyptazy). [#268]
## [1.1.5] - 2025-07-14
### Added
- Allow custom API ports instead of fixed tcp/8006 (@gyptazy). [#260]
## [1.1.4] - 2025-06-27
### Added
- Allow pinning of guests to a group of nodes (@gyptazy). [#245]
### Fixed
- Modified log levels to make output lighter at INFO level (@pmarasse) [#255]
- Fixed an issue where balancing was performed in combination of deactivated balancing and dry-run mode (@gyptazy). [#248]
## [1.1.3] - 2025-06-19
### Added
- Add relaod (SIGHUP) function to ProxLB to reload the configuration (by @gyptazy). [#189]
- Add optional wait time parameter to delay execution until the service takes action (by @gyptazy). [#239]
- Make the amount of parallel migrations configurable (by @gyptazy). [#241]
### Changed
- Use the average CPU consumption of a guest within the last 60 minutes instead of the current CPU usage (by @philslab-ninja & @gyptazy). [#94]
### Fixed
- Align maintenance mode with Proxmox HA maintenance mode (by @gyptazy). [#232]
## [1.1.2] - 2025-05-13
### Added
- Add a configurable retry mechanism when connecting to the Proxmox API (by @gyptazy) [#157]
- Add 1-to-1 relationships between guest and hypervisor node to ping a guest on a node (by @gyptazy) [#218]
### Fixed
- Force type cast cpu count of guests to int for some corner cases where a str got returned (by @gyptazy). [#222]
- Fix systemd unit file to run after network on non PVE nodes (by @robertdahlem) [#137]
## [1.1.1] - 2025-04-20
### Added
- Providing the API upstream error message when migration fails in debug mode (by @gyptazy) [#205]
### Changed
- Change the default behaviour of the daemon mode to active [#176]
- Change the default banalcing mode to used instead of assigned [#180]
### Fixed
- Set cpu_used to the cpu usage, which is a percent, times the total number of cores to get a number where guest cpu_used can be added to nodes cpu_used and be meaningful (by @glitchvern) [#195]
- Fix tag evluation for VMs for being ignored for further balancing [#163]
- Honor the value when balancing should not be performed and stop balancing [#174]
- allow the use of minutes instead of hours and only accept hours or minutes in the format (by @glitchvern) [#187]
- Remove hard coded memory usage from lowest usage node and use method and mode specified in configuration instead (by @glitchvern) [#197]
- Fix the guest type relationship in the logs when a migration job failed (by @gyptazy) [#204]
- Requery a guest if that running guest reports 0 cpu usage (by @glitchvern) [#200]
- Fix Python path for Docker entrypoint (by @crandler) [#170]
- Improve logging verbosity of messages that had a wrong servity [#165]
## [1.1.0] - 2025-04-01
### Fixed
- Refactored code base for ProxLB [#114]
- Switched to `pycodestyle` for linting [#114]
- Package building will be done within GitHub actions pipeline [#114]
- ProxLB now only returns a warning when no guests for further balancing are not present (instead of quitting) [132#]
- All nodes (according to the free resources) will be used now [#130]
- Fixed logging outputs where highest/lowest were mixed-up [#129]
- Stop balancing when movement would get worste (new force param to enfoce for affinity rules) [#128]
- Added requested documentation regarding Proxmox HA groups [#127]
- Rewrite of the whole affinity/anti-affinity rules evaluation and placement [#123]
- Fixed the `ignore` parameter for nodes where the node and guests on the node will be untouched [#102]
## [1.0.6] - 2024-12-24
### Fixed
- Fix maintenance mode when using cli arg and config mode by using the merged list (by @CartCaved). [#119]
- Fix that a scheduler time definition of 1 (int) gets wrongly interpreted as a bool (by @gyptazy). [#115]
## [1.0.5] - 2024-10-30
### Changed
- Change docs to make bool usage in configs more clear (by @gyptazy). [#104]
### Fixed
- Fix node (and its objects) evaluation when not reachable, e.g., maintenance (by @gyptazy). [#107]
- Fix migration from local disks (by @greenlogles). [#113]
- Fix evaluation of maintenance mode where comparing list & string resulted in a crash (by @glitchvern). [#106]
- Fix allowed values (add DEBUG, WARNING) for log verbosity (by @gyptazy). [#98]
## [1.0.4] - 2024-10-11
### Added
- Add maintenance mode to evacuate a node and move workloads for other nodes in the cluster. [#58]
- Add feature to make API timeout configureable. [#91]
- Add version output cli arg. [#89]
### Changed
- Run storage balancing only on supported shared storages. [#79]
- Run storage balancing only when needed to save time. [#79]
### Fixed
- Fix CPU balancing where calculations are done in float instead of int. (by @glitchvern) [#75]
- Fix documentation for the underlying infrastructure. [#81]
## [1.0.3] - 2024-09-12
### Added
- Add cli arg `-b` to return the next best node for next VM/CT placement. [#8]
- Add a convert function to cast all bool alike options from configparser to bools. [#53]
- Add a config parser options for future features. [#53]
- Add a config versio schema that must be supported by ProxLB. [#53]
- Add feature to allow the API hosts being provided as a comma separated list. [#60]
- Add doc how to add dedicated user for authentication. (by @Dulux-Oz)
- Add storage balancing function. [#51]
### Changed
- Provide a more reasonable output when HA services are not active in a Proxmox cluster. [#68]
- Improve the underlying code base for future implementations. [#53]
### Fixed
- Fix anti-affinity rules not evaluating a new and different node. [#67]
- Fixed `master_only` function by inverting the condition.
- Fix documentation for the master_only parameter placed in the wrong config section. [#74]
- Fix bug in the `proxlb.conf` in the vm_balancing section.
- Fix handling of unset `ignore_nodes` and `ignore_vms` resulted in an attribute error. [#71]
- Improved the overall validation and error handling. [#64]
## [1.0.2] - 2024-08-13
### Added
- Add option to run ProxLB only on the Proxmox's master node in the cluster (reg. HA feature). [#40]
- Add option to run migrations in parallel or sequentially. [#41]
### Changed
- Fix daemon timer to use hours instead of minutes. [#45]
### Fixed
- Fix CMake packaging for Debian package to avoid overwriting the config file. [#49]
## [1.0.0] - 2024-08-01
### Added
- Add feature to prevent VMs from being relocated by defining the 'plb_ignore_vm' tag. [#7]
- Add feature to prevent VMs from being relocated by defining a wildcard pattern. [#7]
- Add Docker/Podman support. [#10 by @daanbosch]
- Add option to rebalance by assigned VM resources to avoid overprovisioning. [#16]
- Add feature to make log verbosity configurable [#17].
- Add dry-run support to see what kind of rebalancing would be done. [#6]
- Add LXC/Container integration. [#27]
- Add exclude grouping feature to rebalance VMs from being located together to new nodes. [#4]
- Add include grouping feature to rebalance VMs bundled to new nodes. [#3]
- Add option_mode to rebalance by node's free resources in percent (instead of bytes). [#29]
### Changed
- Adjusted general logging and log more details.
## [0.9.9] - 2024-07-06
### Added
- Initial public development release of ProxLB.
## [0.9.0] - 2024-02-01
### Added
- Development release of ProxLB.

28
Dockerfile Normal file
View File

@@ -0,0 +1,28 @@
# Use the latest Alpine image
FROM alpine:latest
# Labels
LABEL maintainer="gyptazy@gyptazy.com"
LABEL org.label-schema.name="ProxLB"
LABEL org.label-schema.description="ProxLB - An advanced load balancer for Proxmox clusters."
LABEL org.label-schema.vendor="gyptazy"
LABEL org.label-schema.url="https://proxlb.de"
LABEL org.label-schema.vcs-url="https://github.com/gyptazy/ProxLB"
# Install Python3
RUN apk add --no-cache python3 py3-pip
# Create a directory for the app
WORKDIR /app
# Copy the python program from the current directory to /app
COPY proxlb /app/proxlb
# Copy requirements to the container
COPY requirements.txt /app/requirements.txt
# Install dependencies in the virtual environment
RUN pip install --break-system-packages -r /app/requirements.txt
# Set the entry point to use the virtual environment's python
ENTRYPOINT ["/usr/bin/python3", "/app/proxlb/main.py"]

293
README.md
View File

@@ -1,13 +1,9 @@
# ProxLB - (Re)Balance VM Workloads in Proxmox Clusters
<img align="left" src="https://cdn.gyptazy.com/images/Prox-LB-logo.jpg"/>
<img align="left" src="https://cdn.gyptazy.com/img/ProxLB.jpg"/>
<br>
<p float="center"><img src="https://img.shields.io/github/license/gyptazy/ProxLB"/><img src="https://img.shields.io/github/contributors/gyptazy/ProxLB"/><img src="https://img.shields.io/github/last-commit/gyptazy/ProxLB/main"/><img src="https://img.shields.io/github/issues-raw/gyptazy/ProxLB"/><img src="https://img.shields.io/github/issues-pr/gyptazy/ProxLB"/></p>
# :warning: Important: ProxLB 1.1.x is coming
This repository is currently under heavy work and changes. During that time it might come to issues, non working pipelines or wrong documentation. Please select a stable release tag for a suitable version during this time!
## Table of Contents
1. [Introduction](#introduction)
2. [Features](#features)
@@ -15,26 +11,24 @@ This repository is currently under heavy work and changes. During that time it m
4. [Installation](#installation)
1. [Requirements / Dependencies](#requirements--dependencies)
2. [Debian Package](#debian-package)
3. [RedHat Package](#redhat-package)
4. [Container / Docker](#container--docker)
5. [Source](#source)
5. [Upgrading](#upgrading)
1. [Upgrading from < 1.1.0](#upgrading-from--110)
2. [Upgrading from >= 1.1.0](#upgrading-from--110)
6. [Usage / Configuration](#usage--configuration)
5. [Usage / Configuration](#usage--configuration)
1. [GUI Integration](#gui-integration)
2. [Proxmox HA Integration](#proxmox-ha-integration)
3. [Options](#options)
7. [Affinity & Anti-Affinity Rules](#affinity--anti-affinity-rules)
6. [Affinity & Anti-Affinity Rules](#affinity--anti-affinity-rules)
1. [Affinity Rules](#affinity-rules)
2. [Anti-Affinity Rules](#anti-affinity-rules)
8. [Maintenance](#maintenance)
9. [Misc](#misc)
3. [Ignore VMs](#ignore-vms)
4. [Pin VMs to Hypervisor Nodes](#pin-vms-to-hypervisor-nodes)
7. [Maintenance](#maintenance)
8. [Misc](#misc)
1. [Bugs](#bugs)
2. [Contributing](#contributing)
3. [Documentation](#documentation)
4. [Support](#support)
10. [Author(s)](#authors)
9. [Author(s)](#authors)
## Introduction
@@ -83,6 +77,10 @@ Before starting any migrations, ProxLB validates that rebalancing actions are ne
## Installation
### Requirements / Dependencies
* Proxmox
* Proxmox 7.x
* Proxmox 8.x
* Proxmox 9.x
* Python3.x
* proxmoxer
* requests
@@ -94,23 +92,134 @@ The dependencies can simply be installed with `pip` by running the following com
pip install -r requirements.txt
```
Distribution packages, such like the provided `.deb` package will automatically resolve and install all required dependencies by using already packaged version from the distribution's repository.
*Note: Distribution packages, such like the provided `.deb` package will automatically resolve and install all required dependencies by using already packaged version from the distribution's repository. By using the Docker (container) image or Debian packages, you do not need to take any care of the requirements listed here.*
### Debian Package
ProxLB is a powerful and flexible load balancer designed to work across various architectures, including `amd64`, `arm64`, `rv64` and many other ones that support Python. It runs independently of the underlying hardware, making it a versatile choice for different environments. This chapter covers the step-by-step process to install ProxLB on Debian-based systems, including Debian clones like Ubuntu.
### RedHat Package
#### Quick-Start
You can simply use this snippet to install the repository and to install ProxLB on your system.
### Container / Docker
```bash
echo "deb https://repo.gyptazy.com/stable /" > /etc/apt/sources.list.d/proxlb.list
wget -O /etc/apt/trusted.gpg.d/proxlb.asc https://repo.gyptazy.com/repository.gpg
apt-get update && apt-get -y install proxlb
cp /etc/proxlb/proxlb_example.yaml /etc/proxlb/proxlb.yaml
# Adjust the config to your needs
vi /etc/proxlb/proxlb.yaml
systemctl start proxlb
```
Afterwards, ProxLB is running in the background and balances your cluster by your defined balancing method (default: memory).
#### Details
ProxLB provides two different repositories:
* https://repo.gyptazy.com/stable (only stable release)
* https://repo.gyptazy.com/testing (bleeding edge - not recommended)
The repository is signed and the GPG key can be found at:
* https://repo.gyptazy.com/repository.gpg
You can also simply import it by running:
```
# KeyID: 17169F23F9F71A14AD49EDADDB51D3EB01824F4C
# UID: gyptazy Solutions Repository <contact@gyptazy.com>
# SHA256: 52c267e6f4ec799d40cdbdb29fa518533ac7942dab557fa4c217a76f90d6b0f3 repository.gpg
wget -O /etc/apt/trusted.gpg.d/proxlb.asc https://repo.gyptazy.com/repository.gpg
```
*Note: The defined repositories `repo.gyptazy.com` and `repo.proxlb.de` are the same!*
#### Debian Packages (.deb files)
If you do not want to use the repository you can also find the debian packages as a .deb file on gyptazy's CDN at:
* https://cdn.gyptazy.com/debian/
Afterwards, you can simply install the package by running:
```bash
dpkg -i proxlb_*.deb
cp /etc/proxlb/proxlb_example.yaml /etc/proxlb/proxlb.yaml
# Adjust the config to your needs
vi /etc/proxlb/proxlb.yaml
systemctl start proxlb
```
### Container Images / Docker
Using the ProxLB container images is straight forward and only requires you to mount the config file.
```bash
# Pull the image
docker pull cr.gyptazy.com/proxlb/proxlb:latest
# Download the config
wget -O proxlb.yaml https://raw.githubusercontent.com/gyptazy/ProxLB/refs/heads/main/config/proxlb_example.yaml
# Adjust the config to your needs
vi proxlb.yaml
# Start the ProxLB container image with the ProxLB config
docker run -it --rm -v $(pwd)/proxlb.yaml:/etc/proxlb/proxlb.yaml proxlb
```
*Note: ProxLB container images are officially only available at cr.proxlb.de and cr.gyptazy.com.*
#### Overview of Images
| Version | Image |
|------|:------:|
| latest | cr.gyptazy.com/proxlb/proxlb:latest |
| v1.1.7 | cr.gyptazy.com/proxlb/proxlb:v1.1.7 |
| v1.1.6.1 | cr.gyptazy.com/proxlb/proxlb:v1.1.6.1 |
| v1.1.6 | cr.gyptazy.com/proxlb/proxlb:v1.1.6 |
| v1.1.5 | cr.gyptazy.com/proxlb/proxlb:v1.1.5 |
| v1.1.4 | cr.gyptazy.com/proxlb/proxlb:v1.1.4 |
| v1.1.3 | cr.gyptazy.com/proxlb/proxlb:v1.1.3 |
| v1.1.2 | cr.gyptazy.com/proxlb/proxlb:v1.1.2 |
| v1.1.1 | cr.gyptazy.com/proxlb/proxlb:v1.1.1 |
| v1.1.0 | cr.gyptazy.com/proxlb/proxlb:v1.1.0 |
| v1.0.6 | cr.gyptazy.com/proxlb/proxlb:v1.0.6 |
| v1.0.5 | cr.gyptazy.com/proxlb/proxlb:v1.0.5 |
| v1.0.4 | cr.gyptazy.com/proxlb/proxlb:v1.0.4 |
| v1.0.3 | cr.gyptazy.com/proxlb/proxlb:v1.0.3 |
| v1.0.2 | cr.gyptazy.com/proxlb/proxlb:v1.0.2 |
| v1.0.0 | cr.gyptazy.com/proxlb/proxlb:v1.0.0 |
| v0.9.9 | cr.gyptazy.com/proxlb/proxlb:v0.9.9 |
### Source
ProxLB can also easily be used from the provided sources - for traditional systems but also as a Docker/Podman container image.
## Upgrading
#### Traditional System
Setting up and running ProxLB from the sources is simple and requires just a few commands. Ensure Python 3 and the Python dependencies are installed on your system, then run ProxLB using the following command:
```bash
git clone https://github.com/gyptazy/ProxLB.git
cd ProxLB
```
### Upgrading from < 1.1.0
Upgrading ProxLB is not supported due to a fundamental redesign introduced in version 1.1.x. With this update, ProxLB transitioned from a monolithic application to a pure Python-style project, embracing a more modular and flexible architecture. This shift aimed to improve maintainability and extensibility while keeping up with modern development practices. Additionally, ProxLB moved away from traditional ini-style configuration files and adopted YAML for configuration management. This change simplifies configuration handling, reduces the need for extensive validation, and ensures better type casting, ultimately providing a more streamlined and user-friendly experience.
Afterwards simply adjust the config file to your needs:
```bash
vi config/proxlb.yaml
```
### Upgrading from >= 1.1.0
Uprading within the current stable versions, starting from 1.1.0, will be possible in all supported ways.
Start ProxLB by Python3 on the system:
```bash
python3 proxlb/main.py -c config/proxlb.yaml
```
#### Container Image
Creating a container image of ProxLB is straightforward using the provided Dockerfile. The Dockerfile simplifies the process by automating the setup and configuration required to get ProxLB running in an Alpine container. Simply follow the steps in the Dockerfile to build the image, ensuring all dependencies and configurations are correctly applied. For those looking for an even quicker setup, a ready-to-use ProxLB container image is also available, eliminating the need for manual building and allowing for immediate deployment.
```bash
git clone https://github.com/gyptazy/ProxLB.git
cd ProxLB
docker build -t proxlb .
```
Afterwards simply adjust the config file to your needs:
```bash
vi config/proxlb.yaml
```
Finally, start the created container.
```bash
docker run -it --rm -v $(pwd)/proxlb.yaml:/etc/proxlb/proxlb.yaml proxlb
```
## Usage / Configuration
Running ProxLB is straightforward and versatile, as it only requires `Python3` and the `proxmoxer` library. This means ProxLB can be executed directly on a Proxmox node or on dedicated systems such as Debian, RedHat, or even FreeBSD, provided that the Proxmox API is accessible from the client running ProxLB. ProxLB can also run inside a Container - Docker or LXC - and is simply up to you.
@@ -136,46 +245,61 @@ See also: [#65: Host groups: Honour HA groups](https://github.com/gyptazy/ProxLB
### Options
The following options can be set in the configuration file `proxlb.yaml`:
| Section | Option | Example | Type | Description |
|------|:------:|:------:|:------:|:------:|
| `proxmox_api` | | | | |
| | hosts | ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe'] | `List` | List of Proxmox nodes. Can be IPv4, IPv6 or mixed. |
| | user | root@pam | `Str` | Username for the API. |
| | pass | FooBar | `Str` | Password for the API. (Recommended: Use API token authorization!) |
| | token_id | proxlb | `Str` | Token ID of the user for the API. |
| | token_secret | 430e308f-1337-1337-beef-1337beefcafe | `Str` | Secret of the token ID for the API. |
| | ssl_verification | True | `Bool` | Validate SSL certificates (1) or ignore (0). (default: 1, type: bool) |
| | timeout | 10 | `Int` | Timeout for the Proxmox API in sec. (default: 10) |
| `proxmox_cluster` | | | | |
| | maintenance_nodes | ['virt66.example.com'] | `List` | A list of Proxmox nodes that are defined to be in a maintenance. (default: []) |
| | ignore_nodes | [] | `List` | A list of Proxmox nodes that are defined to be ignored. (default: []) |
| | overprovisioning | False | `Bool` | Avoids balancing when nodes would become overprovisioned. |
| `balancing` | | | | |
| | enable | True | `Bool` | Enables the guest balancing. (default: True)|
| | enforce_affinity | True | `Bool` | Enforcing affinity/anti-affinity rules but balancing might become worse. (default: False) |
| | parallel | False | `Bool` | If guests should be moved in parallel or sequentially. (default: False)|
| | live | True | `Bool` | If guests should be moved live or shutdown. (default: True)|
| | with_local_disks | True | `Bool` | If balancing of guests should include local disks (default: True)|
| | balance_types | ['vm', 'ct'] | `List` | Defined the types of guests that should be honored. (default: ['vm', 'ct']) |
| | max_job_validation | 1800 | `Int` | How long a job validation may take in seconds. (default: 1800) |
| | balanciness | 10 | `Int` | The maximum delta of resource usage between node with highest and lowest usage. (default: 10) |
| | method | memory | `Str` | The balancing method that should be used. (default: memory | choices: memory, cpu, disk)|
| | mode | used | `Str` | The balancing mode that should be used. (default: used | choices: used, assigned)|
| `service` | | | | |
| | daemon | False | `Bool` | If daemon mode should be activated (default: False)|
| | schedule | 12 | `Int` | How often rebalancing should occur in hours in daemon mode (default: 12)|
| | log_level | INFO | `Str` | Defines the default log level that should be logged. (default: INFO) |
| Section | Option | Sub Option | Example | Type | Description |
|---------|:------:|:----------:|:-------:|:----:|:-----------:|
| `proxmox_api` | | | | | |
| | hosts | | ['virt01.example.com', '10.10.10.10', 'fe01:bad:code::cafe', 'virt01.example.com:443', '[fc00::1]', '[fc00::1]:443', 'fc00::1:8006'] | `List` | List of Proxmox nodes. Can be IPv4, IPv6 or mixed. You can specify custom ports. In case of IPv6 without brackets the port is considered after the last colon |
| | user | | root@pam | `Str` | Username for the API. |
| | pass | | FooBar | `Str` | Password for the API. (Recommended: Use API token authorization!) |
| | token_id | | proxlb | `Str` | Token ID of the user for the API. |
| | token_secret | | 430e308f-1337-1337-beef-1337beefcafe | `Str` | Secret of the token ID for the API. |
| | ssl_verification | | True | `Bool` | Validate SSL certificates (1) or ignore (0). [values: `1` (default), `0`] |
| | timeout | | 10 | `Int` | Timeout for the Proxmox API in sec. |
| | retries | | 1 | `Int` | How often a connection attempt to the defined API host should be performed. |
| | wait_time | | 1 | `Int` | How many seconds should be waited before performing another connection attempt to the API host. |
| `proxmox_cluster` | | | | | |
| | maintenance_nodes | | ['virt66.example.com'] | `List` | A list of Proxmox nodes that are defined to be in a maintenance. (must be the same node names as used within the cluster) |
| | ignore_nodes | | [] | `List` | A list of Proxmox nodes that are defined to be ignored. |
| | overprovisioning | | False | `Bool` | Avoids balancing when nodes would become overprovisioned. |
| `balancing` | | | | | |
| | enable | | True | `Bool` | Enables the guest balancing.|
| | enforce_affinity | | True | `Bool` | Enforcing affinity/anti-affinity rules but balancing might become worse. |
| | parallel | | False | `Bool` | If guests should be moved in parallel or sequentially.|
| | parallel_jobs | | 5 | `Int` | The amount if parallel jobs when migrating guests. (default: `5`)|
| | live | | True | `Bool` | If guests should be moved live or shutdown.|
| | with_local_disks | | True | `Bool` | If balancing of guests should include local disks.|
| | with_conntrack_state | | True | `Bool` | If balancing of guests should including the conntrack state.|
| | balance_types | | ['vm', 'ct'] | `List` | Defined the types of guests that should be honored. [values: `vm`, `ct`]|
| | max_job_validation | | 1800 | `Int` | How long a job validation may take in seconds. (default: 1800) |
| | balanciness | | 10 | `Int` | The maximum delta of resource usage between node with highest and lowest usage. |
| | method | | memory | `Str` | The balancing method that should be used. [values: `memory` (default), `cpu`, `disk`]|
| | mode | | used | `Str` | The balancing mode that should be used. [values: `used` (default), `assigned`] |
| `service` | | | | | |
| | daemon | | True | `Bool` | If daemon mode should be activated. |
| | `schedule` | | | `Dict` | Schedule config block for rebalancing. |
| | | interval | 12 | `Int` | How often rebalancing should occur in daemon mode.|
| | | format | hours | `Str` | Sets the time format. [values: `hours` (default), `minutes`]|
| | `delay` | | | `Dict` | Schedule config block for an optional delay until the service starts. |
| | | enable | False | `Bool` | If a delay time should be validated.|
| | | time | 1 | `Int` | Delay time until the service starts after the initial execution.|
| | | format | hours | `Str` | Sets the time format. [values: `hours` (default), `minutes`]|
| | log_level | | INFO | `Str` | Defines the default log level that should be logged. [values: `INFO` (default), `WARNING`, `CRITICAL`, `DEBUG`] |
An example of the configuration file looks like:
```
proxmox_api:
hosts: ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe']
hosts: ['virt01.example.com', '10.10.10.10', 'fe01:bad:code::cafe']
user: root@pam
#pass: crazyPassw0rd!
token_id: proxlb
token_secret: 430e308f-1337-1337-beef-1337beefcafe
ssl_verification: False
pass: crazyPassw0rd!
# API Token method
# token_id: proxlb
# token_secret: 430e308f-1337-1337-beef-1337beefcafe
ssl_verification: True
timeout: 10
# API Connection retries
# retries: 1
# wait_time: 1
proxmox_cluster:
maintenance_nodes: ['virt66.example.com']
@@ -188,16 +312,23 @@ balancing:
parallel: False
live: True
with_local_disks: True
with_conntrack_state: True
balance_types: ['vm', 'ct']
max_job_validation: 1800
balanciness: 5
method: memory
mode: assigned
mode: used
service:
daemon: False
schedule: 12
log_level: DEBUG
daemon: True
schedule:
interval: 12
format: hours
delay:
enable: False
time: 1
format: hours
log_level: INFO
```
### Parameters
@@ -205,7 +336,7 @@ The following options and parameters are currently supported:
| Option | Long Option | Description | Default |
|------|:------:|------:|------:|
| -c | --config | Path to a config file. | /etc/proxlb/proxlb.conf (default) |
| -c | --config | Path to a config file. | /etc/proxlb/proxlb.yaml (default) |
| -d | --dry-run | Performs a dry-run without doing any actions. | False |
| -j | --json | Returns a JSON of the VM movement. | False |
| -b | --best-node | Returns the best next node for a VM/CT placement (useful for further usage with Terraform/Ansible). | False |
@@ -242,11 +373,49 @@ As a result, ProxLB will try to place the VMs with the `plb_anti_affinity_ntp` t
**Note:** While this ensures that ProxLB tries distribute these VMs across different physical hosts within the Proxmox cluster this may not always work. If you have more guests attached to the group than nodes in the cluster, we still need to run them anywhere. If this case occurs, the next one with the most free resources will be selected.
### Ignore VMs
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-ignore-vm-movement.jpg"/> Guests, such as VMs or CTs, can also be completely ignored. This means, they won't be affected by any migration (even when (anti-)affinity rules are enforced). To ensure a proper resource evaluation, these guests are still collected and evaluated but simply skipped for balancing actions. Another thing is the implementation. While ProxLB might have a very restricted configuration file including the file permissions, this file is only read- and writeable by the Proxmox administrators. However, we might have user and groups who want to define on their own that their systems shouldn't be moved. Therefore, these users can simpy set a specific tag to the guest object - just like the (anti)affinity rules.
To define a guest to be ignored from the balancing, users assign a tag with the prefix `plb_ignore_$TAG`:
#### Example for Screenshot
```
plb_ignore_dev
```
As a result, ProxLB will not migrate this guest with the `plb_ignore_dev` tag to any other node.
**Note:** Ignored guests are really ignored. Even by enforcing affinity rules this guest will be ignored.
### Pin VMs to Specific Hypervisor Nodes
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-tag-node-pinning.jpg"/> Guests, such as VMs or CTs, can also be pinned to specific (and multiple) nodes in the cluster. This might be usefull when running applications with some special licensing requirements that are only fulfilled on certain nodes. It might also be interesting, when some physical hardware is attached to a node, that is not available in general within the cluster.
To pin a guest to a specific cluster node, users assign a tag with the prefix `plb_pin_$nodename` to the desired guest:
#### Example for Screenshot
```
plb_pin_node03
```
As a result, ProxLB will pin the guest `dev-vm01` to the node `virt03`.
You can also repeat this step multiple times for different node names to create a potential group of allowed hosts where a the guest may be served on. In this case, ProxLB takes the node with the lowest used resources according to the defined balancing values from this group.
**Note:** The given node names from the tag are validated. This means, ProxLB validated if the given node name is really part of the cluster. In case of a wrongly defined or unavailable node name it continous to use the regular processes to make sure the guest keeps running.
## Maintenance
<img src="https://cdn.gyptazy.com/images/proxlb-rebalancing-demo.gif"/>
The `maintenance_nodes` option allows operators to designate one or more Proxmox nodes for maintenance mode. When a node is set to maintenance, no new guest workloads will be assigned to it, and all existing workloads will be migrated to other available nodes within the cluster. This process ensures that (anti)-affinity rules and resource availability are respected, preventing disruptions while maintaining optimal performance across the infrastructure.
### Adding / Removing Nodes from Maintenance
Within the section `proxmox_cluster` you can define the key `maintenance_nodes` as a list object. Simply add/remove one or more nodes with their equal name in the cluster and restart the daemon.
```
proxmox_cluster:
maintenance_nodes: ['virt66.example.com']
```
Afterwards, all guest objects will be moved to other nodes in the cluster by ensuring the best balancing.
## Misc
### Bugs
Bugs can be reported via the GitHub issue tracker [here](https://github.com/gyptazy/ProxLB/issues). You may also report bugs via email or deliver PRs to fix them on your own. Therefore, you might also see the contributing chapter.
@@ -272,4 +441,4 @@ Connect with us in our dedicated chat room for immediate support and live intera
**Note:** Please always keep in mind that this is a one-man show project without any further help. This includes coding, testing, packaging and all the infrastructure around it to keep this project up and running.
### Author(s)
* Florian Paul Azim Hoberg @gyptazy (https://gyptazy.com)
* Florian Paul Azim Hoberg @gyptazy (https://gyptazy.com)

View File

@@ -1,12 +1,15 @@
proxmox_api:
hosts: ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe']
hosts: ['virt01.example.com', '10.10.10.10', 'fe01:bad:code::cafe']
user: root@pam
pass: crazyPassw0rd!
# API Token method
# token_id: proxlb
# token_secret: 430e308f-1337-1337-beef-1337beefcafe
ssl_verification: False
ssl_verification: True
timeout: 10
# API Connection retries
# retries: 1
# wait_time: 1
proxmox_cluster:
maintenance_nodes: ['virt66.example.com']
@@ -17,15 +20,25 @@ balancing:
enable: True
enforce_affinity: False
parallel: False
# If running parallel job, you can define
# the amount of prallel jobs (default: 5)
parallel_jobs: 1
live: True
with_local_disks: True
with_conntrack_state: True
balance_types: ['vm', 'ct']
max_job_validation: 1800
balanciness: 5
method: memory
mode: assigned
mode: used
service:
daemon: False
schedule: 12
log_level: DEBUG
daemon: True
schedule:
interval: 12
format: hours
delay:
enable: False
time: 1
format: hours
log_level: INFO

80
debian/changelog vendored Normal file
View File

@@ -0,0 +1,80 @@
proxlb (1.1.7) stable; urgency=medium
* Add conntrack state aware migrations of VMs. (Closes: #305)
* Add graceful shutdown for SIGINT command. (Closes: #304)
* Fix crash when validating absent migration job ids. (Closes: #308)
* Fix guest object names are not being evaluated in debug log. (Closes: #310)
* Note: Have a great Dutch Proxmox Day 2025!
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 04 Sep 2025 19:23:51 +0000
proxlb (1.1.6.1) stable; urgency=medium
* Validate for node presence when pinning VMs to avoid crashing. (Closes: #296)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 04 Sep 2025 19:23:51 +0000
proxlb (1.1.6) stable; urgency=medium
* Add validation for provided API user token id to avoid confusions. (Closes: #291)
* Fix stacktrace output when validating permissions on non existing users in Proxmox. (Closes: #291)
* Fix Overprovisioning first node if anti_affinity_group has only one member. (Closes: #295)
* Validate for node presence when pinning guests to avoid crashing. (Closes: #296)
* Fix balancing evaluation of guest types (e.g., VM or CT). (Closes: #268)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 04 Sep 2025 05:12:19 +0000
proxlb (1.1.5) stable; urgency=medium
* Allow custom API ports instead of fixed tcp/8006. (Closes: #260)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Mon, 14 Jul 2025 11:07:34 +0000
proxlb (1.1.4) stable; urgency=medium
* Allow pinning of guests to a group of nodes. (Closes: #245)
* Modified log levels to make output lighter at INFO level. (Closes: #255)
* ixed an issue where balancing was performed in combination of deactivated balancing and dry-run mode. (Closes: #248)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Fri, 27 Jun 2025 16:22:58 +0000
proxlb (1.1.3) stable; urgency=medium
* Add relaod (SIGHUP) function to ProxLB to reload the configuration. (Closes: #189)
* Add optional wait time parameter to delay execution until the service takes action. (Closes: #239)
* Make the amount of parallel migrations configurable. (Closes: #241)
* Use the average CPU consumption of a guest within the last 60 minutes instead of the current CPU usage. (Closes: #94)
* Align maintenance mode with Proxmox HA maintenance mode. (Closes: #232)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 19 Jun 2025 09:10:43 +0000
proxlb (1.1.2) stable; urgency=medium
* Add a configurable retry mechanism when connecting to the Proxmox API. (Closed: #157)
* Add 1-to-1 relationships between guest and hypervisor node to ping a guest on a node. (Closes #218)
* Force type cast cpu count of guests to int for some corner cases where a str got returned. (Closed #222)
* Fix systemd unit file to run after network on non PVE nodes. (Closes #137)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Mon, 13 May 2025 18:12:04 +0000
proxlb (1.1.1) stable; urgency=medium
* Fix tag evluation for VMs for being ignored for further balancing. (Closes: #163)
* Improve logging verbosity of messages that had a wrong servity. (Closes: #165)
* Providing the API upstream error message when migration fails in debug mode (Closes: #205)
* Change the default behaviour of the daemon mode to active. (Closes: #176)
* Change the default banalcing mode to used instead of assigned. (Closes: #180)
* Set cpu_used to the cpu usage, which is a percent, times the total number of cores to get a number where guest cpu_used can be added to nodes cpu_used and be meaningful. (Closes: #195)
* Honor the value when balancing should not be performed and stop balancing. (Closes: #174)
* Allow the use of minutes instead of hours and only accept hours or minutes in the format. (Closes: #187)
* Remove hard coded memory usage from lowest usage node and use method and mode specified in configuration instead. (Closes: #197)
* Fix the guest type relationship in the logs when a migration job failed. (Closes: #204)
* Requery a guest if that running guest reports 0 cpu usage. (Closes: #200)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Sat, 20 Apr 2025 20:55:02 +0000
proxlb (1.1.0) stable; urgency=medium
* Refactored code base of ProxLB. (Closes: #114)
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Mon, 17 Mar 2025 18:55:02 +0000

12
debian/control vendored Normal file
View File

@@ -0,0 +1,12 @@
Source: proxlb
Maintainer: Florian Paul Azim Hoberg <gyptazy@gyptazy.com>
Section: admin
Priority: optional
Standards-Version: 4.5.0
Build-Depends: debhelper-compat (= 13), dh-python, python3-all, python3-setuptools
Package: proxlb
Architecture: all
Depends: ${python3:Depends}, ${misc:Depends}, python3-requests, python3-urllib3, python3-proxmoxer, python3-yaml
Description: A DRS alike Load Balancer for Proxmox Clusters
An advanced DRS alike loadbalancer for Proxmox clusters that also supports maintenance modes and affinity/anti-affinity rules.

2
debian/install vendored Normal file
View File

@@ -0,0 +1,2 @@
proxlb /usr/lib/python3/dist-packages/
service/proxlb.service /lib/systemd/system/

16
debian/postinst vendored Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -e
#DEBHELPER#
if [ "$1" = "configure" ]; then
systemctl enable proxlb.service
systemctl restart proxlb.service || true
# Create the 'plb' user if it does not exist
if ! id "plb" &>/dev/null; then
useradd --system --home /var/lib/proxlb --create-home --shell /usr/sbin/nologin --group nogroup plb
echo "User 'plb' created."
else
echo "User 'plb' already exists, skipping creation."
fi
fi

16
debian/prerm vendored Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -e
#DEBHELPER#
if [ "$1" = "remove" ]; then
systemctl stop proxlb.service || true
systemctl disable proxlb.service || true
# Remove the 'plb' user if it exists
if id "plb" &>/dev/null; then
userdel --remove plb
echo "User 'plb' removed."
else
echo "User 'plb' does not exist, skipping removal."
fi
fi

4
debian/rules vendored Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/make -f
%:
dh $@ --with python3 --buildsystem=pybuild

1
debian/source/format vendored Normal file
View File

@@ -0,0 +1 @@
3.0 (native)

View File

@@ -0,0 +1,65 @@
# Table of Contents
- [Requirements](#requirements)
- [Where To Run?](#where-to-run)
## Requirements
ProxLB is a sophisticated load balancer designed to enhance the management and distribution of workloads within a Proxmox cluster. By fully utilizing the Proxmox API, ProxLB eliminates the need for additional SSH access, streamlining cluster management while maintaining robust security. This chapter outlines the general requirements necessary to deploy and operate ProxLB effectively.
### Proxmox Cluster Requirements
To use ProxLB, you must have an existing Proxmox cluster consisting of at least two nodes. While traditional load balancers often struggle to manage minimal node configurations, ProxLB is optimized to provide efficient load distribution even in a two-node environment. The more nodes present in the cluster, the better ProxLB can optimize resource usage and manage workloads.
### ProxLB Package Requirements
Next to the previously mentioned requirements, ProxLB also requires you to fit the following ones:
* Python3.x
* proxmoxer
* requests
* urllib3
* pyyaml
### Seamless API Integration
ProxLB relies exclusively on the Proxmox API for all management tasks. This eliminates the need for direct SSH access, ensuring a cleaner and more secure interaction with the cluster. The API integration allows ProxLB to:
- Monitor cluster health and node resource utilization
- Migrate virtual machines (VMs) and containers as needed
- Manage storage utilization and distribution
- Implement load balancing policies
### Authentication and Security Standards
ProxLB fully supports Proxmoxs integrated user management system, providing robust authentication and access control. Key features include:
- **Multi-Factor Authentication (MFA):** Enhances security by requiring multiple verification methods.
- **API Key Support:** ProxLB can utilize API keys for authentication instead of traditional username/password combinations, minimizing exposure to credentials.
- **Role-Based Access Control (RBAC):** Ensures administrators have fine-grained control over user permissions.
### Flexible Storage Support
ProxLB offers versatile storage management options, supporting both local and shared storage types. It efficiently balances storage workloads across the cluster using the following storage systems:
- **Local Storage:** Direct-attached storage on each node.
- **Shared Storage:** Includes options like iSCSI, NVMeOF, and NFS for centralized storage solutions.
- **Ceph:** Integrated support for Ceph distributed storage, providing high availability and fault tolerance.
### Network Infrastructure Requirements
For optimal performance, ProxLB requires a reliable and high-speed network connection between the nodes in the cluster. Ensure that the network infrastructure meets the following criteria:
- **Low Latency:** Essential for real-time load balancing and VM migration.
- **Sufficient Bandwidth:** Adequate to handle storage access, data replication, and migration traffic.
- **Redundant Network Paths:** Recommended for increased fault tolerance and uptime.
### System Resource Allocation
ProxLB itself requires minimal system resources to operate. However, for managing larger clusters or high workloads, ensure the node running ProxLB has adequate resources available:
- **CPU:** A modern multi-core processor.
- **Memory:** At least 2 GB of RAM.
- **Storage:** Minimal disk space for configuration files and logs.
## Where To Run?
ProxLB can run on pretty anthing and only requires you to have a network connectivity to any of the Proxmox host's API (usually on tcp/8006).
Therefore, you can simply run ProxLB on:
* Bare-metal Systems
* VMs (even inside the Proxmox cluster)
* Docker/Podman Container
* LXC Container
* On a Proxmox node

View File

@@ -0,0 +1,164 @@
# Table of Contents
- [Installation](#installation)
- [Requirements / Dependencies](#requirements--dependencies)
- [Debian Package](#debian-package)
- [Quick-Start](#quick-start)
- [Details](#details)
- [Debian Packages (.deb files)](#debian-packages-deb-files)
- [RedHat Package](#redhat-package)
- [Container Images / Docker](#container-images--docker)
- [Overview of Images](#overview-of-images)
- [Source](#source)
- [Traditional System](#traditional-system)
- [Container Image](#container-image)
- [Upgrading](#upgrading)
- [Upgrading from < 1.1.0](#upgrading-from--110)
- [Upgrading from >= 1.1.0](#upgrading-from--110)
## Installation
### Requirements / Dependencies
* Python3.x
* proxmoxer
* requests
* urllib3
* pyyaml
The dependencies can simply be installed with `pip` by running the following command:
```
pip install -r requirements.txt
```
*Note: Distribution packages, such like the provided `.deb` package will automatically resolve and install all required dependencies by using already packaged version from the distribution's repository. By using the Docker (container) image or Debian packages, you do not need to take any care of the requirements listed here.*
### Debian Package
ProxLB is a powerful and flexible load balancer designed to work across various architectures, including `amd64`, `arm64`, `rv64` and many other ones that support Python. It runs independently of the underlying hardware, making it a versatile choice for different environments. This chapter covers the step-by-step process to install ProxLB on Debian-based systems, including Debian clones like Ubuntu.
#### Quick-Start
You can simply use this snippet to install the repository and to install ProxLB on your system.
```bash
echo "deb https://repo.gyptazy.com/stable /" > /etc/apt/sources.list.d/proxlb.list
wget -O /etc/apt/trusted.gpg.d/proxlb.asc https://repo.gyptazy.com/repository.gpg
apt-get update && apt-get -y install proxlb
cp /etc/proxlb/proxlb_example.yaml /etc/proxlb/proxlb.yaml
# Adjust the config to your needs
vi /etc/proxlb/proxlb.yaml
systemctl start proxlb
```
Afterwards, ProxLB is running in the background and balances your cluster by your defined balancing method (default: memory).
#### Details
ProxLB provides two different repositories:
* https://repo.gyptazy.com/stable (only stable release)
* https://repo.gyptazy.com/testing (bleeding edge - not recommended)
The repository is signed and the GPG key can be found at:
* https://repo.gyptazy.com/repository.gpg
You can also simply import it by running:
```
# KeyID: 17169F23F9F71A14AD49EDADDB51D3EB01824F4C
# UID: gyptazy Solutions Repository <contact@gyptazy.com>
# SHA256: 52c267e6f4ec799d40cdbdb29fa518533ac7942dab557fa4c217a76f90d6b0f3 repository.gpg
wget -O /etc/apt/trusted.gpg.d/proxlb.asc https://repo.gyptazy.com/repository.gpg
```
*Note: The defined repositories `repo.gyptazy.com` and `repo.proxlb.de` are the same!*
#### Debian Packages (.deb files)
If you do not want to use the repository you can also find the debian packages as a .deb file on gyptazy's CDN at:
* https://cdn.gyptazy.com/files/os/debian/proxlb/
Afterwards, you can simply install the package by running:
```bash
dpkg -i proxlb_*.deb
cp /etc/proxlb/proxlb_example.yaml /etc/proxlb/proxlb.yaml
# Adjust the config to your needs
vi /etc/proxlb/proxlb.yaml
systemctl start proxlb
```
### RedHat Package
There's currently no official support for RedHat based systems. However, there's a dummy .rpm package for such systems in the pipeline which can be found here:
* https://github.com/gyptazy/ProxLB/actions/workflows/20-pipeline-build-rpm-package.yml
### Container Images / Docker
Using the ProxLB container images is straight forward and only requires you to mount the config file.
```bash
# Pull the image
docker pull cr.gyptazy.com/proxlb/proxlb:latest
# Download the config
wget -O proxlb.yaml https://raw.githubusercontent.com/gyptazy/ProxLB/refs/heads/main/config/proxlb_example.yaml
# Adjust the config to your needs
vi proxlb.yaml
# Start the ProxLB container image with the ProxLB config
docker run -it --rm -v $(pwd)/proxlb.yaml:/etc/proxlb/proxlb.yaml proxlb
```
*Note: ProxLB container images are officially only available at cr.proxlb.de and cr.gyptazy.com.*
#### Overview of Images
| Version | Image |
|------|:------:|
| latest | cr.gyptazy.com/proxlb/proxlb:latest |
| v1.1.0 | cr.gyptazy.com/proxlb/proxlb:v1.1.0 |
| v1.0.6 | cr.gyptazy.com/proxlb/proxlb:v1.0.6 |
| v1.0.5 | cr.gyptazy.com/proxlb/proxlb:v1.0.5 |
| v1.0.4 | cr.gyptazy.com/proxlb/proxlb:v1.0.4 |
| v1.0.3 | cr.gyptazy.com/proxlb/proxlb:v1.0.3 |
| v1.0.2 | cr.gyptazy.com/proxlb/proxlb:v1.0.2 |
| v1.0.0 | cr.gyptazy.com/proxlb/proxlb:v1.0.0 |
| v0.9.9 | cr.gyptazy.com/proxlb/proxlb:v0.9.9 |
### Source
ProxLB can also easily be used from the provided sources - for traditional systems but also as a Docker/Podman container image.
#### Traditional System
Setting up and running ProxLB from the sources is simple and requires just a few commands. Ensure Python 3 and the Python dependencies are installed on your system, then run ProxLB using the following command:
```bash
git clone https://github.com/gyptazy/ProxLB.git
cd ProxLB
```
Afterwards simply adjust the config file to your needs:
```bash
vi config/proxlb.yaml
```
Start ProxLB by Python3 on the system:
```bash
python3 proxlb/main.py -c config/proxlb.yaml
```
#### Container Image
Creating a container image of ProxLB is straightforward using the provided Dockerfile. The Dockerfile simplifies the process by automating the setup and configuration required to get ProxLB running in an Alpine container. Simply follow the steps in the Dockerfile to build the image, ensuring all dependencies and configurations are correctly applied. For those looking for an even quicker setup, a ready-to-use ProxLB container image is also available, eliminating the need for manual building and allowing for immediate deployment.
```bash
git clone https://github.com/gyptazy/ProxLB.git
cd ProxLB
docker build -t proxlb .
```
Afterwards simply adjust the config file to your needs:
```bash
vi config/proxlb.yaml
```
Finally, start the created container.
```bash
docker run -it --rm -v $(pwd)/proxlb.yaml:/etc/proxlb/proxlb.yaml proxlb
```
## Upgrading
### Upgrading from < 1.1.0
Upgrading ProxLB is not supported due to a fundamental redesign introduced in version 1.1.x. With this update, ProxLB transitioned from a monolithic application to a pure Python-style project, embracing a more modular and flexible architecture. This shift aimed to improve maintainability and extensibility while keeping up with modern development practices. Additionally, ProxLB moved away from traditional ini-style configuration files and adopted YAML for configuration management. This change simplifies configuration handling, reduces the need for extensive validation, and ensures better type casting, ultimately providing a more streamlined and user-friendly experience.
### Upgrading from >= 1.1.0
Uprading within the current stable versions, starting from 1.1.0, will be possible in all supported ways.

238
docs/03_configuration.md Normal file
View File

@@ -0,0 +1,238 @@
# Table of Contents
1. [Authentication / User Accounts / Permissions](#authentication--user-accounts--permissions)
1. [Authentication](#authentication)
2. [Creating a Dedicated User](#creating-a-dedicated-user)
3. [Creating an API Token for a User](#creating-an-api-token-for-a-user)
4. [Required Permissions for a User](#required-permissions-for-a-user)
2. [Configuration](#configuration)
1. [Affinity & Anti-Affinity Rules](#affinity--anti-affinity-rules)
1. [Affinity Rules](#affinity-rules)
2. [Anti-Affinity Rules](#anti-affinity-rules)
3. [Affinity / Anti-Affinity Enforcing](#affinity--anti-affinity-enforcing)
4. [Ignore VMs](#ignore-vms)
5. [Pin VMs to Hypervisor Nodes](#pin-vms-to-hypervisor-nodes)
2. [API Loadbalancing](#api-loadbalancing)
3. [Ignore Host-Nodes or Guests](#ignore-host-nodes-or-guests)
4. [IPv6 Support](#ipv6-support)
5. [Logging / Log-Level](#logging--log-level)
6. [Parallel Migrations](#parallel-migrations)
7. [Run as a Systemd-Service](#run-as-a-systemd-service)
8. [SSL Self-Signed Certificates](#ssl-self-signed-certificates)
9. [Node Maintenances](#node-maintenances)
## Authentication / User Accounts / Permissions
### Authentication
ProxLB supports the traditional username and password authentication method, which is familiar to many users. This method requires users to provide their credentials (username and password) to gain access to the Proxmox system. While this method is straightforward and easy to implement, it has several security limitations. Username and password combinations can be vulnerable to brute force attacks, where an attacker systematically attempts various combinations until the correct one is found. If a user's credentials are compromised through phishing, malware, or other means, the attacker can gain unauthorized access to the system. Additionally, traditional authentication does not provide granular control over permissions and access levels, potentially exposing sensitive operations to unauthorized users.
To enhance security, ProxLB supports API token authentication. API tokens are unique identifiers that are used to authenticate API requests. They offer several advantages over traditional username and password authentication. API tokens are more secure as they are typically long, random strings that are difficult to guess. They can be revoked and regenerated as needed, reducing the risk of unauthorized access. API tokens can be associated with specific user accounts that have only the required permissions, ensuring that users only have access to the resources and operations they need. Furthermore, API tokens can be used for automated scripts and applications, facilitating seamless integration with other systems and services.
When Multi-Factor Authentication (MFA) or Two-Factor Authentication (2FA) is enabled in the Proxmox cluster, the system enforces the use of API tokens for authentication. This is because traditional username and password authentication is not considered secure enough in conjunction with MFA/2FA. To ensure the highest level of security when using API tokens, follow these best practices: Use dedicated user accounts for API tokens, each with only the necessary permissions. This limits the potential impact of a compromised token. Ensure that API tokens are long, random, and unique. Avoid using easily guessable patterns or sequences. Periodically regenerate and replace API tokens to minimize the risk of long-term exposure. Store API tokens securely, using environment variables or secure vaults. Avoid hardcoding tokens in source code or configuration files. Regularly monitor and audit the usage of API tokens to detect any suspicious activity or unauthorized access.
### Creating a Dedicated User
It is advisable to avoid using the default root@pam user for balancing tasks in ProxLB. Instead, creating a dedicated user account is recommended and can be done easily. You can create a new user through the GUI, API, or CLI. While the detailed roles required for balancing are outlined in the next chapter, you can also use the following CLI commands to create a user with the necessary roles to manage Virtual Machines (VMs) and Containers (CTs):
```
pveum role add proxlb --privs Datastore.Audit,Sys.Audit,VM.Audit,VM.Migrate
pveum user add proxlb@pve --password <password>
pveum acl modify / --roles proxlb --users proxlb@pve
```
*Note: The user management can also be done on the WebUI without invoking the CLI.*
### Creating an API Token for a User
Create an API token for user proxlb@pve with token ID proxlb and deactivated privilege separation:
```
pveum user token add proxlb@pve proxlb --privsep 0
```
Afterwards, you get the token secret returned. You can now add those entries to your ProxLB config. Make sure, that you also keep the `user` parameter, next to the new token parameters.
> [!IMPORTANT]
> The parameter `pass` then needs to be **absent**! You should also take care about the privilege and authentication mechanism behind Proxmox. You might want or even might not want to use privilege separation and this is up to your personal needs and use case.
| Proxmox API | ProxLB Config | Example |
|---|---|---|
| User | [user](https://github.com/gyptazy/ProxLB/blob/main/config/proxlb_example.yaml#L3) | proxlb@pve |
| Token ID | [token_id](https://github.com/gyptazy/ProxLB/blob/main/config/proxlb_example.yaml#L6) | proxlb |
| Token Secret | [token_secret](https://github.com/gyptazy/ProxLB/blob/main/config/proxlb_example.yaml#L7) | 430e308f-1337-1337-beef-1337beefcafe |
*Note: The API token configuration can also be done on the WebUI without invoking the CLI.*
### Required Permissions for a User
To ensure that ProxLB operates effectively and securely, it is essential to assign the appropriate permissions to the user accounts responsible for managing the load balancing tasks. The following permissions are the minimum required for a user to perform essential ProxLB operations:
* `Datastore.Audit`: Grants the ability to audit and view datastore information.
* `Sys.Audit`: Allows the user to audit and view system information.
* `VM.Audit`: Enables the user to audit and view virtual machine details.
* `VM.Migrate`: Provides the permission to migrate virtual machines.
Assigning these permissions ensures that the user can access necessary information and perform critical operations related to load balancing without granting excessive privileges. This practice helps maintain a secure and efficient ProxLB environment.
## Configuration
### Affinity & Anti-Affinity Rules
ProxLB provides an advanced mechanism to define affinity and anti-affinity rules, enabling precise control over virtual machine (VM) placement. These rules help manage resource distribution, improve high availability configurations, and optimize performance within a Proxmox Virtual Environment (PVE) cluster. By leveraging Proxmoxs integrated access management, ProxLB ensures that users can only define and manage rules for guests they have permission to access.
ProxLB implements affinity and anti-affinity rules through a tag-based system within the Proxmox web interface. Each guest (virtual machine or container) can be assigned specific tags, which then dictate its placement behavior. This method maintains a streamlined and secure approach to managing VM relationships while preserving Proxmoxs inherent permission model.
#### Affinity Rules
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-affinity-rules.jpg"/> Affinity rules are used to group certain VMs together, ensuring that they run on the same host whenever possible. This can be beneficial for workloads requiring low-latency communication, such as clustered databases or application servers that frequently exchange data.
To define an affinity rule which keeps all guests assigned to this tag together on a node, users assign a tag with the prefix `plb_affinity_$TAG`:
##### Example for Screenshot
```
plb_affinity_talos
```
As a result, ProxLB will attempt to place all VMs with the `plb_affinity_web` tag on the same host (see also the attached screenshot with the same node).
#### Anti-Affinity Rules
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-anti-affinity-rules.jpg"/> Conversely, anti-affinity rules ensure that designated VMs do not run on the same physical host. This is particularly useful for high-availability setups, where redundancy is crucial. Ensuring that critical services are distributed across multiple hosts reduces the risk of a single point of failure.
To define an anti-affinity rule that ensures to not move systems within this group to the same node, users assign a tag with the prefix:
##### Example for Screenshot
```
plb_anti_affinity_ntp
```
As a result, ProxLB will try to place the VMs with the `plb_anti_affinity_ntp` tag on different hosts (see also the attached screenshot with the different nodes).
**Note:** While this ensures that ProxLB tries distribute these VMs across different physical hosts within the Proxmox cluster this may not always work. If you have more guests attached to the group than nodes in the cluster, we still need to run them anywhere. If this case occurs, the next one with the most free resources will be selected.
### Affinity / Anti-Affinity Enforcing
When a cluster is already balanced and does not require further adjustments, enabling the enforce_affinity parameter ensures that affinity and anti-affinity rules are still respected. This parameter prioritizes the placement of guest objects according to these rules, even if it leads to slight resource imbalances or increased migration overhead. Regularly reviewing and updating these rules, along with monitoring cluster performance, helps maintain optimal performance and reliability. By carefully managing these aspects, you can create a cluster environment that meets your specific needs and maintains a good balance of resources.
```
balancing:
enforce_affinity: True
```
*Note: This may have impacts to the cluster. Depending on the created group matrix, the result may also be an unbalanced cluster.*
### Ignore VMs / CTs
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-ignore-vm-movement.jpg"/> Guests, such as VMs or CTs, can also be completely ignored. This means, they won't be affected by any migration (even when (anti-)affinity rules are enforced). To ensure a proper resource evaluation, these guests are still collected and evaluated but simply skipped for balancing actions. Another thing is the implementation. While ProxLB might have a very restricted configuration file including the file permissions, this file is only read- and writeable by the Proxmox administrators. However, we might have user and groups who want to define on their own that their systems shouldn't be moved. Therefore, these users can simpy set a specific tag to the guest object - just like the (anti)affinity rules.
To define a guest to be ignored from the balancing, users assign a tag with the prefix `plb_ignore_$TAG`:
#### Example for Screenshot
```
plb_ignore_dev
```
As a result, ProxLB will not migrate this guest with the `plb_ignore_dev` tag to any other node.
**Note:** Ignored guests are really ignored. Even by enforcing affinity rules this guest will be ignored.
### Pin VMs to Specific Hypervisor Nodes
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-tag-node-pinning.jpg"/> Guests, such as VMs or CTs, can also be pinned to specific nodes in the cluster. This might be usefull when running applications with some special licensing requirements that are only fulfilled on certain nodes. It might also be interesting, when some physical hardware is attached to a node, that is not available in general within the cluster.
To pin a guest to a specific cluster node, users assign a tag with the prefix `plb_pin_$nodename` to the desired guest:
#### Example for Screenshot
```
plb_pin_node03
```
As a result, ProxLB will pin the guest `dev-vm01` to the node `virt03`.
You can also repeat this step multiple times for different node names to create a potential group of allowed hosts where a the guest may be served on. In this case, ProxLB takes the node with the lowest used resources according to the defined balancing values from this group.
**Note:** The given node names from the tag are validated. This means, ProxLB validated if the given node name is really part of the cluster. In case of a wrongly defined or unavailable node name it continous to use the regular processes to make sure the guest keeps running.
### API Loadbalancing
ProxLB supports API loadbalancing, where one or more host objects can be defined as a list. This ensures, that you can even operator ProxLB without further changes when one or more nodes are offline or in a maintenance. When defining multiple hosts, the first reachable one will be picked. You can speficy custom ports in the list. There are 4 ways of defining hosts with ports:
1. Hostname of IPv4 without port (in this case the default 8006 will be used)
2. Hostname or IPv4 with port
3. IPv6 in brackets with optional port
4. IPv6 without brackets, in this case the port is assumed after last colon
```
proxmox_api:
hosts: ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe', 'virt01.example.com:443', '[fc00::1]', '[fc00::1]:443', 'fc00::1:8006']
```
### Ignore Host-Nodes or Guests
In managing a Proxmox environment, it's often necessary to exclude certain host nodes and guests from various operations. For host nodes, this exclusion can be achieved by specifying them in the ignore_nodes parameter within the proxmox_api chapter, effectively preventing any automated processes from interacting with these nodes. Guests, on the other hand, can be ignored by assigning them a specific tag that starts with or is equal to plb_ignore, ensuring they are omitted from any automated tasks or monitoring. By implementing these configurations, administrators can fine-tune their Proxmox management to focus only on relevant nodes and guests, optimizing operational efficiency and resource allocation.
```
proxmox_cluster:
ignore_nodes: ['node01', 'node02']
```
### IPv6 Support
Yes, ProxLB fully supports IPv6.
### Logging / Log-Level
ProxLB supports systemd for seamless service management on Linux distributions. To enable this, create a proxLB.service file in /etc/systemd/system/ from `service/proxlb.service` within this repository.
On systems without systemd, such as FreeBSD and macOS, ProxLB runs with similar configurations but logs to stdout and stderr. The logging level and verbosity can be set in the `service` section of the configuration file:
```
service:
log_level: DEBUG
```
ProxLB only support the following log levels:
* INFO
* WARNING
* CRITICAL
* DEBUG
### Parallel Migrations
By default, parallel migrations are deactivated. This means, that a guest object gets migrated and the migration job is being watched until the VM or CT got moved to a new node. However, this may take a lot of time and many environments are fast enough to handle the IO load for multiple guest objects. However, there are always corner cases and this depends on your setup. Parallel migrations can be enabled by setting `parallel` to `True` within the `balancing` chapter:
```
balancing:
parallel: False
```
### Run as a Systemd-Service
The proxlb systemd unit orchestrates the ProxLB application. ProxLB can be used either as a one-shot solution or run periodically, depending on the configuration specified in the daemon chapter of its configuration file.
```
service:
daemon: False
schedule:
interval: 12
format: hours
```
In this configuration:
* `daemon`: False indicates that the ProxLB application is not running as a daemon and will execute as a one-shot solution.
* `schedule`: 12 defines the interval for the schedule, specifying how often rebalancing should be done if running as a daemon.
* `format`: Defines the given format of schedule where you can choose between `hours` or `minutes`.
### SSL Self-Signed Certificates
If you are using SSL self-signed certificates or non-valid certificated in general and do not want to deal with additional trust levels, you may also disable the SSL validation. This may mostly be helpful for dev- & test labs.
SSL certificate validation can be disabled in the `proxmox_api` section in the config file by setting:
```
proxmox_api:
ssl_verification: False
```
*Note: Disabling SSL certificate validation is not recommended.*
### Node Maintenances
To exclude specific nodes from receiving any new workloads during the balancing process, the `maintenance_nodes` configuration option can be used. This option allows administrators to define a list of nodes that are currently undergoing maintenance or should otherwise not be used for running virtual machines or containers.
```yaml
maintenance_nodes:
- virt66.example.com
```
which can also be written as:
```yaml
maintenance_nodes: ['virt66.example.com']
```
The maintenance_nodes key must be defined as a list, even if it only includes a single node. Each entry in the list must exactly match the node name as it is known within the Proxmox VE cluster. Do not use IP addresses, alternative DNS names, or aliases—only the actual cluster node names are valid. Once a node is marked as being in maintenance mode:
* No new workloads will be balanced or migrated onto it.
* Any existing workloads currently running on the node will be migrated away in accordance with the configured balancing strategies, assuming resources on other nodes allow.
This feature is particularly useful during planned maintenance, upgrades, or troubleshooting, ensuring that services continue to run with minimal disruption while the specified node is being worked on.

24
docs/99-faq.md Normal file
View File

@@ -0,0 +1,24 @@
## Table of Contents
1. [GUI Integration](#gui-integration)
- [How to install pve-proxmoxlb-service-ui package](https://github.com/gyptazy/ProxLB/issues/44)
2. [Proxmox HA Integration](#proxmox-ha-integration)
- [Host groups: Honour HA groups](https://github.com/gyptazy/ProxLB/issues/65)
### GUI Integration
<img align="left" src="https://cdn.gyptazy.com/images/proxlb-GUI-integration.jpg"/> ProxLB can also be accessed through the Proxmox Web UI by installing the optional `pve-proxmoxlb-service-ui` package, which depends on the proxlb package. For full Web UI integration, this package must be installed on all nodes within the cluster. Once installed, a new menu item - `Rebalancing`, appears in the cluster level under the HA section. Once installed, it offers two key functionalities:
* Rebalancing VM workloads
* Migrate VM workloads away from a defined node (e.g. maintenance preparation)
**Note:** This package is currently discontinued and will be readded at a later time. See also: [#44: How to install pve-proxmoxlb-service-ui package](https://github.com/gyptazy/ProxLB/issues/44).
### Proxmox HA Integration
Proxmox HA (High Availability) groups are designed to ensure that virtual machines (VMs) remain running within a Proxmox cluster. HA groups define specific rules for where VMs should be started or migrated in case of node failures, ensuring minimal downtime and automatic recovery.
However, when used in conjunction with ProxLB, the built-in load balancer for Proxmox, conflicts can arise. ProxLB operates with its own logic for workload distribution, taking into account affinity and anti-affinity rules. While it effectively balances guest workloads, it may re-shift and redistribute VMs in a way that does not align with HA group constraints, potentially leading to unsuitable placements.
Due to these conflicts, it is currently not recommended to use both HA groups and ProxLB simultaneously. The interaction between the two mechanisms can lead to unexpected behavior, where VMs might not adhere to HA group rules after being moved by ProxLB.
A solution to improve compatibility between HA groups and ProxLB is under evaluation, aiming to ensure that both features can work together without disrupting VM placement strategies.
See also: [#65: Host groups: Honour HA groups](https://github.com/gyptazy/ProxLB/issues/65).

View File

6
helm/proxlb/Chart.yaml Normal file
View File

@@ -0,0 +1,6 @@
apiVersion: v3
name: proxlb
description: A Helm chart for self-hosted ProxLB
type: application
version: "1.1.7"
appVersion: "v1.1.7"

View File

@@ -0,0 +1,13 @@
{{- define "proxlb.fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{ define "proxlb.labels" }}
app.kubernetes.io/name: {{ .Release.Name }}
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: proxlb
{{- if .Values.labels }}
{{ toYaml .Values.labels }}
{{- end }}
{{ end }}

View File

@@ -0,0 +1,11 @@
{{- if .Values.configmap.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: proxlb-config
labels:
{{- include "proxlb.labels" . | nindent 4 }}
data:
proxlb.yaml: |
{{ toYaml .Values.configmap.config | indent 4 }}
{{ end }}

View File

@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
labels:
{{- include "proxlb.labels" . | nindent 4 }}
spec:
replicas: 1 # Number of replicas cannot be more than 1
selector:
matchLabels:
{{- include "proxlb.labels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "proxlb.labels" . | nindent 8 }}
spec:
{{- with .Values.image.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
# not interacting with the k8s cluster
automountServiceAccountToken: False
containers:
- name: proxlb
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
{{- if .Values.extraArgs.dryRun }}
- --dry-run
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/proxlb/proxlb.yaml
subPath: proxlb.yaml
{{ if .Values.resources }}
resources:
{{ with .Values.resources }}
{{ toYaml . | nindent 10 }}
{{ end }}
{{ end }}
volumes:
- name: config
configMap:
name: proxlb-config

61
helm/proxlb/values.yaml Normal file
View File

@@ -0,0 +1,61 @@
image:
registry: cr.gyptazy.com
repository: proxlb/proxlb
tag: v1.1.7
pullPolicy: IfNotPresent
imagePullSecrets: [ ]
resources:
limits:
cpu: "1000m"
memory: "2Gi"
requests:
cpu: "100m"
memory: "100Mi"
labels: {}
extraArgs:
dryRun: false
configmap:
create: true
config:
proxmox_api:
hosts: []
#Can be either a user or a token
# user: ""
# pass: ""
# token_id: ""
# token_secret: ""
ssl_verification: True
timeout: 10
proxmox_cluster:
maintenance_nodes: [ ]
ignore_nodes: [ ]
overprovisioning: True
balancing:
enable: True
enforce_affinity: False
parallel: False
# If running parallel job, you can define
# the amount of prallel jobs (default: 5)
parallel_jobs: 1
live: True
with_local_disks: True
with_conntrack_state: True
balance_types: [ 'vm', 'ct' ]
max_job_validation: 1800
balanciness: 5
method: memory
mode: used
service:
daemon: True
schedule:
interval: 12
format: "hours"
delay:
enable: False
time: 1
format: "hours"
log_level: INFO

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env bash
VERSION="1.1.0-alpha"
VERSION="1.1.7"
# ProxLB
sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" "proxlb/utils/version.py"
sed -i "s/version=\"[0-9]*\.[0-9]*\.[0-9]*\"/version=\"$VERSION\"/" setup.py
echo "OK: Versions have been sucessfully set to $VERSION"
# Helm Chart
sed -i "s/^version: .*/version: \"$VERSION\"/" helm/proxlb/Chart.yaml
sed -i "s/^appVersion: .*/appVersion: \"v$VERSION\"/" helm/proxlb/Chart.yaml
echo "OK: Versions have been sucessfully set to $VERSION"

View File

@@ -1,2 +0,0 @@
useradd -m plb -s /sbin/nologin
systemctl daemon-reload

View File

@@ -1,3 +0,0 @@
override_dh_python3:
# Do not auto-generate postinst

View File

@@ -13,6 +13,7 @@ __license__ = "GPL-3.0"
import logging
import signal
from utils.logger import SystemdLogger
from utils.cli_parser import CliParser
from utils.config_parser import ConfigParser
@@ -32,6 +33,10 @@ def main():
# Initialize logging handler
logger = SystemdLogger(level=logging.INFO)
# Initialize handlers
signal.signal(signal.SIGHUP, Helper.handler_sighup)
signal.signal(signal.SIGINT, Helper.handler_sigint)
# Parses arguments passed from the CLI
cli_parser = CliParser()
cli_args = cli_parser.parse_args()
@@ -44,6 +49,9 @@ def main():
# Update log level from config and fallback to INFO if not defined
logger.set_log_level(proxlb_config.get('service', {}).get('log_level', 'INFO'))
# Validate of an optional service delay
Helper.get_service_delay(proxlb_config)
# Connect to Proxmox API & create API object
proxmox_api = ProxmoxApi(proxlb_config)
@@ -51,10 +59,19 @@ def main():
proxlb_config["proxmox_api"]["pass"] = "********"
while True:
# Validate if reload signal was sent during runtime
# and reload the ProxLB configuration and adjust log level
if Helper.proxlb_reload:
logger.info("Reloading ProxLB configuration.")
proxlb_config = config_parser.get_config()
logger.set_log_level(proxlb_config.get('service', {}).get('log_level', 'INFO'))
Helper.proxlb_reload = False
# Get all required objects from the Proxmox cluster
meta = {"meta": proxlb_config}
nodes = Nodes.get_nodes(proxmox_api, proxlb_config)
guests = Guests.get_guests(proxmox_api, nodes)
guests = Guests.get_guests(proxmox_api, nodes, meta)
groups = Groups.get_groups(guests, nodes)
# Merge obtained objects from the Proxmox cluster for further usage
@@ -71,9 +88,13 @@ def main():
Helper.log_node_metrics(proxlb_data, init=False)
# Perform balancing actions via Proxmox API
if not cli_args.dry_run:
Balancing(proxmox_api, proxlb_data)
if proxlb_data["meta"]["balancing"].get("enable", False):
if not cli_args.dry_run:
Balancing(proxmox_api, proxlb_data)
# Validate if the JSON output should be
# printed to stdout
Helper.print_json(proxlb_data, cli_args.json)
# Validate daemon mode
Helper.get_daemon_mode(proxlb_config)

View File

@@ -12,6 +12,7 @@ __license__ = "GPL-3.0"
import proxmoxer
import time
from itertools import islice
from utils.logger import SystemdLogger
from typing import Dict, Any
@@ -48,26 +49,81 @@ class Balancing:
Initializes the Balancing class with the provided ProxLB data.
Args:
proxlb_data (dict): The data required for balancing VMs and CTs.
proxmox_api (object): The Proxmox API client instance used to interact with the Proxmox cluster.
proxlb_data (dict): A dictionary containing data related to the ProxLB load balancing configuration.
"""
for guest_name, guest_meta in proxlb_data["guests"].items():
def chunk_dict(data, size):
"""
Splits a dictionary into chunks of a specified size.
Args:
data (dict): The dictionary to be split into chunks.
size (int): The size of each chunk.
Yields:
dict: A chunk of the original dictionary with the specified size.
"""
logger.debug("Starting: chunk_dict.")
it = iter(data.items())
for chunk in range(0, len(data), size):
yield dict(islice(it, size))
if guest_meta["node_current"] != guest_meta["node_target"]:
guest_id = guest_meta["id"]
guest_node_current = guest_meta["node_current"]
guest_node_target = guest_meta["node_target"]
# Validate if balancing should be performed in parallel or sequentially.
# If parallel balancing is enabled, set the number of parallel jobs.
parallel_jobs = proxlb_data["meta"]["balancing"].get("parallel_jobs", 5)
if not proxlb_data["meta"]["balancing"].get("parallel", False):
parallel_jobs = 1
logger.debug("Balancing: Parallel balancing is disabled. Running sequentially.")
else:
logger.debug(f"Balancing: Parallel balancing is enabled. Running with {parallel_jobs} parallel jobs.")
# VM Balancing
if guest_meta["type"] == "vm":
self.exec_rebalancing_vm(proxmox_api, proxlb_data, guest_name)
for chunk in chunk_dict(proxlb_data["guests"], parallel_jobs):
jobs_to_wait = []
# CT Balancing
elif guest_meta["type"] == "ct":
self.exec_rebalancing_ct(proxmox_api, proxlb_data, guest_name)
for guest_name, guest_meta in chunk.items():
# Hopefully never reaching, but should be catched
# Check if the guest's target is not the same as the current node
if guest_meta["node_current"] != guest_meta["node_target"]:
# Check if the guest is not ignored and perform the balancing
# operation based on the guest type
if not guest_meta["ignore"]:
job_id = None
# VM Balancing
if guest_meta["type"] == "vm":
if 'vm' in proxlb_data["meta"]["balancing"].get("balance_types", []):
logger.debug(f"Balancing: Balancing for guest {guest_name} of type VM started.")
job_id = self.exec_rebalancing_vm(proxmox_api, proxlb_data, guest_name)
else:
logger.debug(
f"Balancing: Balancing for guest {guest_name} will not be performed. "
"Guest is of type VM which is not included in allowed balancing types.")
# CT Balancing
elif guest_meta["type"] == "ct":
if 'ct' in proxlb_data["meta"]["balancing"].get("balance_types", []):
logger.debug(f"Balancing: Balancing for guest {guest_name} of type CT started.")
job_id = self.exec_rebalancing_ct(proxmox_api, proxlb_data, guest_name)
else:
logger.debug(
f"Balancing: Balancing for guest {guest_name} will not be performed. "
"Guest is of type CT which is not included in allowed balancing types.")
# Just in case we get a new type of guest in the future
else:
logger.critical(f"Balancing: Got unexpected guest type: {guest_meta['type']}. Cannot proceed guest: {guest_meta['name']}.")
if job_id:
jobs_to_wait.append((guest_name, guest_meta["node_current"], job_id))
else:
logger.debug(f"Balancing: Guest {guest_name} is ignored and will not be rebalanced.")
else:
logger.critical(f"Balancing: Got unexpected guest type: {guest_meta['type']}. Cannot proceed guest: {guest_meta['name']}.")
logger.debug(f"Balancing: Guest {guest_name} is already on the target node {guest_meta['node_target']} and will not be rebalanced.")
# Wait for all jobs in the current chunk to complete
for guest_name, node, job_id in jobs_to_wait:
if job_id:
self.get_rebalancing_job_status(proxmox_api, proxlb_data, guest_name, node, job_id)
def exec_rebalancing_vm(self, proxmox_api: any, proxlb_data: Dict[str, Any], guest_name: str) -> None:
"""
@@ -88,6 +144,7 @@ class Balancing:
guest_id = proxlb_data["guests"][guest_name]["id"]
guest_node_current = proxlb_data["guests"][guest_name]["node_current"]
guest_node_target = proxlb_data["guests"][guest_name]["node_target"]
job_id = None
if proxlb_data["meta"]["balancing"].get("live", True):
online_migration = 1
@@ -99,20 +156,27 @@ class Balancing:
else:
with_local_disks = 0
if proxlb_data["meta"]["balancing"].get("with_conntrack_state", True):
with_conntrack_state = 1
else:
with_conntrack_state = 0
migration_options = {
'target': {guest_node_target},
'target': guest_node_target,
'online': online_migration,
'with-local-disks': with_local_disks
'with-local-disks': with_local_disks,
'with-conntrack-state': with_conntrack_state,
}
try:
logger.debug(f"Balancing: Starting to migrate guest {guest_name} of type VM.")
logger.info(f"Balancing: Starting to migrate VM guest {guest_name} from {guest_node_current} to {guest_node_target}.")
job_id = proxmox_api.nodes(guest_node_current).qemu(guest_id).migrate().post(**migration_options)
job = self.get_rebalancing_job_status(proxmox_api, proxlb_data, guest_name, guest_node_current, job_id)
except proxmoxer.core.ResourceException as proxmox_api_error:
logger.critical(f"Balancing: Failed to migrate guest {guest_name} of type CT due to some Proxmox errors. Please check if resource is locked or similar.")
logger.critical(f"Balancing: Failed to migrate guest {guest_name} of type VM due to some Proxmox errors. Please check if resource is locked or similar.")
logger.debug(f"Balancing: Failed to migrate guest {guest_name} of type VM due to some Proxmox errors: {proxmox_api_error}")
logger.debug("Finished: exec_rebalancing_vm.")
return job_id
def exec_rebalancing_ct(self, proxmox_api: any, proxlb_data: Dict[str, Any], guest_name: str) -> None:
"""
@@ -133,15 +197,17 @@ class Balancing:
guest_id = proxlb_data["guests"][guest_name]["id"]
guest_node_current = proxlb_data["guests"][guest_name]["node_current"]
guest_node_target = proxlb_data["guests"][guest_name]["node_target"]
job_id = None
try:
logger.debug(f"Balancing: Starting to migrate guest {guest_name} of type CT.")
logger.info(f"Balancing: Starting to migrate CT guest {guest_name} from {guest_node_current} to {guest_node_target}.")
job_id = proxmox_api.nodes(guest_node_current).lxc(guest_id).migrate().post(target=guest_node_target, restart=1)
job = self.get_rebalancing_job_status(proxmox_api, proxlb_data, guest_name, guest_node_current, job_id)
except proxmoxer.core.ResourceException as proxmox_api_error:
logger.critical(f"Balancing: Failed to migrate guest {guest_name} of type CT due to some Proxmox errors. Please check if resource is locked or similar.")
logger.debug(f"Balancing: Failed to migrate guest {guest_name} of type CT due to some Proxmox errors: {proxmox_api_error}")
logger.debug("Finished: exec_rebalancing_ct.")
return job_id
def get_rebalancing_job_status(self, proxmox_api: any, proxlb_data: Dict[str, Any], guest_name: str, guest_current_node: str, job_id: int, retry_counter: int = 1) -> bool:
"""
@@ -159,35 +225,32 @@ class Balancing:
bool: True if the job completed successfully, False otherwise.
"""
logger.debug("Starting: get_rebalancing_job_status.")
# Parallel migrations can take a huge time and create a higher load, if not defined by an
# operator we will use a sequential mode by default
if not proxlb_data["meta"]["balancing"].get("parallel", False):
job = proxmox_api.nodes(guest_current_node).tasks(job_id).status().get()
job = proxmox_api.nodes(guest_current_node).tasks(job_id).status().get()
# Watch job id until it finalizes
if job["status"] == "running":
# Do not hammer the API while
# watching the job status
time.sleep(10)
retry_counter += 1
# Watch job id until it finalizes
if job["status"] == "running":
# Do not hammer the API while
# watching the job status
time.sleep(10)
retry_counter += 1
# Run recursion until we hit the soft-limit of maximum migration time for a guest
if retry_counter < proxlb_data["meta"]["balancing"].get("max_job_validation", 1800):
logger.debug(f"Balancing: Job ID {job_id} (guest: {guest_name}) for migration is still running... (Run: {retry_counter})")
self.get_rebalancing_job_status(proxmox_api, proxlb_data, guest_name, guest_current_node, job_id, retry_counter)
else:
logger.warning(f"Balancing: Job ID {job_id} (guest: {guest_name}) for migration took too long. Please check manually.")
logger.debug("Finished: get_rebalancing_job_status.")
return False
# Run recursion until we hit the soft-limit of maximum migration time for a guest
if retry_counter < proxlb_data["meta"]["balancing"].get("max_job_validation", 1800):
logger.debug(f"Balancing: Job ID {job_id} (guest: {guest_name}) for migration is still running... (Run: {retry_counter})")
self.get_rebalancing_job_status(proxmox_api, proxlb_data, guest_name, guest_current_node, job_id, retry_counter)
else:
logger.warning(f"Balancing: Job ID {job_id} (guest: {guest_name}) for migration took too long. Please check manually.")
logger.debug("Finished: get_rebalancing_job_status.")
return False
# Validate job output for errors when finished
if job["status"] == "stopped":
# Validate job output for errors when finished
if job["status"] == "stopped":
if job["exitstatus"] == "OK":
logger.debug(f"Balancing: Job ID {job_id} (guest: {guest_name}) was sucessfully.")
logger.debug("Finished: get_rebalancing_job_status.")
return True
else:
logger.critical(f"Balancing: Job ID {job_id} (guest: {guest_name}) went into an error! Please check manually.")
logger.debug("Finished: get_rebalancing_job_status.")
return False
if job["exitstatus"] == "OK":
logger.debug(f"Balancing: Job ID {job_id} (guest: {guest_name}) was successfully.")
logger.debug("Finished: get_rebalancing_job_status.")
return True
else:
logger.critical(f"Balancing: Job ID {job_id} (guest: {guest_name}) went into an error! Please check manually.")
logger.debug("Finished: get_rebalancing_job_status.")
return False

View File

@@ -66,7 +66,7 @@ class Calculations:
@staticmethod
def set_node_assignments(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
"""
Set the assigned ressources of the nodes based on the current assigned
Set the assigned resources of the nodes based on the current assigned
guest resources by their created groups as an initial base.
Args:
@@ -82,6 +82,7 @@ class Calculations:
guest_node_current = proxlb_data["guests"][guest_name]["node_current"]
# Update Hardware assignments
# Update assigned values for the current node
logger.debug(f"set_node_assignment of guest {guest_name} on node {guest_node_current} with cpu_total: {proxlb_data['guests'][guest_name]['cpu_total']}, memory_total: {proxlb_data['guests'][guest_name]['memory_total']}, disk_total: {proxlb_data['guests'][guest_name]['disk_total']}.")
proxlb_data["nodes"][guest_node_current]["cpu_assigned"] += proxlb_data["guests"][guest_name]["cpu_total"]
proxlb_data["nodes"][guest_node_current]["memory_assigned"] += proxlb_data["guests"][guest_name]["memory_total"]
proxlb_data["nodes"][guest_node_current]["disk_assigned"] += proxlb_data["guests"][guest_name]["disk_total"]
@@ -119,10 +120,8 @@ class Calculations:
if method_value_highest - method_value_lowest > balanciness:
proxlb_data["meta"]["balancing"]["balance"] = True
logger.debug(f"Guest balancing is required. Highest value: {method_value_highest}, lowest value: {method_value_lowest} balanced by {method} and {mode}.")
logger.critical(f"Guest balancing is required. Highest value: {method_value_highest}, lowest value: {method_value_lowest} balanced by {method} and {mode}.")
else:
logger.debug(f"Guest balancing is ok. Highest value: {method_value_highest}, lowest value: {method_value_lowest} balanced by {method} and {mode}.")
logger.critical(f"Guest balancing is ok. Highest value: {method_value_highest}, lowest value: {method_value_lowest} balanced by {method} and {mode}.")
else:
logger.warning("No guests for balancing found.")
@@ -130,7 +129,7 @@ class Calculations:
logger.debug("Finished: get_balanciness.")
@staticmethod
def get_most_free_node(proxlb_data: Dict[str, Any], return_node: bool = False) -> Dict[str, Any]:
def get_most_free_node(proxlb_data: Dict[str, Any], return_node: bool = False, guest_node_relation_list: list = []) -> Dict[str, Any]:
"""
Get the name of the Proxmox node in the cluster with the most free resources based on
the user defined method (e.g.: memory) and mode (e.g.: used).
@@ -139,6 +138,8 @@ class Calculations:
proxlb_data (Dict[str, Any]): The data holding all content of all objects.
return_node (bool): The indicator to simply return the best node for further
assignments.
guest_node_relation_list (list): A list of nodes that have a tag on the given
guest relationship for pinning.
Returns:
Dict[str, Any]: Updated meta data section of the node with the most free resources that should
@@ -147,9 +148,18 @@ class Calculations:
logger.debug("Starting: get_most_free_node.")
proxlb_data["meta"]["balancing"]["balance_next_node"] = ""
# Do not include nodes that are marked in 'maintenance'
# Filter and exclude nodes that are in maintenance mode
filtered_nodes = [node for node in proxlb_data["nodes"].values() if not node["maintenance"]]
lowest_usage_node = min(filtered_nodes, key=lambda x: x["memory_used_percent"])
# Filter and include nodes that given by a relationship between guest and node. This is only
# used if the guest has a relationship to a node defined by "pin" tags.
if len(guest_node_relation_list) > 0:
filtered_nodes = [node for node in proxlb_data["nodes"].values() if node["name"] in guest_node_relation_list]
# Filter by the defined methods and modes for balancing
method = proxlb_data["meta"]["balancing"].get("method", "memory")
mode = proxlb_data["meta"]["balancing"].get("mode", "used")
lowest_usage_node = min(filtered_nodes, key=lambda x: x[f"{method}_{mode}_percent"])
proxlb_data["meta"]["balancing"]["balance_reason"] = 'resources'
proxlb_data["meta"]["balancing"]["balance_next_node"] = lowest_usage_node["name"]
@@ -207,13 +217,13 @@ class Calculations:
None
"""
logger.debug("Starting: relocate_guests.")
if proxlb_data["meta"]["balancing"]["balance"] or proxlb_data["meta"]["balancing"]["enforce_affinity"]:
if proxlb_data["meta"]["balancing"]["balance"] or proxlb_data["meta"]["balancing"].get("enforce_affinity", False):
if proxlb_data["meta"]["balancing"].get("balance", False):
logger.debug("Balancing of guests will be performt. Reason: balanciness")
logger.debug("Balancing of guests will be performed. Reason: balanciness")
if proxlb_data["meta"]["balancing"].get("enforce_affinity", False):
logger.debug("Balancing of guests will be performt. Reason: enforce affinity balancing")
logger.debug("Balancing of guests will be performed. Reason: enforce affinity balancing")
for group_name in proxlb_data["groups"]["affinity"]:
@@ -225,6 +235,7 @@ class Calculations:
for guest_name in proxlb_data["groups"]["affinity"][group_name]["guests"]:
proxlb_data["meta"]["balancing"]["balance_next_guest"] = guest_name
Calculations.val_anti_affinity(proxlb_data, guest_name)
Calculations.val_node_relationships(proxlb_data, guest_name)
Calculations.update_node_resources(proxlb_data)
logger.debug("Finished: relocate_guests.")
@@ -248,36 +259,74 @@ class Calculations:
None
"""
logger.debug("Starting: val_anti_affinity.")
# Start by interating over all defined anti-affinity groups
# Start by iterating over all defined anti-affinity groups
for group_name in proxlb_data["groups"]["anti_affinity"].keys():
# Validate if the provided guest ist included in the anti-affinity group
# Validate if the provided guest is included in the anti-affinity group
if guest_name in proxlb_data["groups"]["anti_affinity"][group_name]['guests'] and not proxlb_data["guests"][guest_name]["processed"]:
logger.debug(f"Anti-Affinity: Guest: {guest_name} is included in anti-affinity group: {group_name}.")
# Iterate over all available nodes
for node_name in proxlb_data["nodes"].keys():
# Check if the group has only one member. If so skip new guest node assignment.
if proxlb_data["groups"]["anti_affinity"][group_name]["counter"] > 1:
logger.debug(f"Anti-Affinity: Group has more than 1 member.")
# Iterate over all available nodes
for node_name in proxlb_data["nodes"].keys():
# Only select node if it was not used before and is not in a
# maintenance mode. Afterwards, add it to the list of already
# used nodes for the current anti-affinity group
if node_name not in proxlb_data["groups"]["anti_affinity"][group_name]["used_nodes"]:
# Only select node if it was not used before and is not in a
# maintenance mode. Afterwards, add it to the list of already
# used nodes for the current anti-affinity group
if node_name not in proxlb_data["groups"]["anti_affinity"][group_name]["used_nodes"]:
if not proxlb_data["nodes"][node_name]["maintenance"]:
# If the node has not been used yet, we assign this node to the guest
proxlb_data["meta"]["balancing"]["balance_next_node"] = node_name
proxlb_data["groups"]["anti_affinity"][group_name]["used_nodes"].append(node_name)
logger.debug(f"Node: {node_name} marked as used for anti-affinity group: {group_name} with guest {guest_name}")
break
if not proxlb_data["nodes"][node_name]["maintenance"]:
# If the node has not been used yet, we assign this node to the guest
proxlb_data["meta"]["balancing"]["balance_next_node"] = node_name
proxlb_data["groups"]["anti_affinity"][group_name]["used_nodes"].append(node_name)
logger.debug(f"Node: {node_name} marked as used for anti-affinity group: {group_name} with guest {guest_name}")
break
else:
logger.critical(f"Node: {node_name} already got used for anti-affinity group:: {group_name}. (Tried for guest: {guest_name})")
else:
logger.critical(f"Node: {node_name} already got used for anti-affinity group:: {group_name}. (Tried for guest: {guest_name})")
else:
logger.debug(f"Anti-Affinity: Group has less than 2 members. Skipping node calculation for the group.")
else:
logger.debug(f"Guest: {guest_name} is not included in anti-affinity group: {group_name}. Skipping.")
logger.debug("Finished: val_anti_affinity.")
@staticmethod
def val_node_relationships(proxlb_data: Dict[str, Any], guest_name: str):
"""
Validates and assigns guests to nodes based on defined relationships based on tags.
Parameters:
proxlb_data (Dict[str, Any]): The data holding all content of all objects.
guest_name (str): The name of the guest to be validated and assigned a node.
Returns:
None
"""
logger.debug("Starting: val_node_relationships.")
proxlb_data["guests"][guest_name]["processed"] = True
if len(proxlb_data["guests"][guest_name]["node_relationships"]) > 0:
logger.debug(f"Guest '{guest_name}' has relationships defined to node(s): {','.join(proxlb_data['guests'][guest_name]['node_relationships'])}. Pinning to node.")
# Get the node with the most free resources of the group
guest_node_relation_list = proxlb_data["guests"][guest_name]["node_relationships"]
Calculations.get_most_free_node(proxlb_data, False, guest_node_relation_list)
# Validate if the specified node name is really part of the cluster
if proxlb_data["meta"]["balancing"]["balance_next_node"] in proxlb_data["nodes"].keys():
logger.debug(f"Guest '{guest_name}' has a specific relationship defined to node: {proxlb_data['meta']['balancing']['balance_next_node']} is a known hypervisor node in the cluster.")
else:
logger.warning(f"Guest '{guest_name}' has a specific relationship defined to node: {proxlb_data['meta']['balancing']['balance_next_node']} but this node name is not known in the cluster!")
else:
logger.debug(f"Guest '{guest_name}' does not have any specific node relationships.")
logger.debug("Finished: val_node_relationships.")
@staticmethod
def update_node_resources(proxlb_data):
"""

View File

@@ -11,6 +11,7 @@ __license__ = "GPL-3.0"
from typing import Dict, Any
from utils.logger import SystemdLogger
from models.tags import Tags
import time
logger = SystemdLogger()
@@ -34,7 +35,7 @@ class Guests:
"""
@staticmethod
def get_guests(proxmox_api: any, nodes: Dict[str, Any]) -> Dict[str, Any]:
def get_guests(proxmox_api: any, nodes: Dict[str, Any], meta: Dict[str, Any]) -> Dict[str, Any]:
"""
Get metrics of all guests in a Proxmox cluster.
@@ -61,10 +62,11 @@ class Guests:
# resource metrics for rebalancing to ensure that we do not overprovisiong the node.
for guest in proxmox_api.nodes(node).qemu.get():
if guest['status'] == 'running':
guests['guests'][guest['name']] = {}
guests['guests'][guest['name']]['name'] = guest['name']
guests['guests'][guest['name']]['cpu_total'] = guest['cpus']
guests['guests'][guest['name']]['cpu_used'] = guest['cpu']
guests['guests'][guest['name']]['cpu_total'] = int(guest['cpus'])
guests['guests'][guest['name']]['cpu_used'] = Guests.get_guest_cpu_usage(proxmox_api, node, guest['vmid'], guest['name'])
guests['guests'][guest['name']]['memory_total'] = guest['maxmem']
guests['guests'][guest['name']]['memory_used'] = guest['mem']
guests['guests'][guest['name']]['disk_total'] = guest['maxdisk']
@@ -77,7 +79,10 @@ class Guests:
guests['guests'][guest['name']]['affinity_groups'] = Tags.get_affinity_groups(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['ignore'] = Tags.get_ignore(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['node_relationships'] = Tags.get_node_relationships(guests['guests'][guest['name']]['tags'], nodes)
guests['guests'][guest['name']]['type'] = 'vm'
logger.debug(f"Resources of Guest {guest['name']} (type VM) added: {guests['guests'][guest['name']]}")
else:
logger.debug(f'Metric for VM {guest["name"]} ignored because VM is not running.')
@@ -88,8 +93,8 @@ class Guests:
if guest['status'] == 'running':
guests['guests'][guest['name']] = {}
guests['guests'][guest['name']]['name'] = guest['name']
guests['guests'][guest['name']]['cpu_total'] = guest['cpus']
guests['guests'][guest['name']]['cpu_used'] = guest['cpu']
guests['guests'][guest['name']]['cpu_total'] = int(guest['cpus'])
guests['guests'][guest['name']]['cpu_used'] = Guests.get_guest_cpu_usage(proxmox_api, node, guest['vmid'], guest['name'])
guests['guests'][guest['name']]['memory_total'] = guest['maxmem']
guests['guests'][guest['name']]['memory_used'] = guest['mem']
guests['guests'][guest['name']]['disk_total'] = guest['maxdisk']
@@ -102,9 +107,47 @@ class Guests:
guests['guests'][guest['name']]['affinity_groups'] = Tags.get_affinity_groups(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['ignore'] = Tags.get_ignore(guests['guests'][guest['name']]['tags'])
guests['guests'][guest['name']]['node_relationships'] = Tags.get_node_relationships(guests['guests'][guest['name']]['tags'], nodes)
guests['guests'][guest['name']]['type'] = 'ct'
logger.debug(f"Resources of Guest {guest['name']} (type CT) added: {guests['guests'][guest['name']]}")
else:
logger.debug(f'Metric for CT {guest["name"]} ignored because CT is not running.')
logger.debug("Finished: get_guests.")
return guests
@staticmethod
def get_guest_cpu_usage(proxmox_api, node_name: str, vm_id: int, vm_name: str) -> float:
"""
Retrieve the average CPU usage of a guest instance (VM/CT) over the past hour.
This method queries the Proxmox VE API for RRD (Round-Robin Database) data
related to CPU usage of a specific guest instance and calculates the average CPU usage
over the last hour using the "AVERAGE" consolidation function.
Args:
proxmox_api: An instance of the Proxmox API client.
node_name (str): The name of the Proxmox node hosting the VM.
vm_id (int): The unique identifier of the guest instance (VM/CT).
vm_name (str): The name of the guest instance (VM/CT).
Returns:
float: The average CPU usage as a fraction (0.0 to 1.0) over the past hour.
Returns 0.0 if no data is available.
"""
logger.debug("Finished: get_guest_cpu_usage.")
time.sleep(0.1)
try:
logger.debug(f"Getting RRD dara for guest: {vm_name}.")
guest_data_rrd = proxmox_api.nodes(node_name).qemu(vm_id).rrddata.get(timeframe="hour", cf="AVERAGE")
except Exception:
logger.error(f"Failed to retrieve RRD data for guest: {vm_name} (ID: {vm_id}) on node: {node_name}. Using 0.0 as CPU usage.")
logger.debug("Finished: get_guest_cpu_usage.")
return 0.0
cpu_usage = sum(entry.get("cpu", 0.0) for entry in guest_data_rrd) / len(guest_data_rrd)
logger.debug(f"CPU RRD data for guest: {vm_name}: {cpu_usage}")
logger.debug("Finished: get_guest_cpu_usage.")
return cpu_usage

View File

@@ -63,7 +63,7 @@ class Nodes:
nodes["nodes"][node["node"]]["maintenance"] = False
nodes["nodes"][node["node"]]["cpu_total"] = node["maxcpu"]
nodes["nodes"][node["node"]]["cpu_assigned"] = 0
nodes["nodes"][node["node"]]["cpu_used"] = node["cpu"]
nodes["nodes"][node["node"]]["cpu_used"] = node["cpu"] * node["maxcpu"]
nodes["nodes"][node["node"]]["cpu_free"] = (node["maxcpu"]) - (node["cpu"] * node["maxcpu"])
nodes["nodes"][node["node"]]["cpu_assigned_percent"] = nodes["nodes"][node["node"]]["cpu_assigned"] / nodes["nodes"][node["node"]]["cpu_total"] * 100
nodes["nodes"][node["node"]]["cpu_free_percent"] = nodes["nodes"][node["node"]]["cpu_free"] / node["maxcpu"] * 100
@@ -84,14 +84,14 @@ class Nodes:
nodes["nodes"][node["node"]]["disk_used_percent"] = nodes["nodes"][node["node"]]["disk_used"] / node["maxdisk"] * 100
# Evaluate if node should be set to maintenance mode
if Nodes.set_node_maintenance(proxlb_config, node["node"]):
if Nodes.set_node_maintenance(proxmox_api, proxlb_config, node["node"]):
nodes["nodes"][node["node"]]["maintenance"] = True
logger.debug("Finished: get_nodes.")
return nodes
@staticmethod
def set_node_maintenance(proxlb_config: Dict[str, Any], node_name: str) -> Dict[str, Any]:
def set_node_maintenance(proxmox_api, proxlb_config: Dict[str, Any], node_name: str) -> Dict[str, Any]:
"""
Set nodes to maintenance mode based on the provided configuration.
@@ -99,6 +99,7 @@ class Nodes:
based on the configuration provided in proxlb_config.
Args:
proxmox_api (any): The Proxmox API client instance.
proxlb_config (Dict[str, Any]): A dictionary containing the ProxLB configuration, including maintenance nodes.
node_name: (str): The current node name within the outer iteration.
@@ -107,11 +108,24 @@ class Nodes:
"""
logger.debug("Starting: set_node_maintenance.")
# Evaluate maintenance mode by config
if proxlb_config.get("proxmox_cluster", None).get("maintenance_nodes", None) is not None:
if len(proxlb_config.get("proxmox_cluster", {}).get("maintenance_nodes", [])) > 0:
if node_name in proxlb_config.get("proxmox_cluster", {}).get("maintenance_nodes", []):
logger.warning(f"Node: {node_name} has been set to maintenance mode.")
logger.info(f"Node: {node_name} has been set to maintenance mode (by ProxLB config).")
return True
else:
logger.debug(f"Node: {node_name} is not in maintenance mode by ProxLB config.")
# Evaluate maintenance mode by Proxmox HA
for ha_element in proxmox_api.cluster.ha.status.current.get():
if ha_element.get("status"):
if "maintenance mode" in ha_element.get("status"):
if ha_element.get("node") == node_name:
logger.info(f"Node: {node_name} has been set to maintenance mode (by Proxmox HA API).")
return True
else:
logger.debug(f"Node: {node_name} is not in maintenance mode by Proxmox HA API.")
logger.debug("Finished: set_node_maintenance.")
@@ -135,7 +149,7 @@ class Nodes:
if proxlb_config.get("proxmox_cluster", None).get("ignore_nodes", None) is not None:
if len(proxlb_config.get("proxmox_cluster", {}).get("ignore_nodes", [])) > 0:
if node_name in proxlb_config.get("proxmox_cluster", {}).get("ignore_nodes", []):
logger.warning(f"Node: {node_name} has been set to be ignored. Not adding node!")
logger.info(f"Node: {node_name} has been set to be ignored. Not adding node!")
return True
logger.debug("Finished: set_node_ignore.")

View File

@@ -12,7 +12,9 @@ __license__ = "GPL-3.0"
import time
from typing import List
from typing import Dict, Any
from utils.logger import SystemdLogger
from utils.helper import Helper
logger = SystemdLogger()
@@ -139,7 +141,7 @@ class Tags:
tags (List): A list holding all defined tags for a given guest.
Returns:
Bool: Returns a bool that indicates wether to ignore a guest or not.
Bool: Returns a bool that indicates whether to ignore a guest or not.
"""
logger.debug("Starting: get_ignore.")
ignore_tag = False
@@ -151,3 +153,37 @@ class Tags:
logger.debug("Finished: get_ignore.")
return ignore_tag
@staticmethod
def get_node_relationships(tags: List[str], nodes: Dict[str, Any]) -> str:
"""
Get a node relationship tag for a guest from the Proxmox cluster by the API to pin
a guest to a node.
This method retrieves a relationship tag between a guest and a specific
hypervisor node to pin the guest to a specific node (e.g., for licensing reason).
Args:
tags (List): A list holding all defined tags for a given guest.
nodes (Dict): A dictionary holding all available nodes in the cluster.
Returns:
Str: The related hypervisor node name.
"""
logger.debug("Starting: get_node_relationships.")
node_relationship_tags = []
if len(tags) > 0:
for tag in tags:
if tag.startswith("plb_pin"):
node_relationship_tag = tag.replace("plb_pin_", "")
# Validate if the node to pin is present in the cluster
if Helper.validate_node_presence(node_relationship_tag, nodes):
logger.info(f"Tag {node_relationship_tag} is valid! Defined node exists in the cluster.")
node_relationship_tags.append(node_relationship_tag)
else:
logger.warning(f"Tag {node_relationship_tag} is invalid! Defined node does not exist in the cluster. Not applying pinning.")
logger.debug("Finished: get_node_relationships.")
return node_relationship_tags

View File

@@ -8,12 +8,15 @@ __copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
__license__ = "GPL-3.0"
import json
import uuid
import re
import sys
import time
import utils.version
from utils.logger import SystemdLogger
from typing import Dict, Any
from types import FrameType
logger = SystemdLogger()
@@ -39,6 +42,8 @@ class Helper:
get_daemon_mode(proxlb_config: Dict[str, Any]) -> None:
Checks if the daemon mode is active and handles the scheduling accordingly.
"""
proxlb_reload = False
def __init__(self):
"""
Initializes the general Helper clas.
@@ -115,12 +120,190 @@ class Helper:
None
"""
logger.debug("Starting: get_daemon_mode.")
if proxlb_config.get("service", {}).get("daemon", False):
sleep_seconds = proxlb_config.get("service", {}).get("schedule", 12) * 3600
logger.info(f"Daemon mode active: Next run in: {proxlb_config.get('service', {}).get('schedule', 12)} hours.")
if proxlb_config.get("service", {}).get("daemon", True):
# Validate schedule format which changed in v1.1.1
if type(proxlb_config["service"].get("schedule", None)) != dict:
logger.error("Invalid format for schedule. Please use 'hours' or 'minutes'.")
sys.exit(1)
# Convert hours to seconds
if proxlb_config["service"]["schedule"].get("format", "hours") == "hours":
sleep_seconds = proxlb_config.get("service", {}).get("schedule", {}).get("interval", 12) * 3600
# Convert minutes to seconds
elif proxlb_config["service"]["schedule"].get("format", "hours") == "minutes":
sleep_seconds = proxlb_config.get("service", {}).get("schedule", {}).get("interval", 720) * 60
else:
logger.error("Invalid format for schedule. Please use 'hours' or 'minutes'.")
sys.exit(1)
logger.info(f"Daemon mode active: Next run in: {proxlb_config.get('service', {}).get('schedule', {}).get('interval', 12)} {proxlb_config['service']['schedule'].get('format', 'hours')}.")
time.sleep(sleep_seconds)
else:
logger.debug("Daemon mode is not active.")
logger.debug("Successfully executed ProxLB. Daemon mode not active - stopping.")
print("Daemon mode not active - stopping.")
sys.exit(0)
logger.debug("Finished: get_daemon_mode.")
@staticmethod
def get_service_delay(proxlb_config: Dict[str, Any]) -> None:
"""
Checks if a start up delay for the service is defined and waits to proceed until
the time is up.
Parameters:
proxlb_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
Returns:
None
"""
logger.debug("Starting: get_service_delay.")
if proxlb_config.get("service", {}).get("delay", {}).get("enable", False):
# Convert hours to seconds
if proxlb_config["service"]["delay"].get("format", "hours") == "hours":
sleep_seconds = proxlb_config.get("service", {}).get("delay", {}).get("time", 1) * 3600
# Convert minutes to seconds
elif proxlb_config["service"]["delay"].get("format", "hours") == "minutes":
sleep_seconds = proxlb_config.get("service", {}).get("delay", {}).get("time", 60) * 60
else:
logger.error("Invalid format for service delay. Please use 'hours' or 'minutes'.")
sys.exit(1)
logger.info(f"Service delay active: First run in: {proxlb_config.get('service', {}).get('delay', {}).get('time', 1)} {proxlb_config['service']['delay'].get('format', 'hours')}.")
time.sleep(sleep_seconds)
else:
logger.debug("Service delay not active. Proceeding without delay.")
logger.debug("Finished: get_service_delay.")
@staticmethod
def print_json(proxlb_config: Dict[str, Any], print_json: bool = False) -> None:
"""
Prints the calculated balancing matrix as a JSON output to stdout.
Parameters:
proxlb_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
Returns:
None
"""
logger.debug("Starting: print_json.")
if print_json:
# Create a filtered list by stripping the 'meta' key from the proxlb_config dictionary
# to make sure that no credentials are leaked.
filtered_data = {k: v for k, v in proxlb_config.items() if k != "meta"}
print(json.dumps(filtered_data, indent=4))
logger.debug("Finished: print_json.")
@staticmethod
def handler_sighup(signum: int, frame: FrameType) -> None:
"""
Signal handler for SIGHUP.
This method is triggered when the process receives a SIGHUP signal.
It sets the `proxlb_reload` class variable to True to indicate that
configuration should be reloaded in the main loop.
Args:
signum (int): The signal number (expected to be signal.SIGHUP).
frame (frame object): Current stack frame (unused but required by signal handler signature).
"""
logger.debug("Starting: handle_sighup.")
logger.debug("Got SIGHUP signal. Reloading...")
Helper.proxlb_reload = True
logger.debug("Finished: handle_sighup.")
@staticmethod
def handler_sigint(signum: int, frame: FrameType) -> None:
"""
Signal handler for SIGINT. (triggered by CTRL+C).
Args:
signum (int): The signal number (e.g., SIGINT).
frame (FrameType): The current stack frame when the signal was received.
Returns:
None
"""
exit_message = "ProxLB has been successfully terminated by user."
logger.debug(exit_message)
print(f"\n {exit_message}")
sys.exit(0)
@staticmethod
def get_host_port_from_string(host_object):
"""
Parses a string containing a host (IPv4, IPv6, or hostname) and an optional port, and returns a tuple of (host, port).
Supported formats:
- Hostname or IPv4 without port: "example.com" or "192.168.0.1"
- Hostname or IPv4 with port: "example.com:8006" or "192.168.0.1:8006"
- IPv6 in brackets with optional port: "[fc00::1]" or "[fc00::1]:8006"
- IPv6 without brackets, port is assumed after last colon: "fc00::1:8006"
If no port is specified, port 8006 is used as the default.
Args:
host_object (str): A string representing a host with or without a port.
Returns:
tuple: A tuple (host: str, port: int)
"""
logger.debug("Starting: get_host_port_from_string.")
# IPv6 (with or without port, written in brackets)
match = re.match(r'^\[(.+)\](?::(\d+))?$', host_object)
if match:
host = match.group(1)
port = int(match.group(2)) if match.group(2) else 8006
return host, port
# Count colons to identify IPv6 addresses without brackets
colon_count = host_object.count(':')
# IPv4 or hostname without port
if colon_count == 0:
return host_object, 8006
# IPv4 or hostname with port
elif colon_count == 1:
host, port = host_object.split(':')
return host, int(port)
# IPv6 (with or without port, assume last colon is port)
else:
parts = host_object.rsplit(':', 1)
try:
port = int(parts[1])
return parts[0], port
except ValueError:
return host_object, 8006
@staticmethod
def validate_node_presence(node: str, nodes: Dict[str, Any]) -> bool:
"""
Validates whether a given node exists in the provided cluster nodes dictionary.
Args:
node (str): The name of the node to validate.
nodes (Dict[str, Any]): A dictionary containing cluster information.
Must include a "nodes" key mapping to a dict of available nodes.
Returns:
bool: True if the node exists in the cluster, False otherwise.
"""
logger.debug("Starting: validate_node_presence.")
if node in nodes["nodes"].keys():
logger.info(f"Node {node} found in cluster. Applying pinning.")
logger.debug("Finished: validate_node_presence.")
return True
else:
logger.warning(f"Node {node} not found in cluster. Not applying pinning!")
logger.debug("Finished: validate_node_presence.")
return False

View File

@@ -9,6 +9,7 @@ __license__ = "GPL-3.0"
import logging
import sys
try:
from systemd.journal import JournalHandler
SYSTEMD_PRESENT = True
@@ -82,17 +83,22 @@ class SystemdLogger:
self.logger = logging.getLogger(name)
self.logger.setLevel(level)
# Create a JournalHandler for systemd integration if this
# is supported on the underlying OS.
# Create a logging handler depending on the
# capabilities of the underlying OS where systemd
# logging is preferred.
if SYSTEMD_PRESENT:
# Add a JournalHandler for systemd integration
journal_handler = JournalHandler()
journal_handler.setLevel(level)
# Set a formatter to include the logger's name and log message
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
journal_handler.setFormatter(formatter)
# Add handler to logger
self.logger.addHandler(journal_handler)
handler = JournalHandler()
else:
# Add a stdout handler as a fallback
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(level)
# Set a formatter to include the logger's name and log message
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# Add handler to logger
self.logger.addHandler(handler)
def set_log_level(self, level: str) -> None:
"""

View File

@@ -20,18 +20,20 @@ except ImportError:
PROXMOXER_PRESENT = False
import random
import socket
import sys
try:
import requests
REQUESTS_PRESENT = True
except ImportError:
REQUESTS_PRESENT = False
import sys
import time
try:
import urllib3
URLLIB3_PRESENT = True
except ImportError:
URLLIB3_PRESENT = False
from typing import Dict, Any
from utils.helper import Helper
from utils.logger import SystemdLogger
@@ -94,6 +96,7 @@ class ProxmoxApi:
"""
logger.debug("Starting: ProxmoxApi initialization.")
self.proxmox_api = self.api_connect(proxlb_config)
self.test_api_user_permissions(self.proxmox_api)
logger.debug("Finished: ProxmoxApi initialization.")
def __getattr__(self, name):
@@ -115,7 +118,7 @@ class ProxmoxApi:
"token_id" and "token_secret" keys for API token authentication.
Raises:
SystemExit: If both username/password and API token authentication methods are
SystemExit: If both pass/token_secret and API token authentication methods are
provided, the function will log a critical error message and terminate
the program.
@@ -130,17 +133,25 @@ class ProxmoxApi:
sys.exit(1)
proxlb_credentials = proxlb_config["proxmox_api"]
present_auth_user = "user" in proxlb_credentials
present_auth_token = "token_id" in proxlb_credentials
present_auth_pass = "pass" in proxlb_credentials
present_auth_secret = "token_secret" in proxlb_credentials
token_id = proxlb_credentials.get("token_id", None)
if present_auth_user and present_auth_token:
if token_id:
non_allowed_chars = ["@", "!"]
for char in non_allowed_chars:
if char in token_id:
logger.error(f"Wrong user/token format defined. User and token id must be splitted! Please see: https://github.com/gyptazy/ProxLB/blob/main/docs/03_configuration.md#required-permissions-for-a-user")
sys.exit(1)
if present_auth_pass and present_auth_secret:
logger.critical(f"Username/password and API token authentication are mutal exclusive. Please use only one!")
print(f"Username/password and API token authentication are mutal exclusive. Please use only one!")
sys.exit(1)
logger.debug("Finished: validate_config.")
def api_connect_get_hosts(self, proxmox_api_endpoints: list) -> str:
def api_connect_get_hosts(self, proxlb_config, proxmox_api_endpoints: list) -> str:
"""
Perform a connectivity test to determine a working host for the Proxmox API.
@@ -151,6 +162,7 @@ class ProxmoxApi:
are found, one is chosen at random to distribute the load across the cluster.
Args:
proxlb_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
proxmox_api_endpoints (list): A list of Proxmox API endpoints to test.
Returns:
@@ -174,26 +186,30 @@ class ProxmoxApi:
logger.critical(f"No proxmox_api hosts are defined.")
sys.exit(1)
# Get a suitable Proxmox API endpoint. Therefore, we check if we only have
# a single Proxmox API endpoint or multiple ones. If only one, we can return
# this one immediately. If this one does not work, the urllib will raise an
# exception during the connection attempt.
if len(proxmox_api_endpoints) == 1:
return proxmox_api_endpoints[0]
# If we have multiple Proxmox API endpoints, we need to check each one by
# doing a connection attempt for IPv4 and IPv6. If we find a working one,
# we return that one. This allows us to define multiple endpoints in a cluster.
validated_api_hosts = []
for host in proxmox_api_endpoints:
validated = self.test_api_proxmox_host(host)
if validated:
validated_api_hosts.append(validated)
# Get or set a default value for a maximum of retries when connecting to
# the Proxmox API
api_connection_retries = proxlb_config["proxmox_api"].get("retries", 1)
api_connection_wait_time = proxlb_config["proxmox_api"].get("wait_time", 1)
for api_connection_attempt in range(api_connection_retries):
validated_api_host, api_port = self.test_api_proxmox_host(host)
if validated_api_host:
validated_api_hosts.append(validated_api_host)
break
else:
logger.warning(f"Attempt {api_connection_attempt + 1}/{api_connection_retries} failed for host {host}. Retrying in {api_connection_wait_time} seconds...")
time.sleep(api_connection_wait_time)
if len(validated_api_hosts) > 0:
# Choose a random host to distribute the load across the cluster
# as a simple load balancing mechanism.
return random.choice(validated_api_hosts)
return random.choice(validated_api_hosts), api_port
logger.critical("No valid Proxmox API hosts found.")
print("No valid Proxmox API hosts found.")
@@ -221,6 +237,10 @@ class ProxmoxApi:
"""
logger.debug("Starting: test_api_proxmox_host.")
# Validate for custom ports in API hosts which might indicate
# that an external loadbalancer will be used.
host, port = Helper.get_host_port_from_string(host)
# Try resolving DNS to IP and log non-resolvable ones
try:
ip = socket.getaddrinfo(host, None, socket.AF_UNSPEC)
@@ -232,12 +252,12 @@ class ProxmoxApi:
for address_type in ip:
if address_type[0] == socket.AF_INET:
logger.debug(f"{host} is type ipv4.")
if self.test_api_proxmox_host_ipv4(host):
return host
if self.test_api_proxmox_host_ipv4(host, port):
return host, port
elif address_type[0] == socket.AF_INET6:
logger.debug(f"{host} is type ipv6.")
if self.test_api_proxmox_host_ipv6(host):
return host
if self.test_api_proxmox_host_ipv6(host, port):
return host, port
else:
return False
@@ -262,7 +282,7 @@ class ProxmoxApi:
logger.debug("Starting: test_api_proxmox_host_ipv4.")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
logger.warning(f"Warning: Host {host} ran into a timout when connectoing on IPv4 for tcp/{port}.")
logger.warning(f"Warning: Host {host} ran into a timeout when connecting on IPv4 for tcp/{port}.")
result = sock.connect_ex((host, port))
if result == 0:
@@ -295,7 +315,7 @@ class ProxmoxApi:
logger.debug("Starting: test_api_proxmox_host_ipv6.")
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.settimeout(timeout)
logger.warning(f"Host {host} ran into a timout when connectoing on IPv6 for tcp/{port}.")
logger.warning(f"Host {host} ran into a timeout when connecting via IPv6 for tcp/{port}.")
result = sock.connect_ex((host, port))
if result == 0:
@@ -306,9 +326,47 @@ class ProxmoxApi:
sock.close()
logger.warning(f"Host {host} is unreachable on IPv6 for tcp/{port}.")
logger.debug("Finished: test_api_proxmox_host_ipv4.")
logger.debug("Finished: test_api_proxmox_host_ipv6.")
return False
def test_api_user_permissions(self, proxmox_api: any):
"""
Test the permissions of the current user/token used for the Proxmox API.
This method gets all assigned permissions for all API paths for the current
used user/token and validates them against the minimum required permissions.
Args:
proxmox_api (any): The Proxmox API client instance.
"""
logger.debug("Starting: test_api_user_permissions.")
permissions_required = ["Datastore.Audit", "Sys.Audit", "VM.Audit", "VM.Migrate"]
permissions_available = []
# Get the permissions for the current user/token from API
try:
permissions = proxmox_api.access.permissions.get()
except proxmoxer.core.ResourceException as api_error:
if "no such user" in str(api_error):
logger.error("Authentication to Proxmox API not possible: User not known - please check your username and config file.")
sys.exit(1)
else:
logger.error(f"Proxmox API error: {api_error}")
sys.exit(1)
# Get all available permissions of the current user/token
for path, permission in permissions.items():
for permission in permissions[path]:
permissions_available.append(permission)
# Validate if all required permissions are included within the available permissions
for required_permission in permissions_required:
if required_permission not in permissions_available:
logger.critical(f"Permission '{required_permission}' is missing. Please adjust the permissions for your user/token. See also: https://github.com/gyptazy/ProxLB/blob/main/docs/03_configuration.md#required-permissions-for-a-user")
sys.exit(1)
logger.debug("Finished: test_api_user_permissions.")
def api_connect(self, proxlb_config: Dict[str, Any]) -> proxmoxer.ProxmoxAPI:
"""
Establishes a connection to the Proxmox API using the provided configuration.
@@ -341,7 +399,7 @@ class ProxmoxApi:
self.validate_config(proxlb_config)
# Get a valid Proxmox API endpoint
proxmox_api_endpoint = self.api_connect_get_hosts(proxlb_config.get("proxmox_api", {}).get("hosts", []))
proxmox_api_endpoint, proxmox_api_port = self.api_connect_get_hosts(proxlb_config, proxlb_config.get("proxmox_api", {}).get("hosts", []))
# Disable warnings for SSL certificate validation
if not proxlb_config.get("proxmox_api").get("ssl_verification", True):
@@ -355,6 +413,7 @@ class ProxmoxApi:
if proxlb_config.get("proxmox_api").get("token_secret", False):
proxmox_api = proxmoxer.ProxmoxAPI(
proxmox_api_endpoint,
port=proxmox_api_port,
user=proxlb_config.get("proxmox_api").get("user", True),
token_name=proxlb_config.get("proxmox_api").get("token_id", True),
token_value=proxlb_config.get("proxmox_api").get("token_secret", True),
@@ -364,6 +423,7 @@ class ProxmoxApi:
else:
proxmox_api = proxmoxer.ProxmoxAPI(
proxmox_api_endpoint,
port=proxmox_api_port,
user=proxlb_config.get("proxmox_api").get("user", True),
password=proxlb_config.get("proxmox_api").get("pass", True),
verify_ssl=proxlb_config.get("proxmox_api").get("ssl_verification", True),
@@ -383,6 +443,5 @@ class ProxmoxApi:
sys.exit(2)
logger.info(f"API connection to host {proxmox_api_endpoint} succeeded.")
logger.debug("Finished: api_connect.")
return proxmox_api

View File

@@ -3,5 +3,5 @@ __app_desc__ = "A DRS alike loadbalancer for Proxmox clusters."
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
__license__ = "GPL-3.0"
__version__ = "1.1.0-alpha"
__version__ = "1.1.7"
__url__ = "https://github.com/gyptazy/ProxLB"

View File

@@ -1,11 +1,13 @@
[Unit]
Description=ProxLB - A loadbalancer for Proxmox clusters
After=network-online.target
Wants=network-online.target
After=network-online.target pveproxy.service
Wants=network-online.target pveproxy.service
[Service]
ExecStart=python3 /usr/lib/python3/dist-packages/proxlb/main.py -c /etc/proxlb/proxlb.yaml
User=plb
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
WantedBy=multi-user.target

View File

@@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="proxlb",
version="1.1.0-alpha",
version="1.1.7",
description="A DRS alike loadbalancer for Proxmox clusters.",
long_description="An advanced DRS alike loadbalancer for Proxmox clusters that also supports maintenance modes and affinity/anti-affinity rules.",
author="Florian Paul Azim Hoberg",
@@ -10,7 +10,7 @@ setup(
maintainer="Florian Paul Azim Hoberg",
maintainer_email="gyptazy@gyptazy.com",
url="https://github.com/gyptazy/ProxLB",
packages=["proxlb", "proxlb.utils", "proxlb.models", misc/debian],
packages=["proxlb", "proxlb.utils", "proxlb.models"],
install_requires=[
"requests",
"urllib3",