|
3 | 3 | import time |
4 | 4 | import urllib.parse |
5 | 5 |
|
6 | | -import requests |
7 | 6 | from flask import current_app as app |
8 | 7 |
|
9 | 8 | from proxstar import logging |
@@ -74,25 +73,15 @@ def delete_vnc_target(node=None, port=None, token=None): |
74 | 73 | raise LookupError('Target does not exist') |
75 | 74 |
|
76 | 75 |
|
77 | | -def open_vnc_session(vmid, node, proxmox_user, proxmox_token_name, proxmox_token_value): |
| 76 | +def open_vnc_session(vmid, node, proxmox): |
78 | 77 | """Pings the Proxmox API to request a VNC Proxy connection. Authenticates |
79 | 78 | against the API using a Uname/Token, gets a few tokens back, then uses those |
80 | 79 | tokens to open the VNC Proxy. Use these to connect to the VM's host with |
81 | 80 | websockify proxy. |
82 | 81 | Returns: Ticket to use as the noVNC password, and a port. |
83 | 82 | """ |
84 | | - # Get Proxmox API ticket and CSRF_Prevention_Token |
85 | | - # TODO (willnilges): Use Proxmoxer to get this information |
86 | 83 | # 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) |
97 | 86 |
|
98 | 87 | return urllib.parse.quote_plus(vncproxy_response_data['ticket']), vncproxy_response_data['port'] |
0 commit comments