mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
Check if vnc_target is None before trying to use
Haha oops
This commit is contained in:
parent
737c9f9367
commit
5a28460db0
1 changed files with 11 additions and 7 deletions
|
@ -254,10 +254,11 @@ 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}. Going to attempt anyway. Likely, someone never opened a VNC session.')
|
||||||
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 +267,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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue