From 63af20c44b265fcb62aa5044f707bb1adb3dfa51 Mon Sep 17 00:00:00 2001 From: Mateusz779 Date: Fri, 14 Apr 2023 14:02:01 +0200 Subject: [PATCH] add release_allocation --- app.py | 16 ++++++++++++++++ config.py | 3 ++- db.py | 11 +++++++++++ utils.py | 3 ++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index ccda6d7..6440e91 100644 --- a/app.py +++ b/app.py @@ -154,5 +154,21 @@ def get_image(): return send_file(os.path.join(app.config['UPLOAD_FOLDER'], filename)) +@app.route("/api/release_allocation", methods=['POST']) +def release_allocation(): + try: + name = db.get_conf_image(request.headers['name']) + if name is None or name == "": + return jsonify(message="400") + except: + pass + id_allocation = db.get_conf_id_name(name) + if id_allocation is not None: + db.del_image_allocation_id(id_allocation) + else: + return jsonify(message="400") + + return jsonify(message="200") + if __name__ == '__main__': app.run(host="0.0.0.0") \ No newline at end of file diff --git a/config.py b/config.py index 82d0bff..04b0d42 100644 --- a/config.py +++ b/config.py @@ -3,4 +3,5 @@ host="localhost" user="praktyki" password="2a7driUITXFy73tO" port="5432" -default_file = "default.squashfs" \ No newline at end of file +default_file = "default.squashfs" +webssh_port = "8000" \ No newline at end of file diff --git a/db.py b/db.py index 8fd2b08..1c26ece 100644 --- a/db.py +++ b/db.py @@ -84,6 +84,17 @@ def get_conf_id(token): return cur.fetchone()[0] except: return None + +def get_conf_id_name(name): + connect() + with get_cur() as cur: + cur.execute(""" + SELECT id FROM image WHERE image_name = %s + """,(name+".squashfs",)) + try: + return cur.fetchone()[0] + except: + return None def add_user(username, password): connect() diff --git a/utils.py b/utils.py index 35be998..7a6d2af 100644 --- a/utils.py +++ b/utils.py @@ -8,6 +8,7 @@ import subprocess import threading from time import sleep import db +import config def generate_random_string(length): letters = string.ascii_letters @@ -31,7 +32,7 @@ def ping_client(ip): def ssh_thread_function(): - subprocess.run(['wssh','--fbidhttp=False']) + subprocess.run(['wssh','--fbidhttp=False', '--port='+config.webssh_port]) def check_allocation_thread_function(): while True: