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):
if host:
attempted_connection = attempt_proxmox_connection(host)
if attempted_connection:
return attempted_connection
try:
return attempt_proxmox_connection(host)
except:
logging.error(f'unable to connect to {host}')
raise
for host in app.config['PROXMOX_HOSTS']:
attempted_connection = attempt_proxmox_connection(host)
if attempted_connection:
return attempted_connection
for host_candidate in app.config['PROXMOX_HOSTS']:
try:
return attempt_proxmox_connection(host_candidate)
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')
raise
def attempt_proxmox_connection(host):
try:
proxmox = ProxmoxAPI(
host,
user=app.config['PROXMOX_USER'],
@ -33,8 +35,6 @@ def attempt_proxmox_connection(host):
)
proxmox.version.get()
return proxmox
except:
return None
def get_node_least_mem(proxmox):