forked from DevTable/gantryd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgantry_server.py
executable file
·73 lines (57 loc) · 2.28 KB
/
gantry_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
from flask import Flask, request
from werkzeug.utils import secure_filename
import subprocess
import os
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '/etc/gantryd/config_files'
@app.route('/config', methods=['POST'])
def upload_config():
config_file = request.files.get('config')
if config_file is not None:
filename = secure_filename(config_file.filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
config_file.save(filepath)
return 'Uploaded file %s.' % filename
return 'Please pass the configuration file in your form.'
@app.route('/list', methods=['GET'])
def list():
config_file = request.args.get('config')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], config_file)
project_name = request.args.get('project')
r = subprocess.check_output(['./gantry.py', filepath, 'list', project_name])
return r
@app.route('/start', methods=['GET'])
def start():
config_file = request.args.get('config')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], config_file)
project_name = request.args.get('project')
r = subprocess.check_output(['./gantry.py', filepath, 'start', project_name])
return r
@app.route('/stop', methods=['GET'])
def stop():
config_file = request.args.get('config')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], config_file)
project_name = request.args.get('project')
r = subprocess.check_output(['./gantry.py', filepath, 'stop', project_name])
return r
@app.route('/kill', methods=['GET'])
def kill():
config_file = request.args.get('config')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], config_file)
project_name = request.args.get('project')
r = subprocess.check_output(['./gantry.py', filepath, 'kill', project_name])
return r
@app.route('/update', methods=['GET'])
def update():
config_file = request.args.get('config')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], config_file)
project_name = request.args.get('project')
r = subprocess.check_output(['./gantry.py', filepath, 'update', project_name])
return r
if __name__ == '__main__':
try:
os.makedirs(app.config['UPLOAD_FOLDER'])
except OSError:
pass
app.run(host='0.0.0.0', port=5000, debug=True)