mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
Merge branch 'master' into apikey
This commit is contained in:
commit
a11b7eefc0
2 changed files with 5 additions and 22 deletions
|
@ -331,17 +331,11 @@ def vm_power(vmid, action):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_console(vmid):
|
def vm_console(vmid):
|
||||||
user = User(session['userinfo']['preferred_username'])
|
user = User(session['userinfo']['preferred_username'])
|
||||||
connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if user.rtp or int(vmid) in user.allowed_vms:
|
if user.rtp or int(vmid) in user.allowed_vms:
|
||||||
# import pdb; pdb.set_trace()
|
# import pdb; pdb.set_trace()
|
||||||
vm = VM(vmid)
|
vm = VM(vmid)
|
||||||
vnc_ticket, vnc_port = open_vnc_session(
|
vnc_ticket, vnc_port = open_vnc_session(vmid, vm.node, proxmox)
|
||||||
vmid,
|
|
||||||
vm.node,
|
|
||||||
app.config['PROXMOX_USER'],
|
|
||||||
app.config['PROXMOX_TOKEN_NAME'],
|
|
||||||
app.config['PROXMOX_TOKEN_VALUE'],
|
|
||||||
)
|
|
||||||
node = f'{vm.node}.csh.rit.edu'
|
node = f'{vm.node}.csh.rit.edu'
|
||||||
token = add_vnc_target(node, vnc_port)
|
token = add_vnc_target(node, vnc_port)
|
||||||
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.
|
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.
|
||||||
|
|
|
@ -3,7 +3,6 @@ import subprocess
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
import requests
|
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
|
|
||||||
from proxstar import logging
|
from proxstar import logging
|
||||||
|
@ -74,25 +73,15 @@ def delete_vnc_target(node=None, port=None, token=None):
|
||||||
raise LookupError('Target does not exist')
|
raise LookupError('Target does not exist')
|
||||||
|
|
||||||
|
|
||||||
def open_vnc_session(vmid, node, proxmox_user, proxmox_token_name, proxmox_token_value):
|
def open_vnc_session(vmid, node, proxmox):
|
||||||
"""Pings the Proxmox API to request a VNC Proxy connection. Authenticates
|
"""Pings the Proxmox API to request a VNC Proxy connection. Authenticates
|
||||||
against the API using a Uname/Token, gets a few tokens back, then uses those
|
against the API using a Uname/Token, gets a few tokens back, then uses those
|
||||||
tokens to open the VNC Proxy. Use these to connect to the VM's host with
|
tokens to open the VNC Proxy. Use these to connect to the VM's host with
|
||||||
websockify proxy.
|
websockify proxy.
|
||||||
Returns: Ticket to use as the noVNC password, and a port.
|
Returns: Ticket to use as the noVNC password, and a port.
|
||||||
"""
|
"""
|
||||||
# Get Proxmox API ticket and CSRF_Prevention_Token
|
|
||||||
# TODO (willnilges): Use Proxmoxer to get this information
|
|
||||||
# TODO (willnilges): Report errors
|
# TODO (willnilges): Report errors
|
||||||
proxy_params = {'node': node, 'vmid': str(vmid), 'websocket': '1', 'generate-password': '0'}
|
params = {'websocket': '1', 'generate-password': '0'}
|
||||||
vncproxy_response_data = requests.post(
|
vncproxy_response_data = proxmox.nodes(node).qemu(str(vmid)).vncproxy.post(**params)
|
||||||
f'https://{node}.csh.rit.edu:8006/api2/json/nodes/{node}/qemu/{vmid}/vncproxy',
|
|
||||||
verify=False,
|
|
||||||
timeout=5,
|
|
||||||
params=proxy_params,
|
|
||||||
headers={
|
|
||||||
'Authorization': f'PVEAPIToken={proxmox_user}!{proxmox_token_name}={proxmox_token_value}'
|
|
||||||
},
|
|
||||||
).json()['data']
|
|
||||||
|
|
||||||
return urllib.parse.quote_plus(vncproxy_response_data['ticket']), vncproxy_response_data['port']
|
return urllib.parse.quote_plus(vncproxy_response_data['ticket']), vncproxy_response_data['port']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue