mirror of
https://github.com/gyptazy/ProxLB.git
synced 2026-04-06 04:41:58 +02:00
Compare commits
234 Commits
developmen
...
pipeline/d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48d621a06d | ||
|
|
c133ef1aee | ||
|
|
9ea04f904d | ||
|
|
5101202f72 | ||
|
|
929390b288 | ||
|
|
d4560c3af4 | ||
|
|
55c885194e | ||
|
|
3d9f0eb85e | ||
|
|
490fb55ee1 | ||
|
|
a70330d4c3 | ||
|
|
71d373eedb | ||
|
|
040eeb9f13 | ||
|
|
4ef1e92aad | ||
|
|
7e5fe13dfe | ||
|
|
66c2ab6570 | ||
|
|
ba63514896 | ||
|
|
571025a8a6 | ||
|
|
dd13181cf9 | ||
|
|
37d19a6a2d | ||
|
|
fe333749ce | ||
|
|
8f9bcfcdcf | ||
|
|
ff5fd2f7f1 | ||
|
|
1f6576ecd6 | ||
|
|
46bbe01141 | ||
|
|
07ed12fcb7 | ||
|
|
546fbc7d73 | ||
|
|
15436c431f | ||
|
|
33f6ff8db0 | ||
|
|
84628f232e | ||
|
|
6a91afd405 | ||
|
|
909643a09f | ||
|
|
7de1ba366b | ||
|
|
0cb19fab34 | ||
|
|
972b10b7e5 | ||
|
|
7fa110e465 | ||
|
|
948df0316b | ||
|
|
016378e37c | ||
|
|
8a193b9891 | ||
|
|
30e3b66be9 | ||
|
|
b9be405194 | ||
|
|
ac108f2abe | ||
|
|
02b43d3ef7 | ||
|
|
581d6d480b | ||
|
|
5b395b7f15 | ||
|
|
7d94c52883 | ||
|
|
7d19788be1 | ||
|
|
0bbc5992ca | ||
|
|
a4a5d9e68a | ||
|
|
af98ee8d5b | ||
|
|
afc93f7b21 | ||
|
|
bc6d8c8509 | ||
|
|
6d50f32486 | ||
|
|
5fe49a9dc1 | ||
|
|
fca1d1211c | ||
|
|
36388d9429 | ||
|
|
3f424e9e6d | ||
|
|
44a733aed3 | ||
|
|
2f44ff48a0 | ||
|
|
7b6db9cfdd | ||
|
|
8c473b416c | ||
|
|
51c8afe5c5 | ||
|
|
a8a154abde | ||
|
|
554a3eaf72 | ||
|
|
0b35987403 | ||
|
|
d93048db69 | ||
|
|
2aba7dbe23 | ||
|
|
ba388dfd7c | ||
|
|
5aa8257d40 | ||
|
|
99fefe20bf | ||
|
|
b9fb3a60e1 | ||
|
|
88b3288eb7 | ||
|
|
fa0113f112 | ||
|
|
0039ae9093 | ||
|
|
e3bbf31fdd | ||
|
|
bf393c6bbf | ||
|
|
7e5b72cfc7 | ||
|
|
0ba76f80f3 | ||
|
|
b48ff9d677 | ||
|
|
b5c11af474 | ||
|
|
af2992747d | ||
|
|
fb8dc40c16 | ||
|
|
34f1de8367 | ||
|
|
0e992e99de | ||
|
|
f5d073dc02 | ||
|
|
70ba1f2dfc | ||
|
|
c9855f1991 | ||
|
|
9bd29158b9 | ||
|
|
1ff0c5d96e | ||
|
|
3eb4038723 | ||
|
|
47e7dd3c56 | ||
|
|
bb8cf9033d | ||
|
|
756b4efcbd | ||
|
|
8630333e4b | ||
|
|
7bd9a9b038 | ||
|
|
16651351de | ||
|
|
63805f1f50 | ||
|
|
c0ff1b5273 | ||
|
|
07f8596fc5 | ||
|
|
affbe433f9 | ||
|
|
7bda22e754 | ||
|
|
253dcf8eb9 | ||
|
|
6212d23268 | ||
|
|
cf8c06393f | ||
|
|
5c23fd3433 | ||
|
|
0fb732fc8c | ||
|
|
f36d96c72a | ||
|
|
9cc03717ef | ||
|
|
4848887ccc | ||
|
|
04476feeaf | ||
|
|
b3765bf0ae | ||
|
|
806b728a14 | ||
|
|
2c34ec91b1 | ||
|
|
08b746a53b | ||
|
|
615e2f5608 | ||
|
|
fa1e1ad8a3 | ||
|
|
c78def3919 | ||
|
|
54c53b9860 | ||
|
|
1fe8f703cc | ||
|
|
7ba806abf7 | ||
|
|
6b2e120739 | ||
|
|
e4103df326 | ||
|
|
f2acd4efa6 | ||
|
|
f4ed8d9928 | ||
|
|
ba74254b93 | ||
|
|
792a0f3820 | ||
|
|
b766041c4c | ||
|
|
a31e41f839 | ||
|
|
7cb5a31b89 | ||
|
|
617d0a3ae3 | ||
|
|
db3a3b77fc | ||
|
|
5a9643275a | ||
|
|
60d1e333aa | ||
|
|
96dc435cf6 | ||
|
|
263b08b53a | ||
|
|
89102d517e | ||
|
|
845af4abc8 | ||
|
|
3e02403598 | ||
|
|
0b0d569877 | ||
|
|
1cbda2e2f9 | ||
|
|
b6febf1933 | ||
|
|
53a6d2a459 | ||
|
|
6c82ce010b | ||
|
|
4b8b73e468 | ||
|
|
a75729dd6a | ||
|
|
b8792a87af | ||
|
|
c1261a2d3c | ||
|
|
0035f57738 | ||
|
|
b372d361e7 | ||
|
|
1e096e1aae | ||
|
|
420d669236 | ||
|
|
24aa6aabc6 | ||
|
|
5a9a4af532 | ||
|
|
50f93e5f59 | ||
|
|
33784f60b4 | ||
|
|
9a261aa781 | ||
|
|
366d5bc264 | ||
|
|
96ffa086b1 | ||
|
|
db005c138e | ||
|
|
1168f545e5 | ||
|
|
cc663c0518 | ||
|
|
40de31bc3b | ||
|
|
5884d76ff4 | ||
|
|
7cc59eb6fc | ||
|
|
24b3b35640 | ||
|
|
f2b8829299 | ||
|
|
4b64a041cc | ||
|
|
bd1157127a | ||
|
|
be6e4bbfa0 | ||
|
|
25b631099c | ||
|
|
1d698c5688 | ||
|
|
40f848ad7f | ||
|
|
fd2725c878 | ||
|
|
34b1d72e40 | ||
|
|
ca7db26976 | ||
|
|
94552f9c9e | ||
|
|
32c67b9c96 | ||
|
|
89f337d8c3 | ||
|
|
8a724400b8 | ||
|
|
f96f1d0f64 | ||
|
|
15398712ee | ||
|
|
ddb9963062 | ||
|
|
f18a9f3d4c | ||
|
|
1402ba9732 | ||
|
|
af51f53221 | ||
|
|
bce2d640ef | ||
|
|
1bb1847e45 | ||
|
|
e9543db138 | ||
|
|
a8e8229787 | ||
|
|
d1c91c6f2a | ||
|
|
843691f8b4 | ||
|
|
c9f14946d1 | ||
|
|
77cd7b5388 | ||
|
|
55502f9bed | ||
|
|
f08b823cc4 | ||
|
|
f831d4044f | ||
|
|
e8d8d160a7 | ||
|
|
dbbd4c0ec8 | ||
|
|
fc9a0e2858 | ||
|
|
17eb43db94 | ||
|
|
06610e9b9d | ||
|
|
889b88fd6c | ||
|
|
c5ca3e13e0 | ||
|
|
c1c524f092 | ||
|
|
7ea7defa1f | ||
|
|
6147c0085b | ||
|
|
0b70a9c767 | ||
|
|
d6d22c4096 | ||
|
|
6da54c1255 | ||
|
|
b55b4ea7a0 | ||
|
|
51625fe09e | ||
|
|
f3b9d33c87 | ||
|
|
8e4326f77a | ||
|
|
3d642a7404 | ||
|
|
552364471d | ||
|
|
cf15866270 | ||
|
|
7d4def14b1 | ||
|
|
20ad9389d4 | ||
|
|
d73073a187 | ||
|
|
b307d556e5 | ||
|
|
17c4dc445e | ||
|
|
03ea29ae81 | ||
|
|
e22a27652c | ||
|
|
c3ae3e1f8c | ||
|
|
094a9b2ebb | ||
|
|
d8b1c74155 | ||
|
|
c8fad9605c | ||
|
|
e8d0c13f16 | ||
|
|
f781e74d3a | ||
|
|
3cbdb12741 | ||
|
|
a714ea8d64 | ||
|
|
d81d4380de | ||
|
|
31498da25a | ||
|
|
7f59f69eab | ||
|
|
200b7cd170 |
@@ -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]
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
feature:
|
||||
- Add Proxmox API authentication support. [#125]
|
||||
2
.changelogs/1.1.0/137_fix_systemd_unit_file.yml
Normal file
2
.changelogs/1.1.0/137_fix_systemd_unit_file.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix the systemd unit file to start ProxLB after pveproxy (by @robertdahlem). [#137]
|
||||
@@ -1 +1 @@
|
||||
date: TBD
|
||||
date: 2025-04-01
|
||||
|
||||
2
.changelogs/1.1.1/163_fix_ignore_vm_tag.yml
Normal file
2
.changelogs/1.1.1/163_fix_ignore_vm_tag.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix tag evluation for VMs for being ignored for further balancing [#163]
|
||||
2
.changelogs/1.1.1/165_improve_logging_servity.yml
Normal file
2
.changelogs/1.1.1/165_improve_logging_servity.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Improve logging verbosity of messages that had a wrong servity [#165]
|
||||
2
.changelogs/1.1.1/168_add_more_flexible_schedules.yml
Normal file
2
.changelogs/1.1.1/168_add_more_flexible_schedules.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
feature:
|
||||
- Add a more flexible way to define schedules in minutes or hours (by @gyptazy) [#168]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix Python path for Docker entrypoint (by @crandler) [#170]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Honor the value when balancing should not be performed and stop balancing [#174]
|
||||
@@ -0,0 +1,2 @@
|
||||
changed:
|
||||
- Change the default behaviour of the daemon mode to active [#176]
|
||||
@@ -0,0 +1,2 @@
|
||||
changed:
|
||||
- Change the default banalcing mode to used instead of assigned [#180]
|
||||
@@ -0,0 +1,2 @@
|
||||
feature:
|
||||
- Add validation for the minimum required permissions of a user in Proxmox [#184]
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
2
.changelogs/1.1.1/200_requery_zero_guest_cpu_used.yml
Normal file
2
.changelogs/1.1.1/200_requery_zero_guest_cpu_used.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Requery a guest if that running guest reports 0 cpu usage (by @glitchvern) [#200]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix the guest type relationship in the logs when a migration job failed (by @gyptazy) [#204]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Providing the API upstream error message when migration fails in debug mode (by @gyptazy) [#205]
|
||||
1
.changelogs/1.1.1/release_meta.yml
Normal file
1
.changelogs/1.1.1/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-04-20
|
||||
2
.changelogs/1.1.10/335-prevalidate-affinity-matrix.yml
Normal file
2
.changelogs/1.1.10/335-prevalidate-affinity-matrix.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Prevent redundant rebalancing by validating existing affinity enforcement before taking actions (@gyptazy). [#335]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add safety-guard for PVE 8 users when activating conntrack-aware migrations mistakenly (@gyptazy). [#359]
|
||||
@@ -0,0 +1,3 @@
|
||||
fixed:
|
||||
- Fixed the Proxmox API connection validation which returned a false-positive logging message of timeouts (@gyptazy). [#361]
|
||||
- Refactored Proxmox API connection functions
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fixed a crash during PVE resource pool enumeration by skipping members not having a 'name' property (@stefanoettl). [#368]
|
||||
1
.changelogs/1.1.10/release_meta.yml
Normal file
1
.changelogs/1.1.10/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-11-25
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fixed missing overprovisioning safety guard to avoid node overprovisioning (@gyptazy). [#275]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fixed affinity matrix pre-validation by inverting validations (@Thalagyrt). [#335]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add possibility to sort and select balancing workloads by smaller/larger guest objects (@gyptazy). [#387]
|
||||
@@ -0,0 +1,2 @@
|
||||
feature:
|
||||
- Add support for Proxmox's native HA (affinity/anti-affinity) rules (@gyptazy). [#391]
|
||||
2
.changelogs/1.1.2/137_fix_systemd_unit_file.yml
Normal file
2
.changelogs/1.1.2/137_fix_systemd_unit_file.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix systemd unit file to run after network on non PVE nodes (by @robertdahlem) [#137]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add a configurable retry mechanism when connecting to the Proxmox API (by @gyptazy) [#157]
|
||||
@@ -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]
|
||||
@@ -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]
|
||||
1
.changelogs/1.1.2/release_meta.yml
Normal file
1
.changelogs/1.1.2/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-05-13
|
||||
2
.changelogs/1.1.3/189_add_reload_function.yml
Normal file
2
.changelogs/1.1.3/189_add_reload_function.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add relaod (SIGHUP) function to ProxLB to reload the configuration (by @gyptazy). [#189]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Align maintenance mode with Proxmox HA maintenance mode (by @gyptazy). [#232]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add optional wait time parameter to delay execution until the service takes action (by @gyptazy). #239
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Make the amount of parallel migrations configurable (by @gyptazy). [#241]
|
||||
@@ -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]
|
||||
1
.changelogs/1.1.3/release_meta.yml
Normal file
1
.changelogs/1.1.3/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-06-19
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Allow pinning of guests to a group of nodes (@gyptazy). [#245]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fixed an issue where balancing was performed in combination of deactivated balancing and dry-run mode (@gyptazy). [#248]
|
||||
2
.changelogs/1.1.4/255_fix_loglevels.yml
Normal file
2
.changelogs/1.1.4/255_fix_loglevels.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Modified log levels to make output lighter at INFO level (@pmarasse) [#255]
|
||||
1
.changelogs/1.1.4/release_meta.yml
Normal file
1
.changelogs/1.1.4/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-06-27
|
||||
2
.changelogs/1.1.5/260_allow_custom_api_ports.yml
Normal file
2
.changelogs/1.1.5/260_allow_custom_api_ports.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Allow custom API ports instead of fixed tcp/8006 (@gyptazy). [#260]
|
||||
1
.changelogs/1.1.5/release_meta.yml
Normal file
1
.changelogs/1.1.5/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-07-14
|
||||
2
.changelogs/1.1.6/268_fix_balancing_type_eval.yml
Normal file
2
.changelogs/1.1.6/268_fix_balancing_type_eval.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix balancing evaluation of guest types (e.g., VM or CT) (@gyptazy). [#268]
|
||||
2
.changelogs/1.1.6/290_validate_user_token_syntax.yml
Normal file
2
.changelogs/1.1.6/290_validate_user_token_syntax.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add validation for provided API user token id to avoid confusions (@gyptazy). [#291]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix stacktrace output when validating permissions on non existing users in Proxmox (@gyptazy). [#291]
|
||||
@@ -0,0 +1,3 @@
|
||||
fixed:
|
||||
- Fix Overprovisioning first node if anti_affinity_group has only one member (@MiBUl-eu). [#295]
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fixed:
|
||||
- Validate for node presence when pinning guests to avoid crashing (@gyptazy). [#296]
|
||||
|
||||
1
.changelogs/1.1.6/release_meta.yml
Normal file
1
.changelogs/1.1.6/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-09-04
|
||||
2
.changelogs/1.1.7/304_add_graceful_shutdown_sigint.yml
Normal file
2
.changelogs/1.1.7/304_add_graceful_shutdown_sigint.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add graceful shutdown for SIGINT (e.g., CTRL + C abort). (@gyptazy). [#304]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add conntrack state aware migrations of VMs (@gyptazy). [#305]
|
||||
2
.changelogs/1.1.7/308_fix_only_validate_valid_jobids.yml
Normal file
2
.changelogs/1.1.7/308_fix_only_validate_valid_jobids.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix crash when validating absent migration job ids. (@gyptazy). [#308]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix guest object names are not being evaluated in debug log. (@gyptazy). [#310]
|
||||
1
.changelogs/1.1.7/release_meta.yml
Normal file
1
.changelogs/1.1.7/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-09-19
|
||||
3
.changelogs/1.1.8/317_container_image_non_root.yml
Normal file
3
.changelogs/1.1.8/317_container_image_non_root.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
changed:
|
||||
- Container image does not run as root anymore (@mikaelkrantz945). [#317]
|
||||
- Container image uses venv for running ProxLB (@mikaelkrantz945). [#317]
|
||||
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Fix API errors when using conntrack aware migration with older PVE versions (@gyptazy). [#318]
|
||||
2
.changelogs/1.1.8/329_add_log_prefix.yml
Normal file
2
.changelogs/1.1.8/329_add_log_prefix.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
fixed:
|
||||
- Add a static ProxLB prefix to the log output when used by journal handler (@gyptazy). [#329]
|
||||
1
.changelogs/1.1.8/release_meta.yml
Normal file
1
.changelogs/1.1.8/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-10-09
|
||||
5
.changelogs/1.1.9/337_add_pressure_based_balancing.yml
Normal file
5
.changelogs/1.1.9/337_add_pressure_based_balancing.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
added:
|
||||
- Add pressure (PSI) based balancing for memory, cpu, disk (req. PVE9 or greater) (@gyptazy). [#337]
|
||||
- Pressure (PSI) based balancing for nodes
|
||||
- Pressure (PSI) based balancing for guests
|
||||
- Add PVE version evaluation
|
||||
2
.changelogs/1.1.9/342_add_memory_balancing_threshold.yml
Normal file
2
.changelogs/1.1.9/342_add_memory_balancing_threshold.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add an optional memory balancing threshold (@gyptazy). [#342]
|
||||
@@ -0,0 +1,2 @@
|
||||
added:
|
||||
- Add affinity/anti-affinity support by pools (@gyptazy). [#343]
|
||||
1
.changelogs/1.1.9/release_meta.yml
Normal file
1
.changelogs/1.1.9/release_meta.yml
Normal file
@@ -0,0 +1 @@
|
||||
date: 2025-10-30
|
||||
@@ -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,26 @@ 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 && \
|
||||
|
||||
# Get base version from source code
|
||||
BASE_VERSION=\$(grep __version__ proxlb/utils/version.py | awk '{print \$3}' | tr -d '\"')
|
||||
echo \"Base version: \$BASE_VERSION\"
|
||||
|
||||
# Build full version with timestamp
|
||||
FULL_VERSION=\"\${BASE_VERSION}+$(date +%Y%m%d%H%M)\"
|
||||
echo \"Full version: \$FULL_VERSION\"
|
||||
|
||||
# Update debian/changelog with new version
|
||||
dch --force-bad-version -v \"\$FULL_VERSION\" \
|
||||
\"Automated GitHub Actions build on $(date -u +'%Y-%m-%d %H:%M UTC').\" && \
|
||||
|
||||
# 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,25 +66,35 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debian-package
|
||||
path: deb_dist/*.deb
|
||||
path: package/*.deb
|
||||
|
||||
integration-test-debian:
|
||||
needs: build-package-debian
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
debian_version: [bookworm, trixie]
|
||||
name: Integration Test on Debian ${{ matrix.debian_version }}
|
||||
steps:
|
||||
- name: Download Debian package artifact
|
||||
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
|
||||
run: docker pull debian:${{ matrix.debian_version }}
|
||||
|
||||
- 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 "
|
||||
apt-get update && \
|
||||
apt-get install -y ./python3-proxlb*.deb && \
|
||||
python3 -c 'import proxlb; print(\"OK: Debian package successfully installed.\")'
|
||||
"
|
||||
docker run --rm \
|
||||
-v "$(pwd)/package:/package" \
|
||||
-w /package \
|
||||
debian:${{ matrix.debian_version }} \
|
||||
bash -c "
|
||||
set -e
|
||||
apt-get update
|
||||
apt-get install -y python3 systemd
|
||||
apt-get install -y ./proxlb*.deb
|
||||
python3 -c 'import proxlb; print(\"OK: Debian package successfully installed on ${{ matrix.debian_version }}.\")'
|
||||
"
|
||||
|
||||
26
.github/workflows/30-pipeline-build-container-amd64.yml
vendored
Normal file
26
.github/workflows/30-pipeline-build-container-amd64.yml
vendored
Normal 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
|
||||
26
.github/workflows/30-pipeline-build-container-arm64.yml
vendored
Normal file
26
.github/workflows/30-pipeline-build-container-arm64.yml
vendored
Normal 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
|
||||
23
.github/workflows/30-pipeline-build-container-multi-arch.yml
vendored
Normal file
23
.github/workflows/30-pipeline-build-container-multi-arch.yml
vendored
Normal 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
|
||||
284
CHANGELOG.md
Normal file
284
CHANGELOG.md
Normal file
@@ -0,0 +1,284 @@
|
||||
# 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.10] - 2025-11-25
|
||||
|
||||
### Added
|
||||
|
||||
- Prevent redundant rebalancing by validating existing affinity enforcement before taking actions (@gyptazy). [#335]
|
||||
- Add safety-guard for PVE 8 users when activating conntrack-aware migrations mistakenly (@gyptazy). [#359]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix the Proxmox API connection validation which returned a false-positive logging message of timeouts (@gyptazy). [#361]
|
||||
- Refactored Proxmox API connection functions (@gyptazy). [#361]
|
||||
- Fix a crash during PVE resource pool enumeration by skipping members not having a 'name' property (@stefanoettl). [#368]
|
||||
|
||||
## [1.1.9.1] - 2025-10-30
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix quoting in f-strings which may cause issues on PVE 8 / Debian Bookworm systems (@gyptazy). [#352]
|
||||
|
||||
## [1.1.9] - 2025-10-30
|
||||
|
||||
### Added
|
||||
|
||||
- Add an optional memory balancing threshold (@gyptazy). [#342]
|
||||
- Add affinity/anti-affinity support by pools (@gyptazy). [#343]
|
||||
- Add pressure (PSI) based balancing for memory, cpu, disk (req. PVE9 or greater) (@gyptazy). [#337]
|
||||
- Pressure (PSI) based balancing for nodes
|
||||
- Pressure (PSI) based balancing for guests
|
||||
- Add PVE version evaluation
|
||||
|
||||
## [1.1.8] - 2025-10-09
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix API errors when using conntrack aware migration with older PVE versions (@gyptazy). [#318]
|
||||
- Add a static ProxLB prefix to the log output when used by journal handler (@gyptazy). [#329]
|
||||
|
||||
### Changed
|
||||
- Container image does not run as root anymore (@mikaelkrantz945). [#317]
|
||||
- Container image uses venv for running ProxLB (@mikaelkrantz945). [#317]
|
||||
|
||||
## [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.
|
||||
41
Dockerfile
Normal file
41
Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
||||
# 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"
|
||||
|
||||
# --- Step 1 (root): system deps, user, dirs ---
|
||||
RUN apk add --no-cache python3 py3-pip \
|
||||
&& addgroup -S plb \
|
||||
&& adduser -S -G plb -h /home/plb plb \
|
||||
&& mkdir -p /app/conf /opt/venv \
|
||||
&& chown -R plb:plb /app /home/plb /opt/venv
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only requirements first for better layer caching
|
||||
COPY --chown=plb:plb requirements.txt /app/requirements.txt
|
||||
|
||||
# --- Step 2 (appuser): venv + deps + code ---
|
||||
USER plb
|
||||
|
||||
# Create venv owned by appuser and put it on PATH
|
||||
RUN python3 -m venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:${PATH}"
|
||||
|
||||
# Install Python dependencies into the venv (no PEP 668 issues)
|
||||
RUN pip install --no-cache-dir -r /app/requirements.txt
|
||||
|
||||
# Copy application code (owned by appuser)
|
||||
COPY --chown=plb:plb proxlb /app/proxlb
|
||||
|
||||
# Optional: placeholder config so a bind-mount can override cleanly
|
||||
RUN touch /app/conf/proxlb.yaml
|
||||
|
||||
# Run as non-root using venv Python
|
||||
ENTRYPOINT ["/opt/venv/bin/python", "/app/proxlb/main.py"]
|
||||
420
README.md
420
README.md
@@ -1,26 +1,19 @@
|
||||
# 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)
|
||||
3. [How does it work?](#how-does-it-work)
|
||||
4. [Installation](#installation)
|
||||
4. [Documentation](#documentation)
|
||||
5. [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)
|
||||
1. [GUI Integration](#gui-integration)
|
||||
2. [Proxmox HA Integration](#proxmox-ha-integration)
|
||||
@@ -28,17 +21,19 @@ This repository is currently under heavy work and changes. During that time it m
|
||||
7. [Affinity & Anti-Affinity Rules](#affinity--anti-affinity-rules)
|
||||
1. [Affinity Rules](#affinity-rules)
|
||||
2. [Anti-Affinity Rules](#anti-affinity-rules)
|
||||
3. [Ignore VMs](#ignore-vms)
|
||||
4. [Pin VMs to Hypervisor Nodes](#pin-vms-to-hypervisor-nodes)
|
||||
8. [Maintenance](#maintenance)
|
||||
9. [Misc](#misc)
|
||||
1. [Bugs](#bugs)
|
||||
2. [Contributing](#contributing)
|
||||
3. [Documentation](#documentation)
|
||||
4. [Support](#support)
|
||||
3. [Support](#support)
|
||||
4. [Enterprise-Support](#enterprise-support)
|
||||
10. [Author(s)](#authors)
|
||||
|
||||
|
||||
## Introduction
|
||||
ProxLB is an advanced load balancing solution specifically designed for Proxmox clusters, addressing the absence of a Dynamic Resource Scheduler (DRS) that is familiar to VMware users. As a third-party solution, ProxLB enhances the management and efficiency of Proxmox clusters by intelligently distributing workloads across available nodes. Workloads can be balanced by different times like the guest's memory, CPU or disk usage or their assignment to avoid overprovisioning and ensuring resources.
|
||||
ProxLB is an advanced load balancing solution specifically designed for Proxmox clusters, addressing the absence of an intelligent and more advanced resource scheduler. As a third-party solution, ProxLB enhances the management and efficiency of Proxmox clusters by intelligently distributing workloads across available nodes. Workloads can be balanced by different times like the guest's memory, CPU or disk usage or their assignment to avoid overprovisioning and ensuring resources.
|
||||
|
||||
One of the key advantages of ProxLB is that it is fully open-source and free, making it accessible for anyone to use, modify, and contribute to. This ensures transparency and fosters community-driven improvements. ProxLB supports filtering and ignoring specific nodes and guests through configuration files and API calls, providing administrators with the flexibility to tailor the load balancing behavior to their specific needs.
|
||||
|
||||
@@ -49,7 +44,7 @@ ProxLB can also return the best next node for guest placement, which can be inte
|
||||
Overall, ProxLB significantly enhances resource management by intelligently distributing workloads, reducing downtime through its maintenance mode, and providing improved flexibility with affinity and anti-affinity rules. Its seamless integration with CI/CD tools and reliance on the Proxmox API make it a robust and secure solution for optimizing Proxmox cluster performance.
|
||||
|
||||
### Video of Migration
|
||||
<img src="https://cdn.gyptazy.com/images/proxlb-rebalancing-demo.gif"/>
|
||||
<img src="https://cdn.gyptazy.com/img/proxlb-rebalancing-demo.gif"/>
|
||||
|
||||
## Features
|
||||
ProxLB's key features are by enabling automatic rebalancing of VMs and CTs across a Proxmox cluster based on memory, CPU, and local disk usage while identifying optimal nodes for automation. It supports maintenance mode, affinity rules, and seamless Proxmox API integration with ACL support, offering flexible usage as a one-time operation, a daemon, or through the Proxmox Web GUI.
|
||||
@@ -59,6 +54,10 @@ ProxLB's key features are by enabling automatic rebalancing of VMs and CTs acros
|
||||
* Memory
|
||||
* Disk (only local storage)
|
||||
* CPU
|
||||
* Rebalance by different modes:
|
||||
* Used resources
|
||||
* Assigned resources
|
||||
* PSI (Pressure) of resources
|
||||
* Get best nodes for further automation
|
||||
* Supported Guest Types
|
||||
* VMs
|
||||
@@ -80,9 +79,16 @@ ProxLB is a load-balancing system designed to optimize the distribution of virtu
|
||||
|
||||
Before starting any migrations, ProxLB validates that rebalancing actions are necessary and beneficial. Depending on the selected balancing mode — such as CPU, memory, or disk — it creates a balancing matrix. This matrix sorts the VMs by their maximum used or assigned resources, identifying the VM with the highest usage. ProxLB then places this VM on the node with the most free resources in the selected balancing type. This process runs recursively until the operator-defined Balanciness is achieved. Balancing can be defined for the used or max. assigned resources of VMs/CTs.
|
||||
|
||||
## Documentation
|
||||
This `README.md` doesn't contain all information and only highlights the most important facts. Extended information, such like API permissions, creating dedicated user, best-practices in running ProxLB and much more can be found in the [docs/](https://github.com/gyptazy/ProxLB/tree/main/docs) directory. Please consult the documentation before creating issues.
|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements / Dependencies
|
||||
* Proxmox
|
||||
* Proxmox 7.x
|
||||
* Proxmox 8.x
|
||||
* Proxmox 9.x
|
||||
* Python3.x
|
||||
* proxmoxer
|
||||
* requests
|
||||
@@ -94,29 +100,146 @@ 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).
|
||||
|
||||
**Note**: If you want to use ProxLB with the proxmox-offline-mirror or any other APT mirror tool that does not support the flat repository architecture, please see the [docs](https://github.com/gyptazy/ProxLB/blob/main/docs/02_installation.md#Repo-Mirror-and-Proxmox-Offline-Mirror-Support) how you can add this by using ProxLB's fully repo.
|
||||
|
||||
#### 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/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
|
||||
```
|
||||
|
||||
### 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.10 | cr.gyptazy.com/proxlb/proxlb:v1.1.10 |
|
||||
| v1.1.9.1 | cr.gyptazy.com/proxlb/proxlb:v1.1.9.1 |
|
||||
| v1.1.9 | cr.gyptazy.com/proxlb/proxlb:v1.1.9 |
|
||||
| v1.1.8 | cr.gyptazy.com/proxlb/proxlb:v1.1.8 |
|
||||
| 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.
|
||||
|
||||
### 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:
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/rebalance-ui.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)
|
||||
|
||||
@@ -136,42 +259,65 @@ 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. |
|
||||
| | 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)|
|
||||
| | force | 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. |
|
||||
| | memory_threshold | | 75 | `Int` | The maximum threshold (in percent) that needs to be hit to perform balancing actions. (Optional) |
|
||||
| | 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`, `psi` (pressure)] |
|
||||
| | balance_larger_guests_first | | False | `Bool` | Option to prefer larger/smaller guests first |
|
||||
| | psi | | { nodes: { memory: { pressure_full: 0.20, pressure_some: 0.20, pressure_spikes: 1.00 }}} | `Dict` | A dict of PSI based thresholds for nodes and guests |
|
||||
| | pools | | pools: { dev: { type: affinity }, de-nbg01-db: { type: anti-affinity }} | `Dict` | A dict of pool names and their type for creating affinity/anti-affinity rules |
|
||||
| `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!
|
||||
ssl_verification: False
|
||||
# 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']
|
||||
@@ -180,20 +326,66 @@ proxmox_cluster:
|
||||
|
||||
balancing:
|
||||
enable: True
|
||||
force: False
|
||||
enforce_affinity: False
|
||||
parallel: False
|
||||
live: True
|
||||
with_local_disks: True
|
||||
with_conntrack_state: True
|
||||
balance_types: ['vm', 'ct']
|
||||
max_job_validation: 1800
|
||||
memory_threshold: 75
|
||||
balanciness: 5
|
||||
method: memory
|
||||
mode: assigned
|
||||
mode: used
|
||||
balance_larger_guests_first: False
|
||||
# # PSI thresholds only apply when using mode 'psi'
|
||||
# # PSI based balancing is currently in beta and req. PVE >= 9
|
||||
# psi:
|
||||
# nodes:
|
||||
# memory:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# cpu:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# disk:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# guests:
|
||||
# memory:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# cpu:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# disk:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
pools:
|
||||
dev:
|
||||
type: affinity
|
||||
de-nbg01-db
|
||||
type: anti-affinity
|
||||
pin:
|
||||
- virt66
|
||||
- virt77
|
||||
|
||||
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
|
||||
@@ -201,7 +393,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 |
|
||||
@@ -213,19 +405,33 @@ ProxLB provides an advanced mechanism to define affinity and anti-affinity rules
|
||||
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 Proxmox’s 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.
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/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. In general, there're two ways to manage affinity rules:
|
||||
|
||||
#### Affinity Rules by Tags
|
||||
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.
|
||||
#### Affinity Rules by Pools
|
||||
Antoher approach is by using pools in Proxmox. This way, it can easily also combined with other resources like backup jobs. However, in this approach you need to modify the ProxLB config file to your needs. Within the `balancing` section you can create a dict of pools, including the pool name and the affinity type. Please see the example for further details:
|
||||
|
||||
**Example Config**
|
||||
```
|
||||
balancing:
|
||||
[...]
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
dev: # Pool name: dev
|
||||
type: affinity # Type: affinity (keeping VMs together)
|
||||
pin: # Pin VMs to Nodes
|
||||
- virt77 # Pinning to 'virt77' which is maybe an older system for dev labs
|
||||
```
|
||||
|
||||
### Anti-Affinity Rules by Tags
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/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. In general, there're two ways to manage anti-affinity rules:
|
||||
|
||||
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:
|
||||
|
||||
@@ -236,22 +442,85 @@ 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).
|
||||
|
||||
#### Anti-Affinity Rules by Pools
|
||||
Antoher approach is by using pools in Proxmox. This way, it can easily also combined with other resources like backup jobs. However, in this approach you need to modify the ProxLB config file to your needs. Within the `balancing` section you can create a dict of pools, including the pool name and the affinity type. Please see the example for further details:
|
||||
|
||||
**Example Config**
|
||||
```
|
||||
balancing:
|
||||
[...]
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
de-nbg01-db: # Pool name: de-nbg01-db
|
||||
type: anti-affinity # Type: anti-affinity (spreading VMs apart)
|
||||
```
|
||||
|
||||
|
||||
**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.
|
||||
|
||||
## Maintenance
|
||||
<img src="https://cdn.gyptazy.com/images/proxlb-rebalancing-demo.gif"/>
|
||||
### Ignore VMs
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/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/img/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.
|
||||
|
||||
#### Pinning VMs to (a) specific Hypervisor Node(s) by Tag
|
||||
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`.
|
||||
|
||||
|
||||
#### Pinning VMs to (a) specific Hypervisor Node(s) by Pools
|
||||
Beside the tag approach, you can also pin a resource group to a specific hypervisor or groups of hypervisors by defining a `pin` key of type list.
|
||||
|
||||
**Example Config**
|
||||
```
|
||||
balancing:
|
||||
[...]
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
dev: # Pool name: dev
|
||||
type: affinity # Type: affinity (keeping VMs together)
|
||||
pin: # Pin VMs to Nodes
|
||||
- virt77 # Pinning to 'virt77' which is maybe an older system for dev labs
|
||||
```
|
||||
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
### Contributing
|
||||
Feel free to add further documentation, to adjust already existing one or to contribute with code. Please take care about the style guide and naming conventions. You can find more in our [CONTRIBUTING.md](https://github.com/gyptazy/ProxLB/blob/development/CONTRIBUTING.md) file.
|
||||
|
||||
### Documentation
|
||||
You can also find additional and more detailed documentation within the [docs/](https://github.com/gyptazy/ProxLB/tree/development/docs) directory.
|
||||
Feel free to add further documentation, to adjust already existing one or to contribute with code. Please take care about the style guide and naming conventions. You can find more in our [CONTRIBUTING.md](https://github.com/gyptazy/ProxLB/blob/main/CONTRIBUTING.md) file.
|
||||
|
||||
### Support
|
||||
If you need assistance or have any questions, we offer support through our dedicated [chat room](https://matrix.to/#/#proxlb:gyptazy.com) in Matrix or [Discord](https://discord.gg/JemGu7WbfQ). Join our community for real-time help, advice, and discussions. The Matrix and Discord room are bridged to ensure that the communication is not splitted - so simply feel free to join which fits most to you!
|
||||
@@ -267,5 +536,18 @@ 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.
|
||||
|
||||
### Enterprise-Support
|
||||
Running critical infrastructure in an enterprise environment often comes with requirements that go far beyond functionality alone. Enterprises typically expect predictable service levels, defined escalation paths, and guaranteed response times. In many cases, organizations also demand 24x7 support availability to ensure that their systems remain stable and resilient, even under unexpected circumstances.
|
||||
|
||||
As the creator and maintainer of ProxLB, I operate as a one-man project. While I am continuously working to improve the software, I cannot provide the type of enterprise-grade support that large organizations may require. To address this need, several companies have stepped in to offer professional services around ProxLB in Proxmox VE clusters.
|
||||
|
||||
Below is a list of organizations currently known to provide enterprise-level support for ProxLB. If your business relies on ProxLB in production and you require more than community-based support, these providers may be a good fit for your needs:
|
||||
|
||||
| Company| Country | Web |
|
||||
|------|:------:|:------:|
|
||||
| credativ | DE | [credativ.de](https://www.credativ.de/en/portfolio/support/proxmox-virtualization/) |
|
||||
|
||||
*Note: If you provide support for ProxLB, feel free to create PR with your addition.*
|
||||
|
||||
### Author(s)
|
||||
* Florian Paul Azim Hoberg @gyptazy (https://gyptazy.com)
|
||||
* Florian Paul Azim Hoberg @gyptazy (https://gyptazy.com)
|
||||
|
||||
@@ -1,9 +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!
|
||||
ssl_verification: False
|
||||
# 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']
|
||||
@@ -12,17 +18,65 @@ proxmox_cluster:
|
||||
|
||||
balancing:
|
||||
enable: True
|
||||
force: False
|
||||
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
|
||||
balance_types: ['vm', 'ct']
|
||||
max_job_validation: 1800
|
||||
balanciness: 5
|
||||
method: memory
|
||||
mode: assigned
|
||||
with_conntrack_state: True
|
||||
balance_types: ['vm', 'ct'] # 'vm' | 'ct'
|
||||
max_job_validation: 1800 # Maximum time (in seconds) a job validation may take
|
||||
memory_threshold: 75 # Optional: Maximum threshold (in percent) to trigger balancing actions
|
||||
balanciness: 5 # Maximum delta of resource usage between highest and lowest usage node
|
||||
method: memory # 'memory' | 'cpu' | 'disk'
|
||||
mode: used # 'assigned' | 'used' | 'psi'
|
||||
balance_larger_guests_first: False # Option to prioritize balancing of larger or smaller guests first
|
||||
# # PSI thresholds only apply when using mode 'psi'
|
||||
# psi:
|
||||
# nodes:
|
||||
# memory:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# cpu:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# disk:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# guests:
|
||||
# memory:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# cpu:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
# disk:
|
||||
# pressure_full: 0.20
|
||||
# pressure_some: 0.20
|
||||
# pressure_spikes: 1.00
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
dev: # Pool name: dev
|
||||
type: affinity # Type: affinity (keeping VMs together)
|
||||
de-nbg01-db: # Pool name: de-nbg01-db
|
||||
type: anti-affinity # Type: anti-affinity (spreading VMs apart)
|
||||
pin: # Define a pinning og guests to specific node(s)
|
||||
- virt66
|
||||
- virt77
|
||||
|
||||
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
|
||||
|
||||
111
debian/changelog
vendored
Normal file
111
debian/changelog
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
proxlb (1.1.10) stable; urgency=medium
|
||||
|
||||
* Prevent redundant rebalancing by validating existing affinity enforcement before taking actions. (Closes: #335)
|
||||
* Add safety-guard for PVE 8 users when activating conntrack-aware migrations mistakenly. (Closes: #359)
|
||||
* Fix the Proxmox API connection validation which returned a false-positive logging message of timeouts. (Closes: #361)
|
||||
* Refactored the whole Proxmox API connection function. (Closes: #361)
|
||||
* Fix a crash during PVE resource pool enumeration by skipping members not having a 'name' property. (Closes: #368)
|
||||
|
||||
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Tue, 25 Nov 2025 09:12:04 +0001
|
||||
|
||||
proxlb (1.1.9.1) stable; urgency=medium
|
||||
|
||||
* Fix quoting in f-strings which may cause issues on PVE 8 / Debian Bookworm systems. (Closes: #352)
|
||||
|
||||
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 30 Oct 2025 17:41:02 +0001
|
||||
|
||||
proxlb (1.1.9) stable; urgency=medium
|
||||
|
||||
* Add pressure (PSI) based balancing for memory, cpu, disk (req. PVE9 or greater). (Closes: #339)
|
||||
* Add (memory) threshold for nodes before running balancing. (Closes: #342)
|
||||
* Add affinity/anti-affinity support by pools. (Closes: #343)
|
||||
|
||||
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 30 Oct 2025 06:58:43 +0001
|
||||
|
||||
proxlb (1.1.8) stable; urgency=medium
|
||||
|
||||
* Fix API errors when using conntrack aware migration with older PVE version. (Closes: #318)
|
||||
* Add a static ProxLB prefix to the log output when used by journal handler. (Closes: #329)
|
||||
|
||||
-- Florian Paul Azim Hoberg <gyptazy@gyptazy.com> Thu, 09 Oct 2025 09:04:13 +0002
|
||||
|
||||
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
12
debian/control
vendored
Normal 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-packaging, python3-proxmoxer, python3-yaml
|
||||
Description: An advanced resource scheduler and load balancer for Proxmox clusters
|
||||
An advanced resource scheduler and load balancer for Proxmox clusters that also supports maintenance mode and affinity/anti-affinity rules.
|
||||
2
debian/install
vendored
Normal file
2
debian/install
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
proxlb /usr/lib/python3/dist-packages/
|
||||
service/proxlb.service /lib/systemd/system/
|
||||
16
debian/postinst
vendored
Executable file
16
debian/postinst
vendored
Executable 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
16
debian/prerm
vendored
Executable 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
4
debian/rules
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/make -f
|
||||
%:
|
||||
dh $@ --with python3 --buildsystem=pybuild
|
||||
|
||||
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@@ -0,0 +1 @@
|
||||
3.0 (native)
|
||||
65
docs/01_requirements.md
Normal file
65
docs/01_requirements.md
Normal 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 Proxmox’s 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 is lightweight and flexible where it runs on nearly any environment and only needs access to your Proxmox host’s API endpoint (commonly TCP port 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
|
||||
186
docs/02_installation.md
Normal file
186
docs/02_installation.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# 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)
|
||||
- [Repo Mirror and Proxmox Offline Mirror Support](#repo-mirror-and-proxmox-offline-mirror-support)
|
||||
- [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
|
||||
```
|
||||
|
||||
#### Repo Mirror and Proxmox Offline Mirror Support
|
||||
ProxLB uses the supported flat mirror style for the Debian repository. Unfortunately, not all offline-mirror applications support it. One of the known ones is the official *proxmox-offline-mirror* which is unable to handle flat repositories (see also: [#385](https://github.com/gyptazy/ProxLB/issues/385)).
|
||||
|
||||
Therefore, we currently operate and support both ways to avoid everyone force switching to the new repository. As a result, you can simply use this repository:
|
||||
```
|
||||
deb https://repo.gyptazy.com/proxlb stable main
|
||||
```
|
||||
|
||||
**Example Config for proxmox-offline-mirror:**
|
||||
|
||||
An example config for the proxmox-offline-mirror would look like:
|
||||
```
|
||||
mirror: proxlb
|
||||
architectures amd64
|
||||
base-dir /var/lib/proxmox-offline-mirror/mirrors/
|
||||
key-path /etc/apt/trusted.gpg.d/proxlb.asc
|
||||
repository deb https://repo.gyptazy.com/proxlb stable main
|
||||
sync true
|
||||
verify true
|
||||
```
|
||||
|
||||
### 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.
|
||||
377
docs/03_configuration.md
Normal file
377
docs/03_configuration.md
Normal file
@@ -0,0 +1,377 @@
|
||||
# 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)
|
||||
10. [Balancing Methods](#balancing-methods)
|
||||
1. [Used Resources](#used-resources)
|
||||
2. [Assigned Resources](#assigned-resources)
|
||||
3. [Pressure (PSI) based Resources](#pressure-psi-based-resources)
|
||||
|
||||
## 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 Proxmox’s 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 Proxmox’s inherent permission model.
|
||||
|
||||
#### Affinity Rules by Tags
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/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).
|
||||
|
||||
#### Affinity Rules by Pools
|
||||
Antoher approach is by using pools in Proxmox. This way, it can easily also combined with other resources like backup jobs. However, in this approach you need to modify the ProxLB config file to your needs. Within the `balancing` section you can create a dict of pools, including the pool name and the affinity type. Please see the example for further details:
|
||||
|
||||
**Example Config**
|
||||
```
|
||||
balancing:
|
||||
[...]
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
dev: # Pool name: dev
|
||||
type: affinity # Type: affinity (keeping VMs together)
|
||||
```
|
||||
|
||||
#### Anti-Affinity Rules by Tags
|
||||
<img align="left" src="https://cdn.gyptazy.com/img/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.
|
||||
|
||||
#### Anti-Affinity Rules by Pools
|
||||
Antoher approach is by using pools in Proxmox. This way, it can easily also combined with other resources like backup jobs. However, in this approach you need to modify the ProxLB config file to your needs. Within the `balancing` section you can create a dict of pools, including the pool name and the affinity type. Please see the example for further details:
|
||||
|
||||
**Example Config**
|
||||
```
|
||||
balancing:
|
||||
[...]
|
||||
pools: # Optional: Define affinity/anti-affinity rules per pool
|
||||
de-nbg01-db: # Pool name: de-nbg01-db
|
||||
type: anti-affinity # Type: anti-affinity (spreading VMs apart)
|
||||
````
|
||||
|
||||
### 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/img/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.
|
||||
|
||||
## 10. Balancing Methods
|
||||
ProxLB provides multiple balancing modes that define *how* resources are evaluated and compared during cluster balancing.
|
||||
Each mode reflects a different strategy for determining load and distributing guests (VMs or containers) between nodes.
|
||||
|
||||
Depending on your environment, provisioning strategy, and performance goals, you can choose between:
|
||||
|
||||
| Mode | Description | Typical Use Case |
|
||||
|------|--------------|------------------|
|
||||
| `used` | Uses the *actual runtime resource usage* (e.g. CPU, memory, disk). | Dynamic or lab environments with frequent workload changes and tolerance for overprovisioning. |
|
||||
| `assigned` | Uses the *statically defined resource allocations* from guest configurations. | Production or SLA-driven clusters that require guaranteed resources and predictable performance. |
|
||||
| `psi` | Uses Linux *Pressure Stall Information (PSI)* metrics to evaluate real system contention and pressure. | Advanced clusters that require pressure-aware decisions for proactive rebalancing. |
|
||||
|
||||
### 10.1 Used Resources
|
||||
When **mode: `used`** is configured, ProxLB evaluates the *real usage metrics* of guest objects (VMs and CTs).
|
||||
It collects the current CPU, memory, and disk usage directly from the Proxmox API to determine the *actual consumption* of each guest and node.
|
||||
|
||||
This mode is ideal for **dynamic environments** where workloads frequently change and **overprovisioning is acceptable**. It provides the most reactive balancing behavior, since decisions are based on live usage instead of static assignment.
|
||||
|
||||
Typical scenarios include:
|
||||
- Production environments to distribute workloads across the nodes.
|
||||
- Test or development clusters with frequent VM changes.
|
||||
- Clusters where resource spikes are short-lived.
|
||||
- Environments where slight resource contention is tolerable.
|
||||
|
||||
#### Example Configuration
|
||||
```yaml
|
||||
balancing:
|
||||
mode: used
|
||||
```
|
||||
|
||||
### 10.2 Assigned Resources
|
||||
When **mode: `assigned`** is configured, ProxLB evaluates the *provisioned or allocated resources* of each guest (VM or CT) instead of their runtime usage.
|
||||
It uses data such as **CPU cores**, **memory limits**, and **disk allocations** defined in Proxmox to calculate how much of each node’s capacity is reserved.
|
||||
|
||||
This mode is ideal for **production clusters** where:
|
||||
- Overcommitment is *not allowed or only minimally tolerated*.
|
||||
- Each node’s workload is planned based on the assigned capacities.
|
||||
- Administrators want predictable resource distribution aligned with provisioning policies.
|
||||
|
||||
Unlike the `used` mode, `assigned` focuses purely on the *declared configuration* of guests and remains stable even if actual usage varies temporarily.
|
||||
|
||||
Typical scenarios include:
|
||||
- Enterprise environments with SLA or QoS requirements.
|
||||
- Clusters where workloads are sized deterministically.
|
||||
- Situations where consistent node utilization and capacity awareness are crucial.
|
||||
|
||||
#### Example Configuration
|
||||
```yaml
|
||||
balancing:
|
||||
mode: assigned
|
||||
```
|
||||
|
||||
### 10.3 Pressure (PSI) based Resources
|
||||
> [!IMPORTANT]
|
||||
> PSI based balancing is still in beta! If you find any bugs, please raise an issue including metrics of all nodes and affected guests. You can provide metrics directly from PVE or Grafana (via node_exporter or pve_exporter).
|
||||
|
||||
When **mode: `psi`** is configured, ProxLB uses the **Linux Pressure Stall Information (PSI)** interface to measure the *real-time pressure* on system resources such as **CPU**, **memory**, and **disk I/O**.
|
||||
Unlike the `used` or `assigned` modes, which rely on static or average metrics, PSI provides *direct insight into how often and how long tasks are stalled* because of insufficient resources.
|
||||
|
||||
This enables ProxLB to make **proactive balancing decisions** — moving workloads *before* performance degradation becomes visible to the user.
|
||||
|
||||
**IMPORTANT**: Predicting distributing workloads is dangerous and might not result into the expected state. Therefore, ProxLB migrates only a single instance each 60 minutes to obtain new real-metrics and to validate if further changes are required. Keep in mind, that migrations are also costly and should be avoided as much as possible.
|
||||
|
||||
PSI metrics are available for both **nodes** and **guest objects**, allowing fine-grained balancing decisions:
|
||||
- **Node-level PSI:** Detects cluster nodes under systemic load or contention.
|
||||
- **Guest-level PSI:** Identifies individual guests suffering from memory, CPU, or I/O stalls.
|
||||
|
||||
### PSI Metrics Explained
|
||||
Each monitored resource defines three pressure thresholds:
|
||||
| Key | Description |
|
||||
|-----|--------------|
|
||||
| `pressure_some` | Indicates partial stall conditions where some tasks are waiting for a resource. |
|
||||
| `pressure_full` | Represents complete stall conditions where *all* tasks are blocked waiting for a resource. |
|
||||
| `pressure_spikes` | Defines short-term burst conditions that may signal saturation spikes. |
|
||||
|
||||
These thresholds are expressed in **percentages** and represent how much time the kernel reports stalls over specific averaging windows (e.g. 5s, 10s, 60s).
|
||||
|
||||
### Example Configuration
|
||||
|
||||
```yaml
|
||||
balancing:
|
||||
mode: psi
|
||||
psi:
|
||||
nodes:
|
||||
memory:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
cpu:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
disk:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
guests:
|
||||
memory:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
cpu:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
disk:
|
||||
pressure_full: 0.20
|
||||
pressure_some: 0.20
|
||||
pressure_spikes: 1.00
|
||||
```
|
||||
24
docs/99-faq.md
Normal file
24
docs/99-faq.md
Normal 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).
|
||||
6
helm/proxlb/Chart.yaml
Normal file
6
helm/proxlb/Chart.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: v2
|
||||
name: proxlb
|
||||
description: A Helm chart for self-hosted ProxLB
|
||||
type: application
|
||||
version: "1.1.10"
|
||||
appVersion: "v1.1.10"
|
||||
13
helm/proxlb/templates/_helpers.yaml
Normal file
13
helm/proxlb/templates/_helpers.yaml
Normal 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 }}
|
||||
11
helm/proxlb/templates/configmap.yaml
Normal file
11
helm/proxlb/templates/configmap.yaml
Normal 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 }}
|
||||
44
helm/proxlb/templates/deployment.yaml
Normal file
44
helm/proxlb/templates/deployment.yaml
Normal 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
61
helm/proxlb/values.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
image:
|
||||
registry: cr.gyptazy.com
|
||||
repository: proxlb/proxlb
|
||||
tag: v1.1.10
|
||||
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
|
||||
@@ -1,6 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
VERSION="1.1.0-alpha"
|
||||
VERSION="1.1.9.1"
|
||||
|
||||
# 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
|
||||
sed -i "s/^tag: .*/tag: \"v$VERSION\"/" helm/proxlb/values.yaml
|
||||
|
||||
echo "OK: Versions have been sucessfully set to $VERSION"
|
||||
|
||||
@@ -7,16 +7,25 @@ perform balancing actions based on the configuration provided. It also includes
|
||||
parser for handling command-line arguments and a custom logger for systemd integration.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__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
|
||||
from utils.proxmox_api import ProxmoxApi
|
||||
from models.nodes import Nodes
|
||||
from models.features import Features
|
||||
from models.guests import Guests
|
||||
from models.groups import Groups
|
||||
from models.calculations import Calculations
|
||||
from models.balancing import Balancing
|
||||
from models.pools import Pools
|
||||
from models.ha_rules import HaRules
|
||||
from utils.helper import Helper
|
||||
|
||||
|
||||
@@ -27,6 +36,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()
|
||||
@@ -39,6 +52,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)
|
||||
|
||||
@@ -46,29 +62,50 @@ 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)
|
||||
pools = Pools.get_pools(proxmox_api)
|
||||
ha_rules = HaRules.get_ha_rules(proxmox_api)
|
||||
guests = Guests.get_guests(proxmox_api, pools, ha_rules, nodes, meta, proxlb_config)
|
||||
groups = Groups.get_groups(guests, nodes)
|
||||
|
||||
# Merge obtained objects from the Proxmox cluster for further usage
|
||||
proxlb_data = {**meta, **nodes, **guests, **groups}
|
||||
proxlb_data = {**meta, **nodes, **guests, **pools, **ha_rules, **groups}
|
||||
Helper.log_node_metrics(proxlb_data)
|
||||
|
||||
# Validate usable features by PVE versions
|
||||
Features.validate_available_features(proxlb_data)
|
||||
|
||||
# Update the initial node resource assignments
|
||||
# by the previously created groups.
|
||||
Calculations.set_node_assignments(proxlb_data)
|
||||
Calculations.set_node_hot(proxlb_data)
|
||||
Calculations.set_guest_hot(proxlb_data)
|
||||
Calculations.get_most_free_node(proxlb_data, cli_args.best_node)
|
||||
Calculations.validate_affinity_map(proxlb_data)
|
||||
Calculations.relocate_guests_on_maintenance_nodes(proxlb_data)
|
||||
Calculations.get_balanciness(proxlb_data)
|
||||
Calculations.relocate_guests(proxlb_data)
|
||||
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)
|
||||
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
"""
|
||||
The balancing class is responsible for processing workloads on Proxmox clusters.
|
||||
The previously generated data (hold in proxlb_data) will processed and guests and
|
||||
other supported types will be moved across Proxmox clusters based on the defined
|
||||
values by an operator.
|
||||
The Balancing class is responsible for processing workloads on Proxmox clusters.
|
||||
It processes the previously generated data (held in proxlb_data) and moves guests
|
||||
and other supported types across Proxmox clusters based on the defined values by an operator.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
import proxmoxer
|
||||
import time
|
||||
from itertools import islice
|
||||
from utils.logger import SystemdLogger
|
||||
from typing import Dict, Any
|
||||
|
||||
@@ -19,6 +25,23 @@ class Balancing:
|
||||
The previously generated data (hold in proxlb_data) will processed and guests and
|
||||
other supported types will be moved across Proxmox clusters based on the defined
|
||||
values by an operator.
|
||||
|
||||
Methods:
|
||||
__init__(self, proxmox_api: any, proxlb_data: Dict[str, Any]):
|
||||
Initializes the Balancing class with the provided ProxLB data and initiates the rebalancing
|
||||
process for guests.
|
||||
|
||||
exec_rebalancing_vm(self, proxmox_api: any, proxlb_data: Dict[str, Any], guest_name: str) -> None:
|
||||
Executes the rebalancing of a virtual machine (VM) to a new node within the cluster. Logs the migration
|
||||
process and handles exceptions.
|
||||
|
||||
exec_rebalancing_ct(self, proxmox_api: any, proxlb_data: Dict[str, Any], guest_name: str) -> None:
|
||||
Executes the rebalancing of a container (CT) to a new node within the cluster. Logs the migration
|
||||
process and handles exceptions.
|
||||
|
||||
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:
|
||||
Monitors the status of a rebalancing job on a Proxmox node until it completes or a timeout
|
||||
is reached. Returns True if the job completed successfully, False otherwise.
|
||||
"""
|
||||
|
||||
def __init__(self, proxmox_api: any, proxlb_data: Dict[str, Any]):
|
||||
@@ -26,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:
|
||||
"""
|
||||
@@ -66,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
|
||||
@@ -78,19 +157,25 @@ class Balancing:
|
||||
with_local_disks = 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,
|
||||
}
|
||||
|
||||
# Conntrack state aware migrations are not supported in older
|
||||
# PVE versions, so we should not add it by default.
|
||||
if proxlb_data["meta"]["balancing"].get("with_conntrack_state", True):
|
||||
migration_options['with-conntrack-state'] = 1
|
||||
|
||||
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:
|
||||
"""
|
||||
@@ -111,15 +196,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:
|
||||
"""
|
||||
@@ -137,35 +224,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
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
"""
|
||||
The calculation class is responsible for handling the balancing of virtual machines (VMs)
|
||||
The Calculations class is responsible for handling the balancing of virtual machines (VMs)
|
||||
and containers (CTs) across all available nodes in a Proxmox cluster. It provides methods
|
||||
to calculate the optimal distribution of VMs and CTs based on the provided data.
|
||||
"""
|
||||
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
import sys
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
@@ -16,6 +22,37 @@ class Calculations:
|
||||
The calculation class is responsible for handling the balancing of virtual machines (VMs)
|
||||
and containers (CTs) across all available nodes in a Proxmox cluster. It provides methods
|
||||
to calculate the optimal distribution of VMs and CTs based on the provided data.
|
||||
|
||||
Methods:
|
||||
__init__(proxlb_data: Dict[str, Any]):
|
||||
Initializes the Calculation class with the provided ProxLB data.
|
||||
|
||||
set_node_assignments(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
Sets the assigned resources of the nodes based on the current assigned
|
||||
guest resources by their created groups as an initial base.
|
||||
|
||||
get_balanciness(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
Gets the balanciness for further actions where the highest and lowest
|
||||
usage or assignments of Proxmox nodes are compared.
|
||||
|
||||
get_most_free_node(proxlb_data: Dict[str, Any], return_node: bool = False) -> Dict[str, Any]:
|
||||
Gets 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).
|
||||
|
||||
relocate_guests_on_maintenance_nodes(proxlb_data: Dict[str, Any]):
|
||||
Relocates guests that are currently on nodes marked for maintenance to
|
||||
nodes with the most available resources.
|
||||
|
||||
relocate_guests(proxlb_data: Dict[str, Any]):
|
||||
Relocates guests within the provided data structure to ensure affinity groups are
|
||||
placed on nodes with the most free resources.
|
||||
|
||||
val_anti_affinity(proxlb_data: Dict[str, Any], guest_name: str):
|
||||
Validates and assigns nodes to guests based on anti-affinity rules.
|
||||
|
||||
update_node_resources(proxlb_data):
|
||||
Updates the resource allocation and usage statistics for nodes when a guest
|
||||
is moved from one node to another.
|
||||
"""
|
||||
|
||||
def __init__(self, proxlb_data: Dict[str, Any]):
|
||||
@@ -29,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:
|
||||
@@ -43,8 +80,9 @@ class Calculations:
|
||||
|
||||
for guest_name in group_meta["guests"]:
|
||||
guest_node_current = proxlb_data["guests"][guest_name]["node_current"]
|
||||
# Update Hardware assignments
|
||||
# Update resource 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"]
|
||||
@@ -55,6 +93,83 @@ class Calculations:
|
||||
|
||||
logger.debug("Finished: set_node_assignments.")
|
||||
|
||||
def set_node_hot(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Evaluates node 'full' pressure metrics for memory, cpu, and io
|
||||
against defined thresholds and sets <metric>_pressure_hot = True
|
||||
when a node is considered HOT.
|
||||
|
||||
Returns the modified proxlb_data dict.
|
||||
"""
|
||||
logger.debug("Starting: set_node_hot.")
|
||||
balancing_cfg = proxlb_data.get("meta", {}).get("balancing", {})
|
||||
thresholds = balancing_cfg.get("psi_thresholds", balancing_cfg.get("psi", {}).get("nodes", {}))
|
||||
nodes = proxlb_data.get("nodes", {})
|
||||
|
||||
for node_name, node in nodes.items():
|
||||
|
||||
if node.get("maintenance"):
|
||||
continue
|
||||
|
||||
if node.get("ignore"):
|
||||
continue
|
||||
|
||||
# PSI metrics are only availavble on Proxmox VE 9.0 and higher.
|
||||
if proxlb_data["meta"]["balancing"].get("mode", "used") == "psi":
|
||||
|
||||
if tuple(map(int, proxlb_data["nodes"][node["name"]]["pve_version"].split('.'))) < tuple(map(int, "9.0".split('.'))):
|
||||
logger.critical(f"Proxmox node {node['name']} runs Proxmox VE version {proxlb_data['nodes'][node['name']]['pve_version']}."
|
||||
" PSI metrics require Proxmox VE 9.0 or higher. Balancing deactivated!")
|
||||
|
||||
for metric, threshold in thresholds.items():
|
||||
pressure_full = node.get(f"{metric}_pressure_full_percent", 0.0)
|
||||
pressure_some = node.get(f"{metric}_pressure_some_percent", 0.0)
|
||||
pressure_spikes = node.get(f"{metric}_pressure_full_spikes_percent", 0.0)
|
||||
is_hot = (pressure_full >= threshold["pressure_full"] and pressure_some >= threshold["pressure_some"]) or (pressure_spikes >= threshold["pressure_spikes"])
|
||||
|
||||
if is_hot:
|
||||
logger.debug(f"Set node {node['name']} as hot based on {metric} pressure metrics.")
|
||||
proxlb_data["nodes"][node["name"]][f"{metric}_pressure_hot"] = True
|
||||
proxlb_data["nodes"][node["name"]][f"pressure_hot"] = True
|
||||
else:
|
||||
logger.debug(f"Node {node['name']} is not hot based on {metric} pressure metrics.")
|
||||
|
||||
logger.debug("Finished: set_node_hot.")
|
||||
return proxlb_data
|
||||
|
||||
def set_guest_hot(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Evaluates guest 'full' pressure metrics for memory, cpu, and io
|
||||
against defined thresholds and sets <metric>_pressure_hot = True
|
||||
when a guest is considered HOT.
|
||||
|
||||
Returns the modified proxlb_data dict.
|
||||
"""
|
||||
logger.debug("Starting: set_guest_hot.")
|
||||
balancing_cfg = proxlb_data.get("meta", {}).get("balancing", {})
|
||||
thresholds = balancing_cfg.get("psi_thresholds", balancing_cfg.get("psi", {}).get("guests", {}))
|
||||
guests = proxlb_data.get("guests", {})
|
||||
|
||||
for guest_name, guest in guests.items():
|
||||
if guest.get("ignore"):
|
||||
continue
|
||||
|
||||
for metric, threshold in thresholds.items():
|
||||
pressure_full = guest.get(f"{metric}_pressure_full_percent", 0.0)
|
||||
pressure_some = guest.get(f"{metric}_pressure_some_percent", 0.0)
|
||||
pressure_spikes = guest.get(f"{metric}_pressure_full_spikes_percent", 0.0)
|
||||
is_hot = (pressure_full >= threshold["pressure_full"] and pressure_some >= threshold["pressure_some"]) or (pressure_spikes >= threshold["pressure_spikes"])
|
||||
|
||||
if is_hot:
|
||||
logger.debug(f"Set guest {guest['name']} as hot based on {metric} pressure metrics.")
|
||||
proxlb_data["guests"][guest["name"]][f"{metric}_pressure_hot"] = True
|
||||
proxlb_data["guests"][guest["name"]][f"pressure_hot"] = True
|
||||
else:
|
||||
logger.debug(f"guest {guest['name']} is not hot based on {metric} pressure metrics.")
|
||||
|
||||
logger.debug("Finished: set_guest_hot.")
|
||||
return proxlb_data
|
||||
|
||||
@staticmethod
|
||||
def get_balanciness(proxlb_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -75,17 +190,74 @@ class Calculations:
|
||||
method = proxlb_data["meta"]["balancing"].get("method", "memory")
|
||||
mode = proxlb_data["meta"]["balancing"].get("mode", "used")
|
||||
balanciness = proxlb_data["meta"]["balancing"].get("balanciness", 10)
|
||||
method_value = [node_meta[f"{method}_{mode}_percent"] for node_meta in proxlb_data["nodes"].values()]
|
||||
|
||||
if mode == "assigned":
|
||||
method_value = [node_meta[f"{method}_{mode}_percent"] for node_meta in proxlb_data["nodes"].values()]
|
||||
|
||||
if proxlb_data["meta"]["balancing"].get(f"{method}_threshold", None):
|
||||
threshold = proxlb_data["meta"]["balancing"].get(f"{method}_threshold")
|
||||
highest_usage_node = max(proxlb_data["nodes"].values(), key=lambda x: x[f"{method}_{mode}_percent"])
|
||||
highest_node_value = highest_usage_node[f"{method}_{mode}_percent"]
|
||||
|
||||
if highest_node_value >= threshold:
|
||||
logger.debug(f"Guest balancing is required. Highest {method} usage node {highest_usage_node['name']} is above the defined threshold of {threshold}% with a value of {highest_node_value}%.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = True
|
||||
else:
|
||||
logger.debug(f"Guest balancing is ok. Highest {method} usage node {highest_usage_node['name']} is below the defined threshold of {threshold}% with a value of {highest_node_value}%.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = False
|
||||
|
||||
else:
|
||||
logger.debug(f"No {method} threshold defined for balancing. Skipping threshold check.")
|
||||
|
||||
elif mode == "used":
|
||||
method_value = [node_meta[f"{method}_{mode}_percent"] for node_meta in proxlb_data["nodes"].values()]
|
||||
|
||||
if proxlb_data["meta"]["balancing"].get(f"{method}_threshold", None):
|
||||
threshold = proxlb_data["meta"]["balancing"].get(f"{method}_threshold")
|
||||
highest_usage_node = max(proxlb_data["nodes"].values(), key=lambda x: x[f"{method}_{mode}_percent"])
|
||||
highest_node_value = highest_usage_node[f"{method}_{mode}_percent"]
|
||||
|
||||
if highest_node_value >= threshold:
|
||||
logger.debug(f"Guest balancing is required. Highest {method} usage node {highest_usage_node['name']} is above the defined threshold of {threshold}% with a value of {highest_node_value}%.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = True
|
||||
else:
|
||||
logger.debug(f"Guest balancing is ok. Highest {method} usage node {highest_usage_node['name']} is below the defined threshold of {threshold}% with a value of {highest_node_value}%.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = False
|
||||
|
||||
else:
|
||||
logger.debug(f"No {method} threshold defined for balancing. Skipping threshold check.")
|
||||
|
||||
elif mode == "psi":
|
||||
method_value = [node_meta[f"{method}_pressure_full_spikes_percent"] for node_meta in proxlb_data["nodes"].values()]
|
||||
any_node_hot = any(node.get(f"{method}_pressure_hot", False) for node in proxlb_data["nodes"].values())
|
||||
any_guest_hot = any(node.get(f"{method}_pressure_hot", False) for node in proxlb_data["guests"].values())
|
||||
|
||||
if any_node_hot:
|
||||
logger.debug(f"Guest balancing is required. A node is marked as HOT based on {method} pressure metrics.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = True
|
||||
else:
|
||||
logger.debug(f"Guest balancing is ok. No node is marked as HOT based on {method} pressure metrics.")
|
||||
|
||||
if any_guest_hot:
|
||||
logger.debug(f"Guest balancing is required. A guest is marked as HOT based on {method} pressure metrics.")
|
||||
proxlb_data["meta"]["balancing"]["balance"] = True
|
||||
else:
|
||||
logger.debug(f"Guest balancing is ok. No guest is marked as HOT based on {method} pressure metrics.")
|
||||
|
||||
return proxlb_data
|
||||
|
||||
else:
|
||||
logger.critical(f"Unknown balancing mode: {mode} provided. Cannot get balanciness.")
|
||||
sys.exit(1)
|
||||
|
||||
method_value_highest = max(method_value)
|
||||
method_value_lowest = min(method_value)
|
||||
|
||||
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.")
|
||||
@@ -93,7 +265,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).
|
||||
@@ -102,6 +274,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
|
||||
@@ -110,9 +284,34 @@ 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")
|
||||
|
||||
if mode == "assigned":
|
||||
logger.debug(f"Get best node for balancing by assigned {method} resources.")
|
||||
lowest_usage_node = min(filtered_nodes, key=lambda x: x[f"{method}_{mode}_percent"])
|
||||
|
||||
elif mode == "used":
|
||||
logger.debug(f"Get best node for balancing by used {method} resources.")
|
||||
lowest_usage_node = min(filtered_nodes, key=lambda x: x[f"{method}_{mode}_percent"])
|
||||
|
||||
elif mode == "psi":
|
||||
logger.debug(f"Get best node for balancing by pressure of {method} resources.")
|
||||
lowest_usage_node = min(filtered_nodes, key=lambda x: x[f"{method}_pressure_full_spikes_percent"])
|
||||
|
||||
else:
|
||||
logger.critical(f"Unknown balancing mode: {mode} provided. Cannot get best node.")
|
||||
sys.exit(1)
|
||||
|
||||
proxlb_data["meta"]["balancing"]["balance_reason"] = 'resources'
|
||||
proxlb_data["meta"]["balancing"]["balance_next_node"] = lowest_usage_node["name"]
|
||||
|
||||
@@ -141,7 +340,7 @@ class Calculations:
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
logger.debug("Starting: get_most_free_node.")
|
||||
logger.debug("Starting: relocate_guests_on_maintenance_nodes.")
|
||||
proxlb_data["meta"]["balancing"]["balance_next_guest"] = ""
|
||||
|
||||
for guest_name in proxlb_data["groups"]["maintenance"]:
|
||||
@@ -152,7 +351,7 @@ class Calculations:
|
||||
Calculations.update_node_resources(proxlb_data)
|
||||
logger.warning(f"Warning: Balancing may not be perfect because guest {guest_name} was located on a node which is in maintenance mode.")
|
||||
|
||||
logger.debug("Finished: get_most_free_node.")
|
||||
logger.debug("Finished: relocate_guests_on_maintenance_nodes.")
|
||||
|
||||
@staticmethod
|
||||
def relocate_guests(proxlb_data: Dict[str, Any]):
|
||||
@@ -170,15 +369,27 @@ class Calculations:
|
||||
None
|
||||
"""
|
||||
logger.debug("Starting: relocate_guests.")
|
||||
if proxlb_data["meta"]["balancing"]["balance"] or proxlb_data["meta"]["balancing"]["force"]:
|
||||
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("force", False):
|
||||
logger.debug("Balancing of guests will be performt. Reason: force balancing")
|
||||
if proxlb_data["meta"]["balancing"].get("enforce_affinity", False):
|
||||
logger.debug("Balancing of guests will be performed. Reason: enforce affinity balancing")
|
||||
|
||||
for group_name in proxlb_data["groups"]["affinity"]:
|
||||
# Sort guests by used memory
|
||||
# Allows processing larger guests first or smaller guests first
|
||||
larger_first = proxlb_data.get("meta", {}).get("balancing", {}).get("balance_larger_guests_first", False)
|
||||
|
||||
if larger_first:
|
||||
logger.debug("Larger guests will be processed first. (Sorting descending by memory used)")
|
||||
else:
|
||||
logger.debug("Smaller guests will be processed first. (Sorting ascending by memory used)")
|
||||
|
||||
sorted_guest_usage_groups = sorted(proxlb_data["groups"]["affinity"], key=lambda g: proxlb_data["groups"]["affinity"][g]["memory_used"], reverse=larger_first)
|
||||
|
||||
# Iterate over all affinity groups
|
||||
for group_name in sorted_guest_usage_groups:
|
||||
|
||||
# We get initially the node with the most free resources and then
|
||||
# migrate all guests within the group to that node to ensure the
|
||||
@@ -186,8 +397,32 @@ class Calculations:
|
||||
Calculations.get_most_free_node(proxlb_data)
|
||||
|
||||
for guest_name in proxlb_data["groups"]["affinity"][group_name]["guests"]:
|
||||
proxlb_data["meta"]["balancing"]["balance_next_guest"] = guest_name
|
||||
mode = proxlb_data["meta"]["balancing"].get("mode", "used")
|
||||
|
||||
if not Calculations.validate_node_resources(proxlb_data, guest_name):
|
||||
logger.warning(f"Skipping relocation of guest {guest_name} due to insufficient resources on target node {proxlb_data['meta']['balancing']['balance_next_node']}. This might affect affinity group {group_name}.")
|
||||
continue
|
||||
|
||||
if mode == 'psi':
|
||||
logger.debug(f"Evaluating guest relocation based on {mode} mode.")
|
||||
method = proxlb_data["meta"]["balancing"].get("method", "memory")
|
||||
processed_guests_psi = proxlb_data["meta"]["balancing"].setdefault("processed_guests_psi", [])
|
||||
unprocessed_guests_psi = [guest for guest in proxlb_data["guests"].values() if guest["name"] not in processed_guests_psi]
|
||||
|
||||
# Filter by the defined methods and modes for balancing
|
||||
highest_usage_guest = max(unprocessed_guests_psi, key=lambda x: x[f"{method}_pressure_full_spikes_percent"])
|
||||
|
||||
# Append guest to the psi based processed list of guests
|
||||
if highest_usage_guest["name"] == guest_name and guest_name not in proxlb_data["meta"]["balancing"]["processed_guests_psi"]:
|
||||
proxlb_data["meta"]["balancing"]["processed_guests_psi"].append(guest_name)
|
||||
proxlb_data["meta"]["balancing"]["balance_next_guest"] = guest_name
|
||||
|
||||
else:
|
||||
logger.debug(f"Evaluating guest relocation based on {mode} mode.")
|
||||
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.")
|
||||
@@ -211,30 +446,35 @@ 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.")
|
||||
@@ -242,7 +482,40 @@ class Calculations:
|
||||
logger.debug("Finished: val_anti_affinity.")
|
||||
|
||||
@staticmethod
|
||||
def update_node_resources(proxlb_data):
|
||||
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: Dict[str, Any]):
|
||||
"""
|
||||
Updates the resource allocation and usage statistics for nodes when a guest
|
||||
is moved from one node to another.
|
||||
@@ -262,6 +535,11 @@ class Calculations:
|
||||
"""
|
||||
logger.debug("Starting: update_node_resources.")
|
||||
guest_name = proxlb_data["meta"]["balancing"]["balance_next_guest"]
|
||||
|
||||
if guest_name == "":
|
||||
logger.debug("No guest defined to update node resources for.")
|
||||
return
|
||||
|
||||
node_current = proxlb_data["guests"][guest_name]["node_current"]
|
||||
node_target = proxlb_data["meta"]["balancing"]["balance_next_node"]
|
||||
|
||||
@@ -306,3 +584,179 @@ class Calculations:
|
||||
logger.debug(f"Set guest {guest_name} from node {node_current} to node {node_target}.")
|
||||
|
||||
logger.debug("Finished: update_node_resources.")
|
||||
|
||||
def validate_affinity_map(proxlb_data: Dict[str, Any]):
|
||||
"""
|
||||
Validates the affinity and anti-affinity constraints for all guests in the ProxLB data structure.
|
||||
|
||||
This function iterates through each guest and checks both affinity and anti-affinity rules.
|
||||
If any guest violates these constraints, it sets the enforce_affinity flag to trigger rebalancing
|
||||
and skips further validation for efficiency.
|
||||
|
||||
Args:
|
||||
proxlb_data (Dict[str, Any]): A dictionary containing ProxLB configuration with the following structure:
|
||||
- "guests" (list): List of guest identifiers to validate
|
||||
- "meta" (dict): Metadata dictionary containing:
|
||||
- "balancing" (dict): Balancing configuration with "enforce_affinity" flag
|
||||
|
||||
Returns:
|
||||
None: Modifies proxlb_data in-place by updating the "enforce_affinity" flag in meta.balancing
|
||||
|
||||
Raises:
|
||||
None: Function handles validation gracefully and logs outcomes
|
||||
"""
|
||||
logger.debug("Starting: validate_current_affinity.")
|
||||
balancing_ok = True
|
||||
|
||||
for guest in proxlb_data["guests"]:
|
||||
|
||||
# We do not need to validate anymore if rebalancing is required
|
||||
if balancing_ok is False:
|
||||
proxlb_data["meta"]["balancing"]["enforce_affinity"] = True
|
||||
logger.debug(f"Rebalancing based on affinity/anti-affinity map is required. Skipping further validation...")
|
||||
break
|
||||
|
||||
balancing_state_affinity = Calculations.validate_current_affinity(proxlb_data, guest)
|
||||
balancing_state_anti_affinity = Calculations.validate_current_anti_affinity(proxlb_data, guest)
|
||||
logger.debug(f"Affinity for guest {guest} is {'valid' if balancing_state_affinity else 'NOT valid'}")
|
||||
logger.debug(f"Anti-affinity for guest {guest} is {'valid' if balancing_state_anti_affinity else 'NOT valid'}")
|
||||
|
||||
balancing_ok = balancing_state_affinity and balancing_state_anti_affinity
|
||||
|
||||
if balancing_ok:
|
||||
logger.debug(f"Rebalancing based on affinity/anti-affinity map is not required.")
|
||||
proxlb_data["meta"]["balancing"]["enforce_affinity"] = False
|
||||
|
||||
logger.debug("Finished: validate_current_affinity.")
|
||||
|
||||
@staticmethod
|
||||
def get_guest_node(proxlb_data: Dict[str, Any], guest_name: str) -> str:
|
||||
"""
|
||||
Return a currently assoicated PVE node where the guest is running on.
|
||||
|
||||
Args:
|
||||
proxlb_data (Dict[str, Any]): A dictionary containing ProxLB configuration.
|
||||
|
||||
Returns:
|
||||
node_name_current (str): The name of the current node where the guest runs on.
|
||||
|
||||
"""
|
||||
return proxlb_data["guests"][guest_name]["node_current"]
|
||||
|
||||
@staticmethod
|
||||
def validate_current_affinity(proxlb_data: Dict[str, Any], guest_name: str) -> bool:
|
||||
"""
|
||||
Validate that all guests in affinity groups containing the specified guest are on the same non-maintenance node.
|
||||
|
||||
This function checks affinity group constraints for a given guest. It ensures that:
|
||||
1. All guests within an affinity group are located on the same physical node
|
||||
2. The node hosting the affinity group is not in maintenance mode
|
||||
|
||||
Args:
|
||||
proxlb_data (Dict[str, Any]): A dictionary containing the complete ProxLB state including:
|
||||
- "groups": Dictionary with "affinity" key containing affinity group definitions
|
||||
- "guests": Dictionary with guest information
|
||||
- "nodes": Dictionary with node information including maintenance status
|
||||
guest_name (str): The name of the guest to validate affinity for
|
||||
|
||||
Returns:
|
||||
bool: True if all affinity groups containing the guest are valid (all members on same
|
||||
non-maintenance node), False otherwise
|
||||
"""
|
||||
logger.debug("Starting: validate_current_affinity.")
|
||||
for group_name, grp in proxlb_data["groups"]["affinity"].items():
|
||||
if guest_name not in grp["guests"]:
|
||||
continue
|
||||
|
||||
nodes = []
|
||||
for group in grp["guests"]:
|
||||
if group not in proxlb_data["guests"]:
|
||||
continue
|
||||
|
||||
node = Calculations.get_guest_node(proxlb_data, group)
|
||||
if proxlb_data["nodes"][node]["maintenance"]:
|
||||
logger.debug(f"Group '{group_name}' invalid: node '{node}' in maintenance.")
|
||||
return False
|
||||
nodes.append(node)
|
||||
|
||||
if len(set(nodes)) != 1:
|
||||
logger.debug(f"Group '{group_name}' invalid: guests spread across nodes {set(nodes)}.")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def validate_current_anti_affinity(proxlb_data: Dict[str, Any], guest_name: str) -> bool:
|
||||
"""
|
||||
Validate that all guests in anti-affinity groups containing the specified guest are not on the same node.
|
||||
|
||||
This function checks anti-affinity group constraints for a given guest. It ensures that:
|
||||
1. All guests within an anti-affinity group are located on the same physical node
|
||||
2. The node hosting the anti-affinity group is not in maintenance mode
|
||||
|
||||
Args:
|
||||
proxlb_data (Dict[str, Any]): A dictionary containing the complete ProxLB state including:
|
||||
- "groups": Dictionary with "affinity" key containing affinity group definitions
|
||||
- "guests": Dictionary with guest information
|
||||
- "nodes": Dictionary with node information including maintenance status
|
||||
guest_name (str): The name of the guest to validate affinity for
|
||||
|
||||
Returns:
|
||||
bool: True if all anti-affinity groups containing the guest are valid (all members on different
|
||||
non-maintenance node), False otherwise
|
||||
"""
|
||||
logger.debug("Starting: validate_current_anti_affinity.")
|
||||
for group_name, grp in proxlb_data["groups"]["anti_affinity"].items():
|
||||
if guest_name not in grp["guests"]:
|
||||
continue
|
||||
nodes = []
|
||||
for group in grp["guests"]:
|
||||
if group not in proxlb_data["guests"]:
|
||||
continue
|
||||
|
||||
node = Calculations.get_guest_node(proxlb_data, group)
|
||||
if proxlb_data["nodes"][node]["maintenance"]:
|
||||
return False
|
||||
nodes.append(node)
|
||||
|
||||
if len(nodes) != len(set(nodes)):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def validate_node_resources(proxlb_data: Dict[str, Any], guest_name: str) -> bool:
|
||||
"""
|
||||
Validate that the target node has sufficient resources to host the specified guest.
|
||||
|
||||
This function checks if the target node, determined by the balancing logic,
|
||||
has enough CPU, memory, and disk resources available to accommodate the guest.
|
||||
|
||||
Args:
|
||||
proxlb_data (Dict[str, Any]): A dictionary containing the complete ProxLB state including:
|
||||
- "nodes": Dictionary with node resource information
|
||||
- "guests": Dictionary with guest resource requirements
|
||||
- "meta": Dictionary with balancing information including target node
|
||||
guest_name (str): The name of the guest to validate resources for
|
||||
Returns:
|
||||
bool: True if the target node has sufficient resources, False otherwise
|
||||
"""
|
||||
logger.debug("Starting: validate_node_resources.")
|
||||
node_target = proxlb_data["meta"]["balancing"]["balance_next_node"]
|
||||
|
||||
node_memory_free = proxlb_data["nodes"][node_target]["memory_free"]
|
||||
node_cpu_free = proxlb_data["nodes"][node_target]["cpu_free"]
|
||||
node_disk_free = proxlb_data["nodes"][node_target]["disk_free"]
|
||||
|
||||
guest_memory_required = proxlb_data["guests"][guest_name]["memory_used"]
|
||||
guest_cpu_required = proxlb_data["guests"][guest_name]["cpu_used"]
|
||||
guest_disk_required = proxlb_data["guests"][guest_name]["disk_used"]
|
||||
|
||||
if guest_memory_required < node_memory_free:
|
||||
logger.debug(f"Node '{node_target}' has sufficient resources for guest '{guest_name}'.")
|
||||
logger.debug("Finished: validate_node_resources.")
|
||||
return True
|
||||
else:
|
||||
logger.debug(f"Node '{node_target}' lacks sufficient resources for guest '{guest_name}'.")
|
||||
logger.debug("Finished: validate_node_resources.")
|
||||
return False
|
||||
|
||||
90
proxlb/models/features.py
Normal file
90
proxlb/models/features.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
ProxLB Features module for validating and adjusting feature flags
|
||||
based on Proxmox VE node versions and cluster compatibility.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
from typing import List
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
from packaging import version
|
||||
|
||||
logger = SystemdLogger()
|
||||
|
||||
|
||||
class Features:
|
||||
"""
|
||||
ProxLB Features module for validating and adjusting feature flags
|
||||
based on Proxmox VE node versions and cluster compatibility.
|
||||
|
||||
Responsibilities:
|
||||
- Validate and adjust feature flags based on Proxmox VE node versions.
|
||||
|
||||
Methods:
|
||||
__init__():
|
||||
No-op initializer.
|
||||
|
||||
validate_available_features(proxlb_data: dict) -> None:
|
||||
Static method that inspects proxlb_data["nodes"] versions and disables
|
||||
incompatible balancing features for Proxmox VE versions < 9.0.0.
|
||||
This function mutates proxlb_data in place.
|
||||
|
||||
Notes:
|
||||
- Expects proxlb_data to be a dict with "nodes" and "meta" keys.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the Features class.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def validate_available_features(proxlb_data: any) -> None:
|
||||
"""
|
||||
Validate and adjust feature flags in the provided proxlb_data according to Proxmox VE versions.
|
||||
|
||||
This function inspects the cluster node versions in proxlb_data and disables features
|
||||
that are incompatible with Proxmox VE versions older than 9.0.0. Concretely, if any node
|
||||
reports a 'pve_version' lower than "9.0.0":
|
||||
- If meta.balancing.with_conntrack_state is truthy, it is set to False and a warning is logged.
|
||||
- If meta.balancing.mode equals "psi", meta.balancing.enable is set to False and a warning is logged.
|
||||
|
||||
proxlb_data (dict): Cluster data structure that must contain:
|
||||
- "nodes": a mapping (e.g., dict) whose values are mappings containing a 'pve_version' string.
|
||||
- "meta": a mapping that may contain a "balancing" mapping with keys:
|
||||
- "with_conntrack_state" (bool, optional)
|
||||
- "mode" (str, optional)
|
||||
- "enable" (bool, optional)
|
||||
|
||||
None: The function mutates proxlb_data in place to disable incompatible features.
|
||||
|
||||
Side effects:
|
||||
- Mutates proxlb_data["meta"]["balancing"] when incompatible features are detected.
|
||||
- Emits debug and warning log messages.
|
||||
|
||||
Notes:
|
||||
- Unexpected or missing keys/types in proxlb_data may raise KeyError or TypeError.
|
||||
- Version comparison uses semantic version parsing; callers should provide versions as strings.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
logger.debug("Starting: validate_available_features.")
|
||||
|
||||
any_non_pve9_node = any(version.parse(n['pve_version']) < version.parse("9.0.0") for n in proxlb_data["nodes"].values())
|
||||
if any_non_pve9_node:
|
||||
|
||||
with_conntrack_state = proxlb_data["meta"].get("balancing", {}).get("with_conntrack_state", False)
|
||||
if with_conntrack_state:
|
||||
logger.warning("Non Proxmox VE 9 systems detected: Deactivating migration option 'with-conntrack-state'!")
|
||||
proxlb_data["meta"]["balancing"]["with_conntrack_state"] = False
|
||||
|
||||
psi_balancing = proxlb_data["meta"].get("balancing", {}).get("mode", None)
|
||||
if psi_balancing == "psi":
|
||||
logger.warning("Non Proxmox VE 9 systems detected: Deactivating balancing!")
|
||||
proxlb_data["meta"]["balancing"]["enable"] = False
|
||||
|
||||
logger.debug("Finished: validate_available_features.")
|
||||
@@ -1,9 +1,15 @@
|
||||
"""
|
||||
The groups class is responsible for handling the correlations between the guests
|
||||
and their groups like affinity and anti-affinity groups. To ensure a proper balancing
|
||||
guests will ge grouped and then evaluated for further balancing.
|
||||
The Groups class is responsible for handling the correlations between the guests
|
||||
and their groups, such as affinity and anti-affinity groups. It ensures proper balancing
|
||||
by grouping guests and evaluating them for further balancing. The class provides methods
|
||||
to initialize with ProxLB data and to generate groups based on guest and node data.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
from utils.helper import Helper
|
||||
@@ -16,6 +22,14 @@ class Groups:
|
||||
The groups class is responsible for handling the correlations between the guests
|
||||
and their groups like affinity and anti-affinity groups. To ensure a proper balancing
|
||||
guests will ge grouped and then evaluated for further balancing.
|
||||
|
||||
Methods:
|
||||
__init__(proxlb_data: Dict[str, Any]):
|
||||
Initializes the Groups class.
|
||||
|
||||
get_groups(guests: Dict[str, Any], nodes: Dict[str, Any]) -> Dict[str, Any]:
|
||||
Generates and returns a dictionary of affinity and anti-affinity groups
|
||||
based on the provided data.
|
||||
"""
|
||||
|
||||
def __init__(self, proxlb_data: Dict[str, Any]):
|
||||
|
||||
@@ -3,9 +3,17 @@ The Guests class retrieves all running guests on the Proxmox cluster across all
|
||||
It handles both VM and CT guest types, collecting their resource metrics.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
from models.pools import Pools
|
||||
from models.ha_rules import HaRules
|
||||
from models.tags import Tags
|
||||
import time
|
||||
|
||||
logger = SystemdLogger()
|
||||
|
||||
@@ -14,6 +22,14 @@ class Guests:
|
||||
"""
|
||||
The Guests class retrieves all running guests on the Proxmox cluster across all available nodes.
|
||||
It handles both VM and CT guest types, collecting their resource metrics.
|
||||
|
||||
Methods:
|
||||
__init__:
|
||||
Initializes the Guests class.
|
||||
|
||||
get_guests(proxmox_api: any, nodes: Dict[str, Any]) -> Dict[str, Any]:
|
||||
Retrieves metrics for all running guests (both VMs and CTs) across all nodes in the Proxmox cluster.
|
||||
It collects resource metrics such as CPU, memory, and disk usage, as well as tags and affinity/anti-affinity groups.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
@@ -21,7 +37,7 @@ class Guests:
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_guests(proxmox_api: any, nodes: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def get_guests(proxmox_api: any, pools: Dict[str, Any], ha_rules: Dict[str, Any], nodes: Dict[str, Any], meta: Dict[str, Any], proxlb_config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Get metrics of all guests in a Proxmox cluster.
|
||||
|
||||
@@ -31,7 +47,11 @@ class Guests:
|
||||
|
||||
Args:
|
||||
proxmox_api (any): The Proxmox API client instance.
|
||||
pools (Dict[str, Any]): A dictionary containing information about the pools in the Proxmox cluster.
|
||||
ha_rules (Dict[str, Any]): A dictionary containing information about the HA rules in the
|
||||
nodes (Dict[str, Any]): A dictionary containing information about the nodes in the Proxmox cluster.
|
||||
meta (Dict[str, Any]): A dictionary containing metadata information.
|
||||
proxmox_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary containing metrics and information for all running guests.
|
||||
@@ -50,21 +70,42 @@ 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_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', None)
|
||||
guests['guests'][guest['name']]['cpu_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'some')
|
||||
guests['guests'][guest['name']]['cpu_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'full')
|
||||
guests['guests'][guest['name']]['cpu_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['cpu_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['cpu_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['memory_total'] = guest['maxmem']
|
||||
guests['guests'][guest['name']]['memory_used'] = guest['mem']
|
||||
guests['guests'][guest['name']]['memory_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'some')
|
||||
guests['guests'][guest['name']]['memory_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'full')
|
||||
guests['guests'][guest['name']]['memory_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['memory_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['memory_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['disk_total'] = guest['maxdisk']
|
||||
guests['guests'][guest['name']]['disk_used'] = guest['disk']
|
||||
guests['guests'][guest['name']]['disk_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'some')
|
||||
guests['guests'][guest['name']]['disk_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'full')
|
||||
guests['guests'][guest['name']]['disk_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['disk_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['disk_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['id'] = guest['vmid']
|
||||
guests['guests'][guest['name']]['node_current'] = node
|
||||
guests['guests'][guest['name']]['node_target'] = node
|
||||
guests['guests'][guest['name']]['processed'] = False
|
||||
guests['guests'][guest['name']]['pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['tags'] = Tags.get_tags_from_guests(proxmox_api, node, guest['vmid'], 'vm')
|
||||
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']]['pools'] = Pools.get_pools_for_guest(guest['name'], pools)
|
||||
guests['guests'][guest['name']]['ha_rules'] = HaRules.get_ha_rules_for_guest(guest['name'], ha_rules, guest['vmid'])
|
||||
guests['guests'][guest['name']]['affinity_groups'] = Tags.get_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
|
||||
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], guests['guests'][guest['name']]['ha_rules'], proxlb_config)
|
||||
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']]['pools'], proxlb_config)
|
||||
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.')
|
||||
|
||||
@@ -75,23 +116,97 @@ 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_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', None)
|
||||
guests['guests'][guest['name']]['cpu_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'some')
|
||||
guests['guests'][guest['name']]['cpu_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'full')
|
||||
guests['guests'][guest['name']]['cpu_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['cpu_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'cpu', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['cpu_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['memory_total'] = guest['maxmem']
|
||||
guests['guests'][guest['name']]['memory_used'] = guest['mem']
|
||||
guests['guests'][guest['name']]['memory_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'some')
|
||||
guests['guests'][guest['name']]['memory_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'full')
|
||||
guests['guests'][guest['name']]['memory_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['memory_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'memory', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['memory_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['disk_total'] = guest['maxdisk']
|
||||
guests['guests'][guest['name']]['disk_used'] = guest['disk']
|
||||
guests['guests'][guest['name']]['disk_pressure_some_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'some')
|
||||
guests['guests'][guest['name']]['disk_pressure_full_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'full')
|
||||
guests['guests'][guest['name']]['disk_pressure_some_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'some', spikes=True)
|
||||
guests['guests'][guest['name']]['disk_pressure_full_spikes_percent'] = Guests.get_guest_rrd_data(proxmox_api, node, guest['vmid'], guest['name'], 'disk', 'full', spikes=True)
|
||||
guests['guests'][guest['name']]['disk_pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['id'] = guest['vmid']
|
||||
guests['guests'][guest['name']]['node_current'] = node
|
||||
guests['guests'][guest['name']]['node_target'] = node
|
||||
guests['guests'][guest['name']]['processed'] = False
|
||||
guests['guests'][guest['name']]['pressure_hot'] = False
|
||||
guests['guests'][guest['name']]['tags'] = Tags.get_tags_from_guests(proxmox_api, node, guest['vmid'], 'ct')
|
||||
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']]['pools'] = Pools.get_pools_for_guest(guest['name'], pools)
|
||||
guests['guests'][guest['name']]['affinity_groups'] = Tags.get_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], proxlb_config)
|
||||
guests['guests'][guest['name']]['anti_affinity_groups'] = Tags.get_anti_affinity_groups(guests['guests'][guest['name']]['tags'], guests['guests'][guest['name']]['pools'], proxlb_config)
|
||||
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']]['pools'], proxlb_config)
|
||||
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_rrd_data(proxmox_api, node_name: str, vm_id: int, vm_name: str, object_name: str, object_type: str, spikes=False) -> float:
|
||||
"""
|
||||
Retrieves the rrd data metrics for a specific resource (CPU, memory, disk) of a guest VM or CT.
|
||||
|
||||
Args:
|
||||
proxmox_api (Any): The Proxmox API client instance.
|
||||
node_name (str): The name of the node hosting the guest.
|
||||
vm_id (int): The ID of the guest VM or CT.
|
||||
vm_name (str): The name of the guest VM or CT.
|
||||
object_name (str): The resource type to query (e.g., 'cpu', 'memory', 'disk').
|
||||
object_type (str, optional): The pressure type ('some', 'full') or None for average usage.
|
||||
spikes (bool, optional): Whether to consider spikes in the calculation. Defaults to False.
|
||||
|
||||
Returns:
|
||||
float: The calculated average usage value for the specified resource.
|
||||
"""
|
||||
logger.debug("Starting: get_guest_rrd_data.")
|
||||
time.sleep(0.1)
|
||||
|
||||
try:
|
||||
if spikes:
|
||||
logger.debug(f"Getting spike RRD data for {object_name} from guest: {vm_name}.")
|
||||
guest_data_rrd = proxmox_api.nodes(node_name).qemu(vm_id).rrddata.get(timeframe="hour", cf="MAX")
|
||||
else:
|
||||
logger.debug(f"Getting average RRD data for {object_name} from 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 value.")
|
||||
logger.debug("Finished: get_guest_rrd_data.")
|
||||
return float(0.0)
|
||||
|
||||
if object_type:
|
||||
|
||||
lookup_key = f"pressure{object_name}{object_type}"
|
||||
if spikes:
|
||||
# RRD data is collected every minute, so we look at the last 6 entries
|
||||
# and take the maximum value to represent the spike
|
||||
logger.debug(f"Getting RRD data (spike: {spikes}) of pressure for {object_name} {object_type} from guest: {vm_name}.")
|
||||
rrd_data_value = [row.get(lookup_key) for row in guest_data_rrd if row.get(lookup_key) is not None]
|
||||
rrd_data_value = max(rrd_data_value[-6:], default=0.0)
|
||||
else:
|
||||
# Calculate the average value from the RRD data entries
|
||||
logger.debug(f"Getting RRD data (spike: {spikes}) of pressure for {object_name} {object_type} from guest: {vm_name}.")
|
||||
rrd_data_value = sum(entry.get(lookup_key, 0.0) for entry in guest_data_rrd) / len(guest_data_rrd)
|
||||
|
||||
else:
|
||||
logger.debug(f"Getting RRD data of cpu usage from guest: {vm_name}.")
|
||||
rrd_data_value = sum(entry.get("cpu", 0.0) for entry in guest_data_rrd) / len(guest_data_rrd)
|
||||
|
||||
logger.debug(f"RRD data (spike: {spikes}) for {object_name} from guest: {vm_name}: {rrd_data_value}")
|
||||
logger.debug("Finished: get_guest_rrd_data.")
|
||||
return rrd_data_value
|
||||
|
||||
106
proxlb/models/ha_rules.py
Normal file
106
proxlb/models/ha_rules.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""
|
||||
The HaRules class retrieves all HA rules defined on a Proxmox cluster
|
||||
including their affinity settings and member resources.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
|
||||
logger = SystemdLogger()
|
||||
|
||||
|
||||
class HaRules:
|
||||
"""
|
||||
The HaRules class retrieves all HA rules defined on a Proxmox cluster
|
||||
including their (anti)a-ffinity settings and member resources and translates
|
||||
them into a ProxLB usable format.
|
||||
|
||||
Methods:
|
||||
__init__:
|
||||
Initializes the HaRules class.
|
||||
|
||||
get_ha_rules(proxmox_api: any) -> Dict[str, Any]:
|
||||
Retrieve HA rule definitions from the Proxmox cluster.
|
||||
Returns a dict with a top-level "ha_rules" mapping each rule id to
|
||||
{"rule": <rule_id>, "type": <affinity_type>, "members": [<resource_ids>...]}.
|
||||
Converts affinity settings to descriptive format (affinity or anti-affinity).
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the HA Rules class with the provided ProxLB data.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_ha_rules(proxmox_api: any) -> Dict[str, Any]:
|
||||
"""
|
||||
Retrieve all HA rules from a Proxmox cluster.
|
||||
|
||||
Queries the Proxmox API for HA rule definitions and returns a dictionary
|
||||
containing each rule's id, affinity type, and member resources (VM/CT IDs).
|
||||
This function processes rule affinity settings and converts them to a more
|
||||
descriptive format (affinity or anti-affinity).
|
||||
|
||||
Args:
|
||||
proxmox_api (any): Proxmox API client instance.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Dictionary with a top-level "ha_rules" key mapping rule id
|
||||
to {"rule": <rule_id>, "type": <affinity_type>, "members": [<resource_ids>...]}.
|
||||
"""
|
||||
logger.debug("Starting: get_ha_rules.")
|
||||
ha_rules = {"ha_rules": {}}
|
||||
|
||||
for rule in proxmox_api.cluster.ha.rules.get():
|
||||
# Create a resource list by splitting on commas and stripping whitespace containing
|
||||
# the VM and CT IDs that are part of this HA rule
|
||||
resources_list = [int(r.split(":")[1]) for r in rule["resources"].split(",") if r.strip()]
|
||||
|
||||
# Convert the affinity field to a more descriptive type
|
||||
if rule.get("affinity", None) == "negative":
|
||||
affinity_type = "anti-affinity"
|
||||
else:
|
||||
affinity_type = "affinity"
|
||||
|
||||
# Create the ha_rule element
|
||||
ha_rules['ha_rules'][rule['rule']] = {}
|
||||
ha_rules['ha_rules'][rule['rule']]['rule'] = rule['rule']
|
||||
ha_rules['ha_rules'][rule['rule']]['type'] = affinity_type
|
||||
ha_rules['ha_rules'][rule['rule']]['members'] = resources_list
|
||||
|
||||
logger.debug(f"Got ha-rule: {rule['rule']} as type {affinity_type} affecting guests: {rule['resources']}")
|
||||
|
||||
logger.debug("Finished: ha_rules.")
|
||||
return ha_rules
|
||||
|
||||
@staticmethod
|
||||
def get_ha_rules_for_guest(guest_name: str, ha_rules: Dict[str, Any], vm_id: int) -> Dict[str, Any]:
|
||||
"""
|
||||
Return the list of HA rules that include the given guest.
|
||||
|
||||
Args:
|
||||
guest_name (str): Name of the VM or CT to look up.
|
||||
ha_rules (Dict[str, Any]): HA rules structure as returned by get_ha_rules(),
|
||||
expected to contain a top-level "ha_rules" mapping each rule id to
|
||||
{"rule": <rule_id>, "type": <affinity_type>, "members": [<resource_ids>...]}.
|
||||
vm_id (int): VM or CT ID of the guest.
|
||||
|
||||
Returns:
|
||||
list: IDs of HA rules the guest is a member of (empty list if none).
|
||||
"""
|
||||
logger.debug("Starting: get_ha_rules_for_guest.")
|
||||
guest_ha_rules = []
|
||||
|
||||
for rule in ha_rules["ha_rules"].values():
|
||||
if vm_id in rule.get("members", []):
|
||||
logger.debug(f"Guest: {guest_name} (VMID: {vm_id}) is member of HA Rule: {rule['rule']}.")
|
||||
guest_ha_rules.append(rule)
|
||||
else:
|
||||
logger.debug(f"Guest: {guest_name} (VMID: {vm_id}) is NOT member of HA Rule: {rule['rule']}.")
|
||||
|
||||
logger.debug("Finished: get_ha_rules_for_guest.")
|
||||
return guest_ha_rules
|
||||
@@ -1,8 +1,27 @@
|
||||
"""
|
||||
The Nodes class retrieves all running nodes in a Proxmox cluster
|
||||
and collects their resource metrics.
|
||||
|
||||
Methods:
|
||||
__init__:
|
||||
Initializes the Nodes class.
|
||||
|
||||
get_nodes(proxmox_api: any, proxlb_config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
Gets metrics of all nodes in a Proxmox cluster.
|
||||
|
||||
set_node_maintenance(proxlb_config: Dict[str, Any], node_name: str) -> Dict[str, Any]:
|
||||
Sets Proxmox nodes to a maintenance mode if required.
|
||||
|
||||
set_node_ignore(proxlb_config: Dict[str, Any], node_name: str) -> Dict[str, Any]:
|
||||
Sets Proxmox nodes to be ignored if requested.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
import time
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
|
||||
@@ -29,6 +48,7 @@ class Nodes:
|
||||
|
||||
Args:
|
||||
proxmox_api (any): The Proxmox API client instance.
|
||||
proxmox_config (Dict[str, Any]): A dictionary containing the ProxLB configuration.
|
||||
nodes (Dict[str, Any]): A dictionary containing information about the nodes in the Proxmox cluster.
|
||||
|
||||
Returns:
|
||||
@@ -42,14 +62,21 @@ class Nodes:
|
||||
if node["status"] == "online" and not Nodes.set_node_ignore(proxlb_config, node["node"]):
|
||||
nodes["nodes"][node["node"]] = {}
|
||||
nodes["nodes"][node["node"]]["name"] = node["node"]
|
||||
nodes["nodes"][node["node"]]["pve_version"] = Nodes.get_node_pve_version(proxmox_api, node["node"])
|
||||
nodes["nodes"][node["node"]]["pressure_hot"] = False
|
||||
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
|
||||
nodes["nodes"][node["node"]]["cpu_used_percent"] = nodes["nodes"][node["node"]]["cpu_used"] / node["maxcpu"] * 100
|
||||
nodes["nodes"][node["node"]]["cpu_pressure_some_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "cpu", "some")
|
||||
nodes["nodes"][node["node"]]["cpu_pressure_full_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "cpu", "full")
|
||||
nodes["nodes"][node["node"]]["cpu_pressure_some_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "cpu", "some", spikes=True)
|
||||
nodes["nodes"][node["node"]]["cpu_pressure_full_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "cpu", "full", spikes=True)
|
||||
nodes["nodes"][node["node"]]["cpu_pressure_hot"] = False
|
||||
nodes["nodes"][node["node"]]["memory_total"] = node["maxmem"]
|
||||
nodes["nodes"][node["node"]]["memory_assigned"] = 0
|
||||
nodes["nodes"][node["node"]]["memory_used"] = node["mem"]
|
||||
@@ -57,6 +84,11 @@ class Nodes:
|
||||
nodes["nodes"][node["node"]]["memory_assigned_percent"] = nodes["nodes"][node["node"]]["memory_assigned"] / nodes["nodes"][node["node"]]["memory_total"] * 100
|
||||
nodes["nodes"][node["node"]]["memory_free_percent"] = nodes["nodes"][node["node"]]["memory_free"] / node["maxmem"] * 100
|
||||
nodes["nodes"][node["node"]]["memory_used_percent"] = nodes["nodes"][node["node"]]["memory_used"] / node["maxmem"] * 100
|
||||
nodes["nodes"][node["node"]]["memory_pressure_some_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "memory", "some")
|
||||
nodes["nodes"][node["node"]]["memory_pressure_full_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "memory", "full")
|
||||
nodes["nodes"][node["node"]]["memory_pressure_some_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "memory", "some", spikes=True)
|
||||
nodes["nodes"][node["node"]]["memory_pressure_full_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "memory", "full", spikes=True)
|
||||
nodes["nodes"][node["node"]]["memory_pressure_hot"] = False
|
||||
nodes["nodes"][node["node"]]["disk_total"] = node["maxdisk"]
|
||||
nodes["nodes"][node["node"]]["disk_assigned"] = 0
|
||||
nodes["nodes"][node["node"]]["disk_used"] = node["disk"]
|
||||
@@ -64,16 +96,22 @@ class Nodes:
|
||||
nodes["nodes"][node["node"]]["disk_assigned_percent"] = nodes["nodes"][node["node"]]["disk_assigned"] / nodes["nodes"][node["node"]]["disk_total"] * 100
|
||||
nodes["nodes"][node["node"]]["disk_free_percent"] = nodes["nodes"][node["node"]]["disk_free"] / node["maxdisk"] * 100
|
||||
nodes["nodes"][node["node"]]["disk_used_percent"] = nodes["nodes"][node["node"]]["disk_used"] / node["maxdisk"] * 100
|
||||
nodes["nodes"][node["node"]]["disk_pressure_some_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "disk", "some")
|
||||
nodes["nodes"][node["node"]]["disk_pressure_full_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "disk", "full")
|
||||
nodes["nodes"][node["node"]]["disk_pressure_some_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "disk", "some", spikes=True)
|
||||
nodes["nodes"][node["node"]]["disk_pressure_full_spikes_percent"] = Nodes.get_node_rrd_data(proxmox_api, node["node"], "disk", "full", spikes=True)
|
||||
nodes["nodes"][node["node"]]["disk_pressure_hot"] = False
|
||||
|
||||
# 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(f"Node metrics collected: {nodes}")
|
||||
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.
|
||||
|
||||
@@ -81,6 +119,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.
|
||||
|
||||
@@ -89,11 +128,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.")
|
||||
|
||||
@@ -117,7 +169,87 @@ 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.")
|
||||
|
||||
@staticmethod
|
||||
def get_node_rrd_data(proxmox_api, node_name: str, object_name: str, object_type: str, spikes=False) -> float:
|
||||
"""
|
||||
Retrieves the rrd data metrics for a specific resource (CPU, memory, disk) of a node.
|
||||
|
||||
Args:
|
||||
proxmox_api (Any): The Proxmox API client instance.
|
||||
node_name (str): The name of the node hosting the guest.
|
||||
object_name (str): The resource type to query (e.g., 'cpu', 'memory', 'disk').
|
||||
object_type (str, optional): The pressure type ('some', 'full') or None for average usage.
|
||||
spikes (bool, optional): Whether to consider spikes in the calculation. Defaults to False.
|
||||
|
||||
Returns:
|
||||
float: The calculated average usage value for the specified resource.
|
||||
"""
|
||||
logger.debug("Starting: get_node_rrd_data.")
|
||||
time.sleep(0.1)
|
||||
|
||||
try:
|
||||
if spikes:
|
||||
logger.debug(f"Getting spike RRD data for {object_name} from node: {node_name}.")
|
||||
node_data_rrd = proxmox_api.nodes(node_name).rrddata.get(timeframe="hour", cf="MAX")
|
||||
else:
|
||||
logger.debug(f"Getting average RRD data for {object_name} from node: {node_name}.")
|
||||
node_data_rrd = proxmox_api.nodes(node_name).rrddata.get(timeframe="hour", cf="AVERAGE")
|
||||
|
||||
except Exception:
|
||||
logger.error(f"Failed to retrieve RRD data for guest: {node_name}. Using 0.0 as value.")
|
||||
logger.debug("Finished: get_node_rrd_data.")
|
||||
return 0.0
|
||||
|
||||
lookup_key = f"pressure{object_name}{object_type}"
|
||||
|
||||
if spikes:
|
||||
# RRD data is collected every minute, so we look at the last 6 entries
|
||||
# and take the maximum value to represent the spike
|
||||
rrd_data_value = [row.get(lookup_key) for row in node_data_rrd if row.get(lookup_key) is not None]
|
||||
rrd_data_value = max(rrd_data_value[-6:], default=0.0)
|
||||
else:
|
||||
# Calculate the average value from the RRD data entries
|
||||
rrd_data_value = sum(entry.get(lookup_key, 0.0) for entry in node_data_rrd) / len(node_data_rrd)
|
||||
|
||||
logger.debug(f"RRD data (spike: {spikes}) for {object_name} from node: {node_name}: {rrd_data_value}")
|
||||
logger.debug("Finished: get_node_rrd_data.")
|
||||
return rrd_data_value
|
||||
|
||||
@staticmethod
|
||||
def get_node_pve_version(proxmox_api, node_name: str) -> float:
|
||||
"""
|
||||
Return the Proxmox VE (PVE) version for a given node by querying the Proxmox API.
|
||||
|
||||
This function calls proxmox_api.nodes(node_name).version.get() and extracts the
|
||||
'version' field from the returned mapping. The value is expected to be numeric
|
||||
(or convertible to float) and is returned as a float.
|
||||
|
||||
Args:
|
||||
proxmox_api (Any): The Proxmox API client instance.
|
||||
node_name (str): The name of the node hosting the guest.
|
||||
|
||||
Returns:
|
||||
float: The PVE version for the specified node as a floating point number.
|
||||
|
||||
Raises:
|
||||
Exception: If the proxmox_api call fails, returns an unexpected structure, or the
|
||||
'version' field is missing or cannot be converted to float. Callers should
|
||||
handle or propagate exceptions as appropriate.
|
||||
"""
|
||||
logger.debug("Starting: get_node_pve_version.")
|
||||
time.sleep(0.1)
|
||||
|
||||
try:
|
||||
logger.debug(f"Trying to get PVE version for node: {node_name}.")
|
||||
version = proxmox_api.nodes(node_name).version.get()
|
||||
except Exception:
|
||||
logger.error(f"Failed to get PVE version for node: {node_name}.")
|
||||
|
||||
logger.debug(f"Got version {version['version']} for node {node_name}.")
|
||||
logger.debug("Finished: get_node_pve_version.")
|
||||
return version["version"]
|
||||
|
||||
117
proxlb/models/pools.py
Normal file
117
proxlb/models/pools.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""
|
||||
The Pools class retrieves all present pools defined on a Proxmox cluster
|
||||
including the chield objects.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
|
||||
from typing import Dict, Any
|
||||
from utils.logger import SystemdLogger
|
||||
from models.tags import Tags
|
||||
import time
|
||||
|
||||
logger = SystemdLogger()
|
||||
|
||||
|
||||
class Pools:
|
||||
"""
|
||||
The Pools class retrieves all present pools defined on a Proxmox cluster
|
||||
including the chield objects.
|
||||
|
||||
Methods:
|
||||
__init__:
|
||||
Initializes the Pools class.
|
||||
|
||||
get_pools(proxmox_api: any) -> Dict[str, Any]:
|
||||
Retrieve pool definitions and membership from the Proxmox cluster.
|
||||
Returns a dict with a top-level "pools" mapping each poolid to
|
||||
{"name": <poolid>, "members": [<member_names>...]}.
|
||||
This method does not collect per-member metrics or perform node filtering.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the Pools class with the provided ProxLB data.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_pools(proxmox_api: any) -> Dict[str, Any]:
|
||||
"""
|
||||
Retrieve all pools and their members from a Proxmox cluster.
|
||||
|
||||
Queries the Proxmox API for pool definitions and returns a dictionary
|
||||
containing each pool's id/name and a list of its member VM/CT names.
|
||||
This function does not perform per-member metric collection or node
|
||||
filtering — it only gathers pool membership information.
|
||||
|
||||
Args:
|
||||
proxmox_api (any): Proxmox API client instance.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Dictionary with a top-level "pools" key mapping poolid
|
||||
to {"name": <poolid>, "members": [<member_names>...]}.
|
||||
"""
|
||||
logger.debug("Starting: get_pools.")
|
||||
pools = {"pools": {}}
|
||||
|
||||
# Pool objects: iterate over all pools in the cluster.
|
||||
# We keep pool members even if their nodes are ignored so resource accounting
|
||||
# for rebalancing remains correct and we avoid overprovisioning nodes.
|
||||
for pool in proxmox_api.pools.get():
|
||||
logger.debug(f"Got pool: {pool['poolid']}")
|
||||
pools['pools'][pool['poolid']] = {}
|
||||
pools['pools'][pool['poolid']]['name'] = pool['poolid']
|
||||
pools['pools'][pool['poolid']]['members'] = []
|
||||
|
||||
# Fetch pool details and collect member names
|
||||
pool_details = proxmox_api.pools(pool['poolid']).get()
|
||||
for member in pool_details.get("members", []):
|
||||
|
||||
# We might also have objects without the key "name", e.g. storage pools
|
||||
if "name" not in member:
|
||||
logger.debug(f"Skipping member without name in pool: {pool['poolid']}")
|
||||
continue
|
||||
|
||||
logger.debug(f"Got member: {member['name']} for pool: {pool['poolid']}")
|
||||
pools['pools'][pool['poolid']]['members'].append(member["name"])
|
||||
|
||||
logger.debug("Finished: get_pools.")
|
||||
return pools
|
||||
|
||||
@staticmethod
|
||||
def get_pools_for_guest(guest_name: str, pools: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Return the list of pool names that include the given guest.
|
||||
|
||||
Args:
|
||||
guest_name (str): Name of the VM or CT to look up.
|
||||
pools (Dict[str, Any]): Pools structure as returned by get_pools(),
|
||||
expected to contain a top-level "pools" mapping each poolid to
|
||||
{"name": <poolid>, "members": [<member_names>...]}.
|
||||
|
||||
Returns:
|
||||
list[str]: Names of pools the guest is a member of (empty list if none).
|
||||
"""
|
||||
logger.debug("Starting: get_pools_for_guests.")
|
||||
guest_pools = []
|
||||
|
||||
for pool in pools.items():
|
||||
for pool_id, pool_data in pool[1].items():
|
||||
|
||||
if type(pool_data) is dict:
|
||||
pool_name = pool_data.get("name", "")
|
||||
pool_name_members = pool_data.get("members", [])
|
||||
|
||||
if guest_name in pool_name_members:
|
||||
logger.debug(f"Guest: {guest_name} is member of Pool: {pool_name}.")
|
||||
guest_pools.append(pool_name)
|
||||
else:
|
||||
logger.debug(f"Guest: {guest_name} is NOT member of Pool: {pool_name}.")
|
||||
|
||||
else:
|
||||
logger.debug(f"Pool data for pool_id {pool_id} is not a dict: {pool_data}")
|
||||
|
||||
logger.debug("Finished: get_pools_for_guests.")
|
||||
return guest_pools
|
||||
@@ -1,25 +1,50 @@
|
||||
"""
|
||||
The Tags class retrieves all tags from guests of the type VM or CT running
|
||||
in a Proxmox cluster and validates for affinity, anti-affinity and ignore
|
||||
tags set for the guest in the Proxmox API.
|
||||
The Tags class retrieves and processes tags from guests of type VM or CT running
|
||||
in a Proxmox cluster. It provides methods to fetch tags from the Proxmox API and
|
||||
evaluate them for affinity, anti-affinity, and ignore tags, which are used during
|
||||
balancing calculations.
|
||||
"""
|
||||
|
||||
__author__ = "Florian Paul Azim Hoberg <gyptazy>"
|
||||
__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)"
|
||||
__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()
|
||||
|
||||
|
||||
class Tags:
|
||||
"""
|
||||
The Tags class retrieves all tags from guests of the type VM or CT running
|
||||
in a Proxmox cluster and validates for affinity, anti-affinity and ignore
|
||||
tags set for the guest in the Proxmox API.
|
||||
The Tags class retrieves and processes tags from guests of type VM or CT running
|
||||
in a Proxmox cluster. It provides methods to fetch tags from the Proxmox API and
|
||||
evaluate them for affinity, anti-affinity, and ignore tags, which are used during
|
||||
balancing calculations.
|
||||
|
||||
Methods:
|
||||
__init__:
|
||||
Initializes the Tags class.
|
||||
|
||||
get_tags_from_guests(proxmox_api: any, node: str, guest_id: int, guest_type: str) -> List[str]:
|
||||
Retrieves all tags for a given guest from the Proxmox API.
|
||||
|
||||
get_affinity_groups(tags: List[str]) -> List[str]:
|
||||
Evaluates and returns all affinity tags from the provided list of tags.
|
||||
|
||||
get_anti_affinity_groups(tags: List[str]) -> List[str]:
|
||||
Evaluates and returns all anti-affinity tags from the provided list of tags.
|
||||
|
||||
get_ignore(tags: List[str]) -> bool:
|
||||
Evaluates and returns a boolean indicating whether the guest should be ignored based on the provided list of tags.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the Tags class.
|
||||
Initializes the tags class.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@@ -55,15 +80,18 @@ class Tags:
|
||||
return tags
|
||||
|
||||
@staticmethod
|
||||
def get_affinity_groups(tags: List[str]) -> List[str]:
|
||||
def get_affinity_groups(tags: List[str], pools: List[str], ha_rules: List[str], proxlb_config: Dict[str, Any]) -> List[str]:
|
||||
"""
|
||||
Get affinity tags for a guest from the Proxmox cluster by the API.
|
||||
|
||||
This method retrieves all tags for a given guest and evaluates the
|
||||
affinity tags which are required during the balancing calculations.
|
||||
This method retrieves all tags for a given guest or based on a
|
||||
membership of a pool and evaluates the affinity groups which are
|
||||
required during the balancing calculations.
|
||||
|
||||
Args:
|
||||
tags (List): A list holding all defined tags for a given guest.
|
||||
pools (List): A list holding all defined pools for a given guest.
|
||||
proxlb_config (Dict): A dict holding the ProxLB configuration.
|
||||
|
||||
Returns:
|
||||
List: A list including all affinity tags for the given guest.
|
||||
@@ -71,24 +99,48 @@ class Tags:
|
||||
logger.debug("Starting: get_affinity_groups.")
|
||||
affinity_tags = []
|
||||
|
||||
# Tag based affinity groups
|
||||
if len(tags) > 0:
|
||||
for tag in tags:
|
||||
if tag.startswith("plb_affinity"):
|
||||
logger.debug(f"Adding affinity group for tag {tag}.")
|
||||
affinity_tags.append(tag)
|
||||
else:
|
||||
logger.debug(f"Skipping affinity group for tag {tag}.")
|
||||
|
||||
# Pool based affinity groups
|
||||
if len(pools) > 0:
|
||||
for pool in pools:
|
||||
if pool in (proxlb_config['balancing'].get('pools') or {}):
|
||||
if proxlb_config['balancing']['pools'][pool].get('type', None) == 'affinity':
|
||||
logger.debug(f"Adding affinity group for pool {pool}.")
|
||||
affinity_tags.append(pool)
|
||||
else:
|
||||
logger.debug(f"Skipping affinity group for pool {pool}.")
|
||||
|
||||
# HA rule based affinity groups
|
||||
if len(ha_rules) > 0:
|
||||
for ha_rule in ha_rules:
|
||||
if ha_rule.get('type', None) == 'affinity':
|
||||
logger.debug(f"Adding affinity group for ha-rule {ha_rule}.")
|
||||
affinity_tags.append(ha_rule['rule'])
|
||||
|
||||
logger.debug("Finished: get_affinity_groups.")
|
||||
return affinity_tags
|
||||
|
||||
@staticmethod
|
||||
def get_anti_affinity_groups(tags: List[str]) -> List[str]:
|
||||
def get_anti_affinity_groups(tags: List[str], pools: List[str], ha_rules: List[str], proxlb_config: Dict[str, Any]) -> List[str]:
|
||||
"""
|
||||
Get anti-affinity tags for a guest from the Proxmox cluster by the API.
|
||||
|
||||
This method retrieves all tags for a given guest and evaluates the
|
||||
anti-affinity tags which are required during the balancing calculations.
|
||||
This method retrieves all tags for a given guest or based on a
|
||||
membership of a pool and evaluates the anti-affinity groups which
|
||||
are required during the balancing calculations.
|
||||
|
||||
Args:
|
||||
tags (List): A list holding all defined tags for a given guest.
|
||||
pools (List): A list holding all defined pools for a given guest.
|
||||
proxlb_config (Dict): A dict holding the ProxLB configuration.
|
||||
|
||||
Returns:
|
||||
List: A list including all anti-affinity tags for the given guest..
|
||||
@@ -96,10 +148,31 @@ class Tags:
|
||||
logger.debug("Starting: get_anti_affinity_groups.")
|
||||
anti_affinity_tags = []
|
||||
|
||||
# Tag based anti-affinity groups
|
||||
if len(tags) > 0:
|
||||
for tag in tags:
|
||||
if tag.startswith("plb_anti_affinity"):
|
||||
logger.debug(f"Adding anti-affinity group for tag {tag}.")
|
||||
anti_affinity_tags.append(tag)
|
||||
else:
|
||||
logger.debug(f"Skipping anti-affinity group for tag {tag}.")
|
||||
|
||||
# Pool based anti-affinity groups
|
||||
if len(pools) > 0:
|
||||
for pool in pools:
|
||||
if pool in (proxlb_config['balancing'].get('pools') or {}):
|
||||
if proxlb_config['balancing']['pools'][pool].get('type', None) == 'anti-affinity':
|
||||
logger.debug(f"Adding anti-affinity group for pool {pool}.")
|
||||
anti_affinity_tags.append(pool)
|
||||
else:
|
||||
logger.debug(f"Skipping anti-affinity group for pool {pool}.")
|
||||
|
||||
# HA rule based anti-affinity groups
|
||||
if len(ha_rules) > 0:
|
||||
for ha_rule in ha_rules:
|
||||
if ha_rule.get('type', None) == 'anti-affinity':
|
||||
logger.debug(f"Adding anti-affinity group for ha-rule {ha_rule}.")
|
||||
anti_affinity_tags.append(ha_rule['rule'])
|
||||
|
||||
logger.debug("Finished: get_anti_affinity_groups.")
|
||||
return anti_affinity_tags
|
||||
@@ -116,7 +189,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
|
||||
@@ -128,3 +201,57 @@ class Tags:
|
||||
|
||||
logger.debug("Finished: get_ignore.")
|
||||
return ignore_tag
|
||||
|
||||
@staticmethod
|
||||
def get_node_relationships(tags: List[str], nodes: Dict[str, Any], pools: List[str], proxlb_config: 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 or by defined pools from ProxLB configuration.
|
||||
|
||||
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.
|
||||
pools (List): A list holding all defined pools for a given guest.
|
||||
proxlb_config (Dict): A dict holding the ProxLB configuration.
|
||||
|
||||
Returns:
|
||||
Str: The related hypervisor node name(s).
|
||||
"""
|
||||
logger.debug("Starting: get_node_relationships.")
|
||||
node_relationship_tags = []
|
||||
|
||||
if len(tags) > 0:
|
||||
logger.debug("Validating node pinning by tags.")
|
||||
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.debug(f"Tag {node_relationship_tag} is valid! Defined node exists in the cluster.")
|
||||
logger.debug(f"Setting node relationship because of tag {tag} to {node_relationship_tag}.")
|
||||
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.")
|
||||
|
||||
if len(pools) > 0:
|
||||
logger.debug("Validating node pinning by pools.")
|
||||
for pool in pools:
|
||||
if pool in (proxlb_config['balancing'].get('pools') or {}):
|
||||
|
||||
node = proxlb_config['balancing']['pools'][pool].get('pin', None)
|
||||
# Validate if the node to pin is present in the cluster
|
||||
if Helper.validate_node_presence(node, nodes):
|
||||
logger.debug(f"Pool pinning tag {node} is valid! Defined node exists in the cluster.")
|
||||
logger.debug(f"Setting node relationship because of pool {pool} to {node}.")
|
||||
node_relationship_tags.append(node)
|
||||
else:
|
||||
logger.warning(f"Pool pinning tag {node} is invalid! Defined node does not exist in the cluster. Not applying pinning.")
|
||||
else:
|
||||
logger.debug(f"Skipping pinning for pool {pool}. Pool is not defined in ProxLB configuration.")
|
||||
|
||||
logger.debug("Finished: get_node_relationships.")
|
||||
return node_relationship_tags
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user