Use correct node in API call

This commit is contained in:
Joe Abbate 2022-10-20 13:26:48 -04:00
parent 5ca4d710bb
commit c8331b66d2
No known key found for this signature in database
GPG key ID: 7F1CC23828058430
2 changed files with 29 additions and 15 deletions

View file

@ -335,6 +335,7 @@ def vm_console(vmid):
if user.rtp or int(vmid) in user.allowed_vms:
# import pdb; pdb.set_trace()
vm = VM(vmid)
proxmox = connect_proxmox(f'{vm.node}.csh.rit.edu')
vnc_ticket, vnc_port = open_vnc_session(vmid, vm.node, proxmox)
node = f'{vm.node}.csh.rit.edu'
token = add_vnc_target(node, vnc_port)

View file

@ -6,22 +6,35 @@ from proxstar.db import get_ignored_pools
from proxstar.ldapdb import is_user
def connect_proxmox():
def connect_proxmox(host=None):
if host:
attempted_connection = attempt_proxmox_connection(host)
if attempted_connection:
return attempted_connection
logging.error(f'unable to connect to {host}')
raise
for host in app.config['PROXMOX_HOSTS']:
try:
proxmox = ProxmoxAPI(
host,
user=app.config['PROXMOX_USER'],
token_name=app.config['PROXMOX_TOKEN_NAME'],
token_value=app.config['PROXMOX_TOKEN_VALUE'],
verify_ssl=False,
)
proxmox.version.get()
return proxmox
except:
if app.config['PROXMOX_HOSTS'].index(host) == (len(app.config['PROXMOX_HOSTS']) - 1):
logging.error('unable to connect to any of the given Proxmox servers')
raise
attempted_connection = attempt_proxmox_connection(host)
if attempted_connection:
return attempted_connection
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'],
token_name=app.config['PROXMOX_TOKEN_NAME'],
token_value=app.config['PROXMOX_TOKEN_VALUE'],
verify_ssl=False,
)
proxmox.version.get()
return proxmox
except:
return None
def get_node_least_mem(proxmox):