Merge pull request #180 from jabbate19/patch-vnc

Use correct node in API call
This commit is contained in:
Joe Abbate 2022-10-20 13:43:22 -04:00 committed by GitHub
commit 95fbfcee80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 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,24 +6,37 @@ from proxstar.db import get_ignored_pools
from proxstar.ldapdb import is_user
def connect_proxmox():
for host in app.config['PROXMOX_HOSTS']:
def connect_proxmox(host=None):
if 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
return attempt_proxmox_connection(host)
except:
if app.config['PROXMOX_HOSTS'].index(host) == (len(app.config['PROXMOX_HOSTS']) - 1):
logging.error(f'unable to connect to {host}')
raise
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):
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
def get_node_least_mem(proxmox):
nodes = proxmox.nodes.get()
sorted_nodes = sorted(nodes, key=lambda x: ('mem' not in x, x.get('mem', None)))