|
| 1 | +""" |
| 2 | +ProxLB Features module for validating and adjusting feature flags |
| 3 | +based on Proxmox VE node versions and cluster compatibility. |
| 4 | +""" |
| 5 | + |
| 6 | +__author__ = "Florian Paul Azim Hoberg <gyptazy>" |
| 7 | +__copyright__ = "Copyright (C) 2025 Florian Paul Azim Hoberg (@gyptazy)" |
| 8 | +__license__ = "GPL-3.0" |
| 9 | + |
| 10 | + |
| 11 | +from typing import List |
| 12 | +from typing import Dict, Any |
| 13 | +from utils.logger import SystemdLogger |
| 14 | +from packaging import version |
| 15 | + |
| 16 | +logger = SystemdLogger() |
| 17 | + |
| 18 | + |
| 19 | +class Features: |
| 20 | + """ |
| 21 | + ProxLB Features module for validating and adjusting feature flags |
| 22 | + based on Proxmox VE node versions and cluster compatibility. |
| 23 | +
|
| 24 | + Responsibilities: |
| 25 | + - Validate and adjust feature flags based on Proxmox VE node versions. |
| 26 | +
|
| 27 | + Methods: |
| 28 | + __init__(): |
| 29 | + No-op initializer. |
| 30 | +
|
| 31 | + validate_available_features(proxlb_data: dict) -> None: |
| 32 | + Static method that inspects proxlb_data["nodes"] versions and disables |
| 33 | + incompatible balancing features for Proxmox VE versions < 9.0.0. |
| 34 | + This function mutates proxlb_data in place. |
| 35 | +
|
| 36 | + Notes: |
| 37 | + - Expects proxlb_data to be a dict with "nodes" and "meta" keys. |
| 38 | + """ |
| 39 | + def __init__(self): |
| 40 | + """ |
| 41 | + Initializes the Features class. |
| 42 | + """ |
| 43 | + |
| 44 | + @staticmethod |
| 45 | + def validate_available_features(proxlb_data: any) -> None: |
| 46 | + """ |
| 47 | + Validate and adjust feature flags in the provided proxlb_data according to Proxmox VE versions. |
| 48 | +
|
| 49 | + This function inspects the cluster node versions in proxlb_data and disables features |
| 50 | + that are incompatible with Proxmox VE versions older than 9.0.0. Concretely, if any node |
| 51 | + reports a 'pve_version' lower than "9.0.0": |
| 52 | + - If meta.balancing.with_conntrack_state is truthy, it is set to False and a warning is logged. |
| 53 | + - If meta.balancing.mode equals "psi", meta.balancing.enable is set to False and a warning is logged. |
| 54 | +
|
| 55 | + proxlb_data (dict): Cluster data structure that must contain: |
| 56 | + - "nodes": a mapping (e.g., dict) whose values are mappings containing a 'pve_version' string. |
| 57 | + - "meta": a mapping that may contain a "balancing" mapping with keys: |
| 58 | + - "with_conntrack_state" (bool, optional) |
| 59 | + - "mode" (str, optional) |
| 60 | + - "enable" (bool, optional) |
| 61 | +
|
| 62 | + None: The function mutates proxlb_data in place to disable incompatible features. |
| 63 | +
|
| 64 | + Side effects: |
| 65 | + - Mutates proxlb_data["meta"]["balancing"] when incompatible features are detected. |
| 66 | + - Emits debug and warning log messages. |
| 67 | +
|
| 68 | + Notes: |
| 69 | + - Unexpected or missing keys/types in proxlb_data may raise KeyError or TypeError. |
| 70 | + - Version comparison uses semantic version parsing; callers should provide versions as strings. |
| 71 | +
|
| 72 | + Returns: |
| 73 | + None |
| 74 | + """ |
| 75 | + logger.debug("Starting: validate_available_features.") |
| 76 | + |
| 77 | + any_non_pve9_node = any(version.parse(n['pve_version']) < version.parse("9.0.0") for n in proxlb_data["nodes"].values()) |
| 78 | + if any_non_pve9_node: |
| 79 | + |
| 80 | + with_conntrack_state = proxlb_data["meta"].get("balancing", {}).get("with_conntrack_state", False) |
| 81 | + if with_conntrack_state: |
| 82 | + logger.warning("Non Proxmox VE 9 systems detected: Deactivating migration option 'with-conntrack-state'!") |
| 83 | + proxlb_data["meta"]["balancing"]["with_conntrack_state"] = False |
| 84 | + |
| 85 | + psi_balancing = proxlb_data["meta"].get("balancing", {}).get("mode", None) |
| 86 | + if psi_balancing == "psi": |
| 87 | + logger.warning("Non Proxmox VE 9 systems detected: Deactivating balancing!") |
| 88 | + proxlb_data["meta"]["balancing"]["enable"] = False |
| 89 | + |
| 90 | + logger.debug("Finished: validate_available_features.") |
0 commit comments