-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
83 lines (72 loc) · 2.37 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from flask import make_response, abort
import panel_gen
# Handler for /app GET
def read_status():
"""
GET /app/
Success: Returns 200 OK + app status messages
Failure: Returns 406 Failed to get info
"""
result = panel_gen.get_info()
if result != False:
return result
else:
abort(
406,
"Failed to get info. Probably an issue with panel_gen",
)
def start(**kwargs):
"""
POST /app/start/{switch}
Success: Returns 200 OK + Starts calls on {switch}.
Also returns JSON formatted switch status message.
Failure: Returns 406
If launched from web browser at http://0.0.0.0:5000, returns 303
redirect back to same page with no status message. This is so the
smartphone browser app will refresh the same page. It's an ugly hack
but it works.
**kwargs allow the POST to be parsed for specifics
switch: In URI path, Can be "1xb", "5xb", "panel", "all"
source: In URI query string. "web", "key"
"""
switch = kwargs.get("switch", "")
source = kwargs.get("source", "")
traffic_load = kwargs.get("traffic_load", "")
try:
result = panel_gen.api_start(**kwargs)
if source == "web":
return 'See Other', 303, {'Location': '/'}
else:
return result
except Exception as e:
abort(
406,
"Failed to create new lines. Check api_start()"
)
def stop(**kwargs):
"""
POST /app/stop/{switch}
Success: Returns 200 OK + Stops calls on {switch}.
Failure: Returns 406
If launched from web browser at http://0.0.0.0:5000, returns 303
redirect back to same page with no status message.
**kwargs allow the POST to be parsed for specifics
switch: In URI path. Can be "1xb", "5xb", "panel", "all"
source: In URI query string. Can be "web", "key".
"""
source = kwargs.get("source", "")
try:
result = panel_gen.api_stop(**kwargs)
if result != False:
if source == "web":
return 'See Other', 303, {'Location': '/'}
else:
return result
elif result == False:
abort(
406,
"Failed to stop switch. Ask Sarah to fix this.",
)
except:
abort(406, "Shits all fucked up",)
pass