This commit is contained in:
Joe Abbate 2022-10-20 13:41:22 -04:00
parent c8331b66d2
commit f91908f286

View file

@ -8,22 +8,24 @@ from proxstar.ldapdb import is_user
def connect_proxmox(host=None): def connect_proxmox(host=None):
if host: if host:
attempted_connection = attempt_proxmox_connection(host) try:
if attempted_connection: return attempt_proxmox_connection(host)
return attempted_connection except:
logging.error(f'unable to connect to {host}') logging.error(f'unable to connect to {host}')
raise raise
for host in app.config['PROXMOX_HOSTS']: for host_candidate in app.config['PROXMOX_HOSTS']:
attempted_connection = attempt_proxmox_connection(host) try:
if attempted_connection: return attempt_proxmox_connection(host_candidate)
return attempted_connection except:
if app.config['PROXMOX_HOSTS'].index(host_candidate) == (
len(app.config['PROXMOX_HOSTS']) - 1
):
logging.error('unable to connect to any of the given Proxmox servers') logging.error('unable to connect to any of the given Proxmox servers')
raise raise
def attempt_proxmox_connection(host): def attempt_proxmox_connection(host):
try:
proxmox = ProxmoxAPI( proxmox = ProxmoxAPI(
host, host,
user=app.config['PROXMOX_USER'], user=app.config['PROXMOX_USER'],
@ -33,8 +35,6 @@ def attempt_proxmox_connection(host):
) )
proxmox.version.get() proxmox.version.get()
return proxmox return proxmox
except:
return None
def get_node_least_mem(proxmox): def get_node_least_mem(proxmox):