mirror of
https://github.com/gyptazy/ProxLB.git
synced 2026-04-05 20:31:57 +02:00
Merge pull request #175 from gyptazy/feature/168-add-more-flexible-schedule-timers
feature: Add a more flexible way to define schedules directly in minutes or hours
This commit is contained in:
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]
|
||||
65
README.md
65
README.md
@@ -231,35 +231,38 @@ See also: [#65: Host groups: Honour HA groups](https://github.com/gyptazy/ProxLB
|
||||
### Options
|
||||
The following options can be set in the configuration file `proxlb.yaml`:
|
||||
|
||||
| Section | Option | Example | Type | Description |
|
||||
|------|:------:|:------:|:------:|:------:|
|
||||
| `proxmox_api` | | | | |
|
||||
| | hosts | ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe'] | `List` | List of Proxmox nodes. Can be IPv4, IPv6 or mixed. |
|
||||
| | user | root@pam | `Str` | Username for the API. |
|
||||
| | pass | FooBar | `Str` | Password for the API. (Recommended: Use API token authorization!) |
|
||||
| | token_id | proxlb | `Str` | Token ID of the user for the API. |
|
||||
| | token_secret | 430e308f-1337-1337-beef-1337beefcafe | `Str` | Secret of the token ID for the API. |
|
||||
| | ssl_verification | True | `Bool` | Validate SSL certificates (1) or ignore (0). (default: 1, type: bool) |
|
||||
| | timeout | 10 | `Int` | Timeout for the Proxmox API in sec. (default: 10) |
|
||||
| `proxmox_cluster` | | | | |
|
||||
| | maintenance_nodes | ['virt66.example.com'] | `List` | A list of Proxmox nodes that are defined to be in a maintenance. (default: []) |
|
||||
| | ignore_nodes | [] | `List` | A list of Proxmox nodes that are defined to be ignored. (default: []) |
|
||||
| | overprovisioning | False | `Bool` | Avoids balancing when nodes would become overprovisioned. |
|
||||
| `balancing` | | | | |
|
||||
| | enable | True | `Bool` | Enables the guest balancing. (default: True)|
|
||||
| | enforce_affinity | True | `Bool` | Enforcing affinity/anti-affinity rules but balancing might become worse. (default: False) |
|
||||
| | parallel | False | `Bool` | If guests should be moved in parallel or sequentially. (default: False)|
|
||||
| | live | True | `Bool` | If guests should be moved live or shutdown. (default: True)|
|
||||
| | with_local_disks | True | `Bool` | If balancing of guests should include local disks (default: True)|
|
||||
| | balance_types | ['vm', 'ct'] | `List` | Defined the types of guests that should be honored. (default: ['vm', 'ct']) |
|
||||
| | max_job_validation | 1800 | `Int` | How long a job validation may take in seconds. (default: 1800) |
|
||||
| | balanciness | 10 | `Int` | The maximum delta of resource usage between node with highest and lowest usage. (default: 10) |
|
||||
| | method | memory | `Str` | The balancing method that should be used. (default: memory | choices: memory, cpu, disk)|
|
||||
| | mode | used | `Str` | The balancing mode that should be used. (default: used | choices: used, assigned)|
|
||||
| `service` | | | | |
|
||||
| | daemon | False | `Bool` | If daemon mode should be activated (default: False)|
|
||||
| | schedule | 12 | `Int` | How often rebalancing should occur in hours in daemon mode (default: 12)|
|
||||
| | log_level | INFO | `Str` | Defines the default log level that should be logged. (default: INFO) |
|
||||
| Section | Option | Sub Option | Example | Type | Description |
|
||||
|---------|:------:|:----------:|:-------:|:----:|:-----------:|
|
||||
| `proxmox_api` | | | | | |
|
||||
| | hosts | | ['virt01.example.com', '10.10.10.10', 'fe01::bad:code::cafe'] | `List` | List of Proxmox nodes. Can be IPv4, IPv6 or mixed. |
|
||||
| | user | | root@pam | `Str` | Username for the API. |
|
||||
| | pass | | FooBar | `Str` | Password for the API. (Recommended: Use API token authorization!) |
|
||||
| | token_id | | proxlb | `Str` | Token ID of the user for the API. |
|
||||
| | token_secret | | 430e308f-1337-1337-beef-1337beefcafe | `Str` | Secret of the token ID for the API. |
|
||||
| | ssl_verification | | True | `Bool` | Validate SSL certificates (1) or ignore (0). (default: 1, type: bool) |
|
||||
| | timeout | | 10 | `Int` | Timeout for the Proxmox API in sec. (default: 10) |
|
||||
| `proxmox_cluster` | | | | | |
|
||||
| | maintenance_nodes | | ['virt66.example.com'] | `List` | A list of Proxmox nodes that are defined to be in a maintenance. (default: []) |
|
||||
| | ignore_nodes | | [] | `List` | A list of Proxmox nodes that are defined to be ignored. (default: []) |
|
||||
| | overprovisioning | | False | `Bool` | Avoids balancing when nodes would become overprovisioned. |
|
||||
| `balancing` | | | | | |
|
||||
| | enable | | True | `Bool` | Enables the guest balancing. (default: True)|
|
||||
| | enforce_affinity | | True | `Bool` | Enforcing affinity/anti-affinity rules but balancing might become worse. (default: False) |
|
||||
| | parallel | | False | `Bool` | If guests should be moved in parallel or sequentially. (default: False)|
|
||||
| | live | | True | `Bool` | If guests should be moved live or shutdown. (default: True)|
|
||||
| | with_local_disks | | True | `Bool` | If balancing of guests should include local disks (default: True)|
|
||||
| | balance_types | | ['vm', 'ct'] | `List` | Defined the types of guests that should be honored. (default: ['vm', 'ct']) |
|
||||
| | max_job_validation | | 1800 | `Int` | How long a job validation may take in seconds. (default: 1800) |
|
||||
| | balanciness | | 10 | `Int` | The maximum delta of resource usage between node with highest and lowest usage. (default: 10) |
|
||||
| | method | | memory | `Str` | The balancing method that should be used. (default: memory | choices: memory, cpu, disk)|
|
||||
| | mode | | used | `Str` | The balancing mode that should be used. (default: used | choices: used, assigned)|
|
||||
| `service` | | | | | |
|
||||
| | daemon | | False | `Bool` | If daemon mode should be activated (default: False)|
|
||||
| | `schedule` | | | `Dict` | Schedule config block for rebalancing. |
|
||||
| | | interval | 12 | `Int` | How often rebalancing should occur in daemon mode (default: 12)|
|
||||
| | | format | hours | `Str` | Sets the time format. (Allowed: `minutes`, `hours` | default: `hours`)|
|
||||
| | log_level | | INFO | `Str` | Defines the default log level that should be logged. (default: INFO) |
|
||||
|
||||
|
||||
An example of the configuration file looks like:
|
||||
```
|
||||
@@ -291,7 +294,9 @@ balancing:
|
||||
|
||||
service:
|
||||
daemon: True
|
||||
schedule: 12
|
||||
schedule:
|
||||
interval: 12
|
||||
format: hours
|
||||
log_level: INFO
|
||||
```
|
||||
|
||||
|
||||
@@ -27,5 +27,7 @@ balancing:
|
||||
|
||||
service:
|
||||
daemon: False
|
||||
schedule: 12
|
||||
schedule:
|
||||
interval: 12
|
||||
format: hours
|
||||
log_level: INFO
|
||||
|
||||
@@ -156,13 +156,15 @@ The proxlb systemd unit orchestrates the ProxLB application. ProxLB can be used
|
||||
```
|
||||
service:
|
||||
daemon: False
|
||||
schedule: 12
|
||||
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 schedule in hours, specifying how often rebalancing should be done if running as a daemon.
|
||||
* `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.
|
||||
|
||||
@@ -117,11 +117,25 @@ class Helper:
|
||||
"""
|
||||
logger.debug("Starting: get_daemon_mode.")
|
||||
if proxlb_config.get("service", {}).get("daemon", False):
|
||||
sleep_seconds = proxlb_config.get("service", {}).get("schedule", 12) * 3600
|
||||
logger.info(f"Daemon mode active: Next run in: {proxlb_config.get('service', {}).get('schedule', 12)} hours.")
|
||||
|
||||
# Validate schedule format which changed in v1.1.1
|
||||
if type(proxlb_config["service"].get("schedule", None)) != dict:
|
||||
logger.error("Invalid format for schedule. Please use 'hours' or 'minutes'.")
|
||||
sys.exit(1)
|
||||
|
||||
# Convert hours to seconds
|
||||
if proxlb_config["service"]["schedule"].get("format", "hours"):
|
||||
sleep_seconds = proxlb_config.get("service", {}).get("schedule", {}).get("interval", 12) * 3600
|
||||
# Convert minutes to seconds
|
||||
else:
|
||||
sleep_seconds = proxlb_config.get("service", {}).get("schedule", {}).get("interval", 720) * 60
|
||||
|
||||
logger.info(f"Daemon mode active: Next run in: {proxlb_config.get('service', {}).get('schedule', {}).get('interval', 12)} {proxlb_config['service']['schedule'].get('format', 'hours')}.")
|
||||
time.sleep(sleep_seconds)
|
||||
|
||||
else:
|
||||
logger.debug("Daemon mode is not active.")
|
||||
logger.debug("Successfully executed ProxLB. Daemon mode not active - stopping.")
|
||||
print("Daemon mode not active - stopping.")
|
||||
sys.exit(0)
|
||||
|
||||
logger.debug("Finished: get_daemon_mode.")
|
||||
|
||||
Reference in New Issue
Block a user