forked from JackSlateur/backurne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
76 lines (55 loc) · 1.45 KB
/
api.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
#!/usr/bin/python3
from flask import Flask
from flask import Blueprint
from flask_autoindex import AutoIndexBlueprint
import json
from restore import Restore
app = Flask(__name__)
def send_json(data, code=200):
return json.dumps(data), 200, {'Content-Type': 'application/json'}
@app.route('/backup/')
def ls():
restore = Restore()
data = restore.ls()
result = list()
for i in data:
result.append({
'ident': i['ident'],
'disk': i['disk'],
'uuid': i['uuid'],
})
return send_json(result)
@app.route('/backup/<rbd>/')
def ls_snaps(rbd):
restore = Restore(rbd)
data = restore.ls()
result = list()
for i in data:
result.append({
'creation_date': str(i['creation']),
'uuid': i['uuid'],
})
return send_json(result)
@app.route('/map/<rbd>/<snap>/')
def map(rbd, snap):
restore = Restore(rbd, snap)
status = restore.mount()
if status is None:
return send_json({'success': False, 'path': None}, code=500)
else:
status = status.replace('/tmp/', '')
return send_json({'success': True, 'path': status})
@app.route('/unmap/<rbd>/<snap>/')
def unmap(rbd, snap):
restore = Restore(rbd, snap)
restore.umount()
return send_json({'success': True})
@app.route('/mapped/')
def mapped():
restore = Restore()
data = restore.list_mapped()
return send_json(data)
auto_bp = Blueprint('auto_bp', __name__)
# FIXME: use config or something
AutoIndexBlueprint(auto_bp, browse_root='/tmp/')
app.register_blueprint(auto_bp, url_prefix='/explore')