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

View file

@ -8,33 +8,33 @@ 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:
logging.error('unable to connect to any of the given Proxmox servers') if app.config['PROXMOX_HOSTS'].index(host_candidate) == (
raise len(app.config['PROXMOX_HOSTS']) - 1
):
logging.error('unable to connect to any of the given Proxmox servers')
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'], token_name=app.config['PROXMOX_TOKEN_NAME'],
token_name=app.config['PROXMOX_TOKEN_NAME'], token_value=app.config['PROXMOX_TOKEN_VALUE'],
token_value=app.config['PROXMOX_TOKEN_VALUE'], verify_ssl=False,
verify_ssl=False, )
) 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):