mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
Merge pull request #167 from ComputerScienceHouse/willnilges/vnc-dev-bugfix
Launch websockify based on config variable, fix more VNC crashes, properly delete keys from Redis using API
This commit is contained in:
commit
6627457958
4 changed files with 30 additions and 14 deletions
|
@ -68,3 +68,10 @@ If you're trying to run this all on a VM without a graphical web browser, you ca
|
||||||
ssh example@dev-server.csh.rit.edu -L 8000:localhost:8000 -L 8001:localhost:8001
|
ssh example@dev-server.csh.rit.edu -L 8000:localhost:8000 -L 8001:localhost:8001
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Firing off Jobs
|
||||||
|
|
||||||
|
To fire off a targets cleanup job, run a curl request:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -X POST http://localhost:8000/console/cleanup -F 'token={VNC_CLEANUP_TOKEN}'
|
||||||
|
```
|
||||||
|
|
|
@ -16,10 +16,11 @@ def start_websockify(websockify_path, target_file):
|
||||||
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
|
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
|
||||||
if not result.stdout:
|
if not result.stdout:
|
||||||
print("Websockify is stopped. Starting websockify.")
|
print("Websockify is stopped. Starting websockify.")
|
||||||
|
proxstar_port = app.config.get('VNC_PORT')
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
[
|
[
|
||||||
websockify_path,
|
websockify_path,
|
||||||
'8081',
|
proxstar_port,
|
||||||
'--token-plugin',
|
'--token-plugin',
|
||||||
'TokenFile',
|
'TokenFile',
|
||||||
'--token-source',
|
'--token-source',
|
||||||
|
|
|
@ -254,10 +254,13 @@ def vm_power(vmid, action):
|
||||||
vm = VM(vmid)
|
vm = VM(vmid)
|
||||||
vnc_token_key = f'vnc_token|{vmid}'
|
vnc_token_key = f'vnc_token|{vmid}'
|
||||||
# For deleting the token from redis later
|
# For deleting the token from redis later
|
||||||
|
vnc_token = None
|
||||||
try:
|
try:
|
||||||
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
|
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
print(f'Error: Could not get vnc_token:{e}')
|
print(
|
||||||
|
f'Warning: Could not get vnc_token during {action}:{e}. {action} is still being performed.'
|
||||||
|
)
|
||||||
if action == 'start':
|
if action == 'start':
|
||||||
vmconfig = vm.config
|
vmconfig = vm.config
|
||||||
usage_check = user.check_usage(vmconfig['cores'], vmconfig['memory'], 0)
|
usage_check = user.check_usage(vmconfig['cores'], vmconfig['memory'], 0)
|
||||||
|
@ -266,18 +269,21 @@ def vm_power(vmid, action):
|
||||||
vm.start()
|
vm.start()
|
||||||
elif action == 'stop':
|
elif action == 'stop':
|
||||||
vm.stop()
|
vm.stop()
|
||||||
delete_vnc_target(token=vnc_token)
|
if vnc_token is not None:
|
||||||
redis_conn.delete(vnc_token_key)
|
delete_vnc_target(token=vnc_token)
|
||||||
|
redis_conn.delete(vnc_token_key)
|
||||||
elif action == 'shutdown':
|
elif action == 'shutdown':
|
||||||
vm.shutdown()
|
vm.shutdown()
|
||||||
delete_vnc_target(token=vnc_token)
|
if vnc_token is not None:
|
||||||
redis_conn.delete(vnc_token_key)
|
delete_vnc_target(token=vnc_token)
|
||||||
|
redis_conn.delete(vnc_token_key)
|
||||||
elif action == 'reset':
|
elif action == 'reset':
|
||||||
vm.reset()
|
vm.reset()
|
||||||
elif action == 'suspend':
|
elif action == 'suspend':
|
||||||
vm.suspend()
|
vm.suspend()
|
||||||
delete_vnc_target(token=vnc_token)
|
if vnc_token is not None:
|
||||||
redis_conn.delete(vnc_token_key)
|
delete_vnc_target(token=vnc_token)
|
||||||
|
redis_conn.delete(vnc_token_key)
|
||||||
elif action == 'resume':
|
elif action == 'resume':
|
||||||
vm.resume()
|
vm.resume()
|
||||||
return '', 200
|
return '', 200
|
||||||
|
@ -592,7 +598,14 @@ def cleanup_vnc():
|
||||||
print('Cleaning up targets file...')
|
print('Cleaning up targets file...')
|
||||||
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
|
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
|
||||||
targets.truncate()
|
targets.truncate()
|
||||||
return '', 200
|
print('Clearing vnc tokens from Redis...')
|
||||||
|
count = 0
|
||||||
|
ns_keys = 'vnc_token*'
|
||||||
|
for key in redis_conn.scan_iter(ns_keys):
|
||||||
|
redis_conn.delete(key)
|
||||||
|
count += 1
|
||||||
|
print(f'Deleted {count} key(s).')
|
||||||
|
return '', 200
|
||||||
print('Got bad cleanup request')
|
print('Got bad cleanup request')
|
||||||
return '', 403
|
return '', 403
|
||||||
|
|
||||||
|
|
|
@ -243,12 +243,7 @@ def cleanup_vnc_task():
|
||||||
ones every couple of minutes
|
ones every couple of minutes
|
||||||
https://github.com/ComputerScienceHouse/proxstar/issues/153
|
https://github.com/ComputerScienceHouse/proxstar/issues/153
|
||||||
"""
|
"""
|
||||||
print('Clearing vnc targets')
|
|
||||||
with open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') as targets:
|
|
||||||
targets.truncate()
|
|
||||||
|
|
||||||
# FIXME (willnilges): This... might be working...?
|
# FIXME (willnilges): This... might be working...?
|
||||||
|
|
||||||
try:
|
try:
|
||||||
requests.post(
|
requests.post(
|
||||||
'https://{}/console/cleanup'.format(app.config['SERVER_NAME']),
|
'https://{}/console/cleanup'.format(app.config['SERVER_NAME']),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue