-
Notifications
You must be signed in to change notification settings - Fork 13
/
sample-api.py
51 lines (42 loc) · 1.24 KB
/
sample-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
#!/usr/bin/python3
from flask import Flask, request
import json
app = Flask(__name__)
def send_json(data, code=200):
return json.dumps(data), 200, {'Content-Type': 'application/json'}
@app.route('/', methods=['POST'])
def profile():
# data is fed with something like:
# {'cluster': {
# 'fqdn': 'supercluster.fqdn.org', 'name': 'supercluster', 'type': 'proxmox'},
# 'vm': {'name': 'super-server', 'vmid': 115},
# 'disk': {'rbd': 'vm-115-disk-1', 'ceph': 'cephcluster'}
# }
data = request.get_json()
# Add your logic here
# As a sample, we only add profiles if the VM's name is 'super-server'
if data['vm']['name'] == 'super-server' or True:
# A sample output, which is roughly the same as config's profiles
# Each profiles will be added to the config's
# Thus, there is no replacement nor override
json = {
'profiles': {
'daily': {
'count': 365,
'max_on_live': 10,
},
'hourly': {
'count': 48,
'max_on_live': 0,
'priority': 'high',
},
}
}
else:
# An empty dict means "no additionnal profile"
json = {}
# Additionally, we can disable backups by setting 'backup' to False
# Any other values are meaningless
if data['vm']['vmid'] == 1234:
json['backup'] = False
return send_json(json)