From 529f980d8e2c1c4816850487b62cfe5a58197fa2 Mon Sep 17 00:00:00 2001 From: AlexTheGeek <28763288+AlexTheGeek@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:30:09 +0100 Subject: [PATCH] =?UTF-8?q?modification=20de=20la=20r=C3=A9cup=C3=A9ration?= =?UTF-8?q?=20de=20l'url=20vnc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 0a37def..4662518 100644 --- a/main.py +++ b/main.py @@ -587,15 +587,10 @@ def vm_status_id(uuid): def vm_url_id(uuid): if not uuid: return jsonify({'message': 'Please provide a VM ID'}), 400 - vm_name = VM.query.filter_by(id=uuid, users_id=current_user.id).first().name - if vm_name: - try: - url_vnc = openstack.get_console_url(conn_openstack, vm_name) - except: - return jsonify({'message': 'ERROR URL'}), 500 - url = url_vnc.rsplit('0/vnc_auto.html', 1)[-1] - # print(url) - return jsonify({"url": "https://vnc.insa-cvl.com/"+url}), 200 + vm = VM.query.filter_by(id=uuid, users_id=current_user.id).first() + if vm: + token = vm.vncurl + return jsonify({"url": "https://vnc.insa-cvl.com/?path="+token}), 200 else: return jsonify({'message': 'VM not found'}), 404 @@ -606,16 +601,10 @@ def vm_url_id(uuid): def vm_url_template(template_id): if not template_id: return jsonify({'message': 'Please provide a template ID'}), 400 - vm_name = VM.query.filter_by(template_id=template_id, users_id=current_user.id).first().name - if vm_name: - try: - url_vnc = openstack.get_console_url(conn_openstack, vm_name) - except: - return jsonify({'message': 'ERROR URL'}), 500 - # print(url_vnc) - url = url_vnc.rsplit('0/vnc_auto.html', 1)[-1] - # print(url) - return jsonify({"url": "https://vnc.insa-cvl.com/"+url}), 200 + vm = VM.query.filter_by(template_id=template_id, users_id=current_user.id).first() + if vm: + token = vm.vncurl + return jsonify({"url": "https://vnc.insa-cvl.com/?path="+token}), 200 else: return jsonify({'message': 'Template not found'}), 404