Open VNC session on the node that the VM belongs

Figured out why I couldn't open a session on anything but 01. It was
because I was making the API call on proxmox01-nrh. So that's where the
session opened. I hope that by doing this, it will balance the load
(what little there is) from VNC sessions.
This commit is contained in:
Will Nilges 2022-07-09 13:57:26 -04:00
parent 0b4efa9784
commit d0af3a9567
2 changed files with 4 additions and 6 deletions

View file

@ -288,7 +288,7 @@ def vm_console(vmid):
# import pdb; pdb.set_trace()
vm = VM(vmid)
vnc_ticket, vnc_port = open_vnc_session(vmid, vm.node, app.config['PROXMOX_USER'], app.config['PROXMOX_PASS'])
node = f'proxmox01-nrh.csh.rit.edu'
node = f'{vm.node}.csh.rit.edu'
token = add_vnc_target(node, vnc_port)
# return {'host' : node, 'port' : vnc_port, 'token' : token, 'password' : vnc_ticket}, 200
return {'host' : app.config['VNC_HOST'], 'port' : 8081, 'token' : token, 'password' : vnc_ticket}, 200

View file

@ -68,8 +68,8 @@ def open_vnc_session(vmid, node, proxmox_user, proxmox_pass):
Returns: Ticket to use as the noVNC password, and a port.
"""
# Get Proxmox API ticket and CSRF_Prevention_Token
# TODO: Use Proxmoxer to get this information?
# TODO: Report errors!?
# TODO (willnilges): Use Proxmoxer to get this information
# TODO (willnilges): Report errors
data = {"username": proxmox_user, "password": proxmox_pass}
response_data = requests.post(
f"https://{node}.csh.rit.edu:8006/" + "api2/json/access/ticket",
@ -82,11 +82,9 @@ def open_vnc_session(vmid, node, proxmox_user, proxmox_pass):
)
csrf_prevention_token = response_data['CSRFPreventionToken']
ticket = response_data['ticket']
proxy_params = {"node": node, "vmid": str(vmid), "websocket": '1', "generate-password": '0'}
vncproxy_response_data = requests.post(
"https://proxmox01-nrh.csh.rit.edu:8006" + f"/api2/json/nodes/{node}/qemu/{vmid}/vncproxy",
f"https://{node}.csh.rit.edu:8006/api2/json/nodes/{node}/qemu/{vmid}/vncproxy",
verify=False,
timeout=5,
params=proxy_params,