-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactuator-server.py
49 lines (34 loc) · 1.17 KB
/
actuator-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
from flask import Flask, request, jsonify
from plugins.kvm import KVMActuator
app = Flask(__name__)
@app.route('/actuator/allocated_resources/', methods=['POST'])
def get_allocated_resources():
data = request.get_json()
if data['actuator_plugin'] == 'kvm':
actuator = KVMActuator()
result = actuator.allocated_resources(data['vm_id'])
return str(result), 200
return 'fail', 500
@app.route('/actuator/set_vcpu_cap/', methods=['POST'])
def set_cap():
data = request.get_json()
if data['actuator_plugin'] == 'kvm':
actuator = KVMActuator()
actuator.set_vcpu_cap(data['vm_id'], int(data['cap']))
return 'ok', 200
return 'fail', 500
@app.route('/actuator/list_vms/', methods=['POST'])
def list_vms():
data = request.get_json()
if data['actuator_plugin'] == 'kvm':
actuator = KVMActuator()
vms = actuator.list_vms()
vms_resp = ""
if len(vms) > 0:
vms_resp += vms[0]
for vm in vms:
vms_resp += "," + vm
return vms_resp, 200
return 'fail', 500
if __name__ == '__main__':
app.run(port=5047, host='0.0.0.0')