Skip to content

Commit a11b7ee

Browse files
authored
Merge branch 'master' into apikey
2 parents 3525b00 + 0b21c65 commit a11b7ee

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

proxstar/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,11 @@ def vm_power(vmid, action):
331331
@auth.oidc_auth
332332
def vm_console(vmid):
333333
user = User(session['userinfo']['preferred_username'])
334-
connect_proxmox()
334+
proxmox = connect_proxmox()
335335
if user.rtp or int(vmid) in user.allowed_vms:
336336
# import pdb; pdb.set_trace()
337337
vm = VM(vmid)
338-
vnc_ticket, vnc_port = open_vnc_session(
339-
vmid,
340-
vm.node,
341-
app.config['PROXMOX_USER'],
342-
app.config['PROXMOX_TOKEN_NAME'],
343-
app.config['PROXMOX_TOKEN_VALUE'],
344-
)
338+
vnc_ticket, vnc_port = open_vnc_session(vmid, vm.node, proxmox)
345339
node = f'{vm.node}.csh.rit.edu'
346340
token = add_vnc_target(node, vnc_port)
347341
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.

proxstar/vnc.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44
import urllib.parse
55

6-
import requests
76
from flask import current_app as app
87

98
from proxstar import logging
@@ -74,25 +73,15 @@ def delete_vnc_target(node=None, port=None, token=None):
7473
raise LookupError('Target does not exist')
7574

7675

77-
def open_vnc_session(vmid, node, proxmox_user, proxmox_token_name, proxmox_token_value):
76+
def open_vnc_session(vmid, node, proxmox):
7877
"""Pings the Proxmox API to request a VNC Proxy connection. Authenticates
7978
against the API using a Uname/Token, gets a few tokens back, then uses those
8079
tokens to open the VNC Proxy. Use these to connect to the VM's host with
8180
websockify proxy.
8281
Returns: Ticket to use as the noVNC password, and a port.
8382
"""
84-
# Get Proxmox API ticket and CSRF_Prevention_Token
85-
# TODO (willnilges): Use Proxmoxer to get this information
8683
# TODO (willnilges): Report errors
87-
proxy_params = {'node': node, 'vmid': str(vmid), 'websocket': '1', 'generate-password': '0'}
88-
vncproxy_response_data = requests.post(
89-
f'https://{node}.csh.rit.edu:8006/api2/json/nodes/{node}/qemu/{vmid}/vncproxy',
90-
verify=False,
91-
timeout=5,
92-
params=proxy_params,
93-
headers={
94-
'Authorization': f'PVEAPIToken={proxmox_user}!{proxmox_token_name}={proxmox_token_value}'
95-
},
96-
).json()['data']
84+
params = {'websocket': '1', 'generate-password': '0'}
85+
vncproxy_response_data = proxmox.nodes(node).qemu(str(vmid)).vncproxy.post(**params)
9786

9887
return urllib.parse.quote_plus(vncproxy_response_data['ticket']), vncproxy_response_data['port']

0 commit comments

Comments
 (0)