bug fix
This commit is contained in:
parent
bdfb2e9b9e
commit
1697f84b73
5
app.py
5
app.py
@ -168,11 +168,12 @@ def get_image():
|
|||||||
@app.route("/api/release_allocation", methods=['POST'])
|
@app.route("/api/release_allocation", methods=['POST'])
|
||||||
def release_allocation():
|
def release_allocation():
|
||||||
try:
|
try:
|
||||||
id_allocation = db.get_conf_id_name(request.headers['name']+".squashfs")
|
id_allocation = db.get_conf_id_name(
|
||||||
|
request.headers['name']+".squashfs")
|
||||||
if id_allocation is None or id_allocation == "":
|
if id_allocation is None or id_allocation == "":
|
||||||
return jsonify(message="400")
|
return jsonify(message="400")
|
||||||
except:
|
except:
|
||||||
pass
|
return jsonify(message="400")
|
||||||
if id_allocation is not None:
|
if id_allocation is not None:
|
||||||
db.del_image_allocation_id_image(id_allocation)
|
db.del_image_allocation_id_image(id_allocation)
|
||||||
else:
|
else:
|
||||||
|
12
utils.py
12
utils.py
@ -10,17 +10,21 @@ from time import sleep
|
|||||||
import db
|
import db
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
def generate_random_string(length):
|
def generate_random_string(length):
|
||||||
letters = string.ascii_letters
|
letters = string.ascii_letters
|
||||||
random_string = ''.join(random.choice(letters) for i in range(length))
|
random_string = ''.join(random.choice(letters) for i in range(length))
|
||||||
return random_string
|
return random_string
|
||||||
|
|
||||||
|
|
||||||
def hash_password(password):
|
def hash_password(password):
|
||||||
return hashlib.sha512(password.encode('utf-8')).hexdigest()
|
return hashlib.sha512(password.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def generate_auth_token():
|
def generate_auth_token():
|
||||||
return secrets.token_urlsafe(32)
|
return secrets.token_urlsafe(32)
|
||||||
|
|
||||||
|
|
||||||
def ping_client(ip):
|
def ping_client(ip):
|
||||||
response = os.system("ping -c 1 " + ip + "> /dev/null")
|
response = os.system("ping -c 1 " + ip + "> /dev/null")
|
||||||
|
|
||||||
@ -30,10 +34,10 @@ def ping_client(ip):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ssh_thread_function():
|
def ssh_thread_function():
|
||||||
subprocess.run(['wssh', '--fbidhttp=False', '--port='+config.webssh_port])
|
subprocess.run(['wssh', '--fbidhttp=False', '--port='+config.webssh_port])
|
||||||
|
|
||||||
|
|
||||||
def check_allocation_thread_function():
|
def check_allocation_thread_function():
|
||||||
while True:
|
while True:
|
||||||
ids = db.get_image_allocation_all()
|
ids = db.get_image_allocation_all()
|
||||||
@ -44,11 +48,13 @@ def check_allocation_thread_function():
|
|||||||
|
|
||||||
sleep(10)
|
sleep(10)
|
||||||
|
|
||||||
|
|
||||||
class PingThread(threading.Thread):
|
class PingThread(threading.Thread):
|
||||||
def __init__(self, ip, id):
|
def __init__(self, ip, id):
|
||||||
super(PingThread, self).__init__()
|
super(PingThread, self).__init__()
|
||||||
self.Ip = ip
|
self.Ip = ip
|
||||||
self.Id = id
|
self.Id = id
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.Ip is None:
|
if self.Ip is None:
|
||||||
return
|
return
|
||||||
@ -62,9 +68,11 @@ class PingThread(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
db.update_image_allocation_time(self.Id)
|
db.update_image_allocation_time(self.Id)
|
||||||
|
|
||||||
|
|
||||||
def init_threads():
|
def init_threads():
|
||||||
ssh_thread = threading.Thread(target=ssh_thread_function)
|
ssh_thread = threading.Thread(target=ssh_thread_function)
|
||||||
ssh_thread.start()
|
ssh_thread.start()
|
||||||
|
|
||||||
allocation_thread = threading.Thread(target=check_allocation_thread_function)
|
allocation_thread = threading.Thread(
|
||||||
|
target=check_allocation_thread_function)
|
||||||
allocation_thread.start()
|
allocation_thread.start()
|
Loading…
Reference in New Issue
Block a user