|
8 | 8 |
|
9 | 9 | def connect_proxmox(host=None): |
10 | 10 | if host: |
11 | | - attempted_connection = attempt_proxmox_connection(host) |
12 | | - if attempted_connection: |
13 | | - return attempted_connection |
14 | | - logging.error(f'unable to connect to {host}') |
15 | | - raise |
16 | | - |
17 | | - for host in app.config['PROXMOX_HOSTS']: |
18 | | - attempted_connection = attempt_proxmox_connection(host) |
19 | | - if attempted_connection: |
20 | | - return attempted_connection |
21 | | - logging.error('unable to connect to any of the given Proxmox servers') |
22 | | - raise |
| 11 | + try: |
| 12 | + return attempt_proxmox_connection(host) |
| 13 | + except: |
| 14 | + logging.error(f'unable to connect to {host}') |
| 15 | + raise |
| 16 | + |
| 17 | + for host_candidate in app.config['PROXMOX_HOSTS']: |
| 18 | + try: |
| 19 | + return attempt_proxmox_connection(host_candidate) |
| 20 | + except: |
| 21 | + if app.config['PROXMOX_HOSTS'].index(host_candidate) == ( |
| 22 | + len(app.config['PROXMOX_HOSTS']) - 1 |
| 23 | + ): |
| 24 | + logging.error('unable to connect to any of the given Proxmox servers') |
| 25 | + raise |
23 | 26 |
|
24 | 27 |
|
25 | 28 | def attempt_proxmox_connection(host): |
26 | | - try: |
27 | | - proxmox = ProxmoxAPI( |
28 | | - host, |
29 | | - user=app.config['PROXMOX_USER'], |
30 | | - token_name=app.config['PROXMOX_TOKEN_NAME'], |
31 | | - token_value=app.config['PROXMOX_TOKEN_VALUE'], |
32 | | - verify_ssl=False, |
33 | | - ) |
34 | | - proxmox.version.get() |
35 | | - return proxmox |
36 | | - except: |
37 | | - return None |
| 29 | + proxmox = ProxmoxAPI( |
| 30 | + host, |
| 31 | + user=app.config['PROXMOX_USER'], |
| 32 | + token_name=app.config['PROXMOX_TOKEN_NAME'], |
| 33 | + token_value=app.config['PROXMOX_TOKEN_VALUE'], |
| 34 | + verify_ssl=False, |
| 35 | + ) |
| 36 | + proxmox.version.get() |
| 37 | + return proxmox |
38 | 38 |
|
39 | 39 |
|
40 | 40 | def get_node_least_mem(proxmox): |
|
0 commit comments