Skip to content

Commit 125d7fa

Browse files
committed
Remove target from targets file in tasks
This probably isn't necessary and will probably error out....
1 parent 433c845 commit 125d7fa

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

proxstar/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def vm_power(vmid, action):
253253
if user.rtp or int(vmid) in user.allowed_vms:
254254
vm = VM(vmid)
255255
vnc_token_key = f'vnc_token|{vmid}'
256-
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8') # For deleting the token from redis later
257-
print(f'vnc_token = {vnc_token}')
256+
# For deleting the token from redis later
257+
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
258258
if action == 'start':
259259
vmconfig = vm.config
260260
usage_check = user.check_usage(vmconfig['cores'], vmconfig['memory'], 0)
@@ -295,7 +295,7 @@ def vm_console(vmid):
295295
)
296296
node = f'{vm.node}.csh.rit.edu'
297297
token = add_vnc_target(node, vnc_port)
298-
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.
298+
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.
299299
return {
300300
'host': app.config['VNC_HOST'],
301301
'port': app.config['VNC_PORT'],

proxstar/tasks.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from proxstar.starrs import get_next_ip, register_starrs, delete_starrs
2424
from proxstar.user import User, get_vms_for_rtp
2525
from proxstar.vm import VM, clone_vm, create_vm
26+
from proxstar.vnc import delete_vnc_target
2627

2728
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
2829

@@ -33,6 +34,7 @@
3334
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py')
3435
app.config.from_pyfile(config)
3536

37+
3638
def connect_db():
3739
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
3840
Base.metadata.bind = engine
@@ -150,7 +152,16 @@ def process_expiring_vms_task():
150152
vm.name, vm.id
151153
)
152154
)
153-
# send_stop_ssh_tunnel(vm.id) # TODO (willnilges): Remove target from targets file
155+
try:
156+
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
157+
vmid = vm['vmid']
158+
vnc_token_key = f'vnc_token|{vmid}'
159+
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
160+
delete_vnc_target(token=vnc_token)
161+
redis_conn.delete(vnc_token_key)
162+
except Exception as e: # pylint: disable=W0703
163+
print(f'ERROR: Could not delete target from targets file: {e}')
164+
154165
delete_vm_task(vm.id)
155166
if expiring_vms:
156167
send_vm_expire_email(pool, expiring_vms)

proxstar/vnc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def delete_vnc_target(node=None, port=None, token=None):
6363
elif token is not None:
6464
target = next((target for target in targets if target['token'] == f'{token}'), None)
6565
else:
66-
raise ValueError("Need either a node and port, or a token.")
66+
raise ValueError('Need either a node and port, or a token.')
6767
if target:
6868
targets.remove(target)
6969
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w')
7070
for target in targets:
7171
target_file.write(f"{target['token']}: {target['host']}\n")
7272
target_file.close()
7373
else:
74-
raise LookupError("Target does not exist")
74+
raise LookupError('Target does not exist')
7575

7676

7777
def open_vnc_session(vmid, node, proxmox_user, proxmox_pass):

0 commit comments

Comments
 (0)