-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
55 lines (44 loc) · 1.1 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask
import os
import threading
import uuid
import datetime
import subprocess
volume = os.environ.get("VOLUME", "/data")
size = os.environ.get("SIZE", 10)
app = Flask(__name__)
start_time = datetime.datetime.now().isoformat()
@app.route("/")
def root():
return (
"sprayfoam is filling "
+ volume
+ " with "
+ size
+ "MB files.<br/>Running since "
+ start_time
+ ".<br/><a href='/size'>Check size</a>"
)
@app.route("/size")
def get_size():
current_size = (
subprocess.check_output(["du", "-sh", volume]).split()[0].decode("utf-8")
)
return "Volume size: " + current_size
@app.route("/healthz")
def healthz():
return "OK"
def generate_big_files(volume, size):
while True:
with open(f"{volume}/{uuid.uuid4()}.txt", "w") as f:
f.write("0" * 1024 * 1024 * int(size))
if __name__ == "__main__":
thread = threading.Thread(
target=generate_big_files,
args=(
volume,
size,
),
)
thread.start()
app.run(host="0.0.0.0", port=5000)