mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-02-12 13:01:51 +00:00
Remove target from targets file in tasks
This probably isn't necessary and will probably error out....
This commit is contained in:
parent
433c845a35
commit
125d7fae51
3 changed files with 17 additions and 6 deletions
|
@ -253,8 +253,8 @@ def vm_power(vmid, action):
|
||||||
if user.rtp or int(vmid) in user.allowed_vms:
|
if user.rtp or int(vmid) in user.allowed_vms:
|
||||||
vm = VM(vmid)
|
vm = VM(vmid)
|
||||||
vnc_token_key = f'vnc_token|{vmid}'
|
vnc_token_key = f'vnc_token|{vmid}'
|
||||||
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8') # For deleting the token from redis later
|
# For deleting the token from redis later
|
||||||
print(f'vnc_token = {vnc_token}')
|
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
|
||||||
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)
|
||||||
|
|
|
@ -23,6 +23,7 @@ from proxstar.proxmox import connect_proxmox, get_pools
|
||||||
from proxstar.starrs import get_next_ip, register_starrs, delete_starrs
|
from proxstar.starrs import get_next_ip, register_starrs, delete_starrs
|
||||||
from proxstar.user import User, get_vms_for_rtp
|
from proxstar.user import User, get_vms_for_rtp
|
||||||
from proxstar.vm import VM, clone_vm, create_vm
|
from proxstar.vm import VM, clone_vm, create_vm
|
||||||
|
from proxstar.vnc import delete_vnc_target
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
|
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ else:
|
||||||
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py')
|
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py')
|
||||||
app.config.from_pyfile(config)
|
app.config.from_pyfile(config)
|
||||||
|
|
||||||
|
|
||||||
def connect_db():
|
def connect_db():
|
||||||
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
|
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
|
||||||
Base.metadata.bind = engine
|
Base.metadata.bind = engine
|
||||||
|
@ -150,7 +152,16 @@ def process_expiring_vms_task():
|
||||||
vm.name, vm.id
|
vm.name, vm.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# send_stop_ssh_tunnel(vm.id) # TODO (willnilges): Remove target from targets file
|
try:
|
||||||
|
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
|
||||||
|
vmid = vm['vmid']
|
||||||
|
vnc_token_key = f'vnc_token|{vmid}'
|
||||||
|
vnc_token = redis_conn.get(vnc_token_key).decode('utf-8')
|
||||||
|
delete_vnc_target(token=vnc_token)
|
||||||
|
redis_conn.delete(vnc_token_key)
|
||||||
|
except Exception as e: # pylint: disable=W0703
|
||||||
|
print(f'ERROR: Could not delete target from targets file: {e}')
|
||||||
|
|
||||||
delete_vm_task(vm.id)
|
delete_vm_task(vm.id)
|
||||||
if expiring_vms:
|
if expiring_vms:
|
||||||
send_vm_expire_email(pool, expiring_vms)
|
send_vm_expire_email(pool, expiring_vms)
|
||||||
|
|
|
@ -63,7 +63,7 @@ def delete_vnc_target(node=None, port=None, token=None):
|
||||||
elif token is not None:
|
elif token is not None:
|
||||||
target = next((target for target in targets if target['token'] == f'{token}'), None)
|
target = next((target for target in targets if target['token'] == f'{token}'), None)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Need either a node and port, or a token.")
|
raise ValueError('Need either a node and port, or a token.')
|
||||||
if target:
|
if target:
|
||||||
targets.remove(target)
|
targets.remove(target)
|
||||||
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w')
|
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w')
|
||||||
|
@ -71,7 +71,7 @@ def delete_vnc_target(node=None, port=None, token=None):
|
||||||
target_file.write(f"{target['token']}: {target['host']}\n")
|
target_file.write(f"{target['token']}: {target['host']}\n")
|
||||||
target_file.close()
|
target_file.close()
|
||||||
else:
|
else:
|
||||||
raise LookupError("Target does not exist")
|
raise LookupError('Target does not exist')
|
||||||
|
|
||||||
|
|
||||||
def open_vnc_session(vmid, node, proxmox_user, proxmox_pass):
|
def open_vnc_session(vmid, node, proxmox_user, proxmox_pass):
|
||||||
|
|
Loading…
Reference in a new issue