Skip to content

Commit

Permalink
feature: Add feature to make API timeout configureable
Browse files Browse the repository at this point in the history
Fixes: #91
  • Loading branch information
gyptazy committed Oct 10, 2024
1 parent cca4c45 commit 50a9e91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .changelogs/1.0.4/91_make_api_timeout_configureable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
added:
- Add feature to make API timeout configureable. [#91]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The following options can be set in the `proxlb.conf` file:
| | api_user | root@pam | Username for the API. |
| | api_pass | FooBar | Password for the API. |
| | verify_ssl | 1 | Validate SSL certificates (1) or ignore (0). (default: 1) |
| | timeout | 10 | Timeout for the Proxmox API in sec. (default: 10) |
| `vm_balancing` | enable | 1 | Enables VM/CT balancing. |
| | method | memory | Defines the balancing method (default: memory) where you can use `memory`, `disk` or `cpu`. |
| | mode | used | Rebalance by `used` resources (efficiency) or `assigned` (avoid overprovisioning) resources. (default: used)|
Expand Down Expand Up @@ -142,6 +143,7 @@ api_host: hypervisor01.gyptazy.com
api_user: root@pam
api_pass: FooBar
verify_ssl: 1
timeout: 10
[vm_balancing]
enable: 1
method: memory
Expand Down
7 changes: 4 additions & 3 deletions proxlb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def initialize_config_options(config_path):
proxlb_config['proxmox_api_user'] = config['proxmox']['api_user']
proxlb_config['proxmox_api_pass'] = config['proxmox']['api_pass']
proxlb_config['proxmox_api_ssl_v'] = config['proxmox']['verify_ssl']
proxlb_config['proxmox_api_timeout'] = config['proxmox'].get('timeout', 10)
# VM Balancing
proxlb_config['vm_balancing_enable'] = config['vm_balancing'].get('enable', 1)
proxlb_config['vm_balancing_method'] = config['vm_balancing'].get('method', 'memory')
Expand Down Expand Up @@ -323,7 +324,7 @@ def validate_config_minimum_version(proxlb_config):
logging.info(f'{info_prefix} ProxLB config version {proxlb_config["config_version"]} is fine. Required: {__config_version__}.')


def api_connect(proxmox_api_host, proxmox_api_user, proxmox_api_pass, proxmox_api_ssl_v):
def api_connect(proxmox_api_host, proxmox_api_user, proxmox_api_pass, proxmox_api_ssl_v, proxmox_api_timeout):
""" Connect and authenticate to the Proxmox remote API. """
error_prefix = 'Error: [api-connection]:'
warn_prefix = 'Warning: [api-connection]:'
Expand All @@ -337,7 +338,7 @@ def api_connect(proxmox_api_host, proxmox_api_user, proxmox_api_pass, proxmox_ap
proxmox_api_host = __api_connect_get_host(proxmox_api_host)

try:
api_object = proxmoxer.ProxmoxAPI(proxmox_api_host, user=proxmox_api_user, password=proxmox_api_pass, verify_ssl=proxmox_api_ssl_v)
api_object = proxmoxer.ProxmoxAPI(proxmox_api_host, user=proxmox_api_user, password=proxmox_api_pass, verify_ssl=proxmox_api_ssl_v, timeout=proxmox_api_timeout)
except proxmoxer.backends.https.AuthenticationError as proxmox_api_error:
logging.critical(f'{error_prefix} Provided credentials do not work: {proxmox_api_error}')
sys.exit(2)
Expand Down Expand Up @@ -1517,7 +1518,7 @@ def main():

while True:
# API Authentication.
api_object = api_connect(proxlb_config['proxmox_api_host'], proxlb_config['proxmox_api_user'], proxlb_config['proxmox_api_pass'], proxlb_config['proxmox_api_ssl_v'])
api_object = api_connect(proxlb_config['proxmox_api_host'], proxlb_config['proxmox_api_user'], proxlb_config['proxmox_api_pass'], proxlb_config['proxmox_api_ssl_v'], proxlb_config['proxmox_api_timeout'])

# Get master node of cluster and ensure that ProxLB is only performed on the
# cluster master node to avoid ongoing rebalancing.
Expand Down

0 comments on commit 50a9e91

Please sign in to comment.