Merge "Initial docs skeleton"
[it/test.git] / ons_2019_demo / a1_med / a1_med_http_server / dockerized_version / a1med.py
1 #!flask/bin/python
2 #
3 #
4 # Copyright 2019 AT&T Intellectual Property
5 # Copyright 2019 Nokia
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 from flask import Flask, jsonify, request
21 import json
22
23 app = Flask(__name__)
24
25
26
27 @app.route('/a1ric/metrics', methods=['GET'])
28 def get_metrics():
29     with open('metrics.json') as json_file:
30         metrics = json.load(json_file)
31     return jsonify(metrics)
32
33 @app.route('/a1ric/delay', methods=['GET'])
34 def get_delay():
35     with open('delay.json') as json_file:
36         delay = json.load(json_file)
37     return jsonify(delay)
38
39 @app.route('/a1ric/load', methods=['GET'])
40 def get_load():
41     with open('load.json') as json_file:
42         load = json.load(json_file)
43     return jsonify(load)
44
45 @app.route('/a1ric/delay', methods=['PUT'])
46 def write_delay_file():
47     if not request.json or not 'delay' in request.json:
48         abort(400)
49     delay = {
50         'delay': request.json['delay'],
51     }
52     delay_json = json.dumps(delay)
53     f = open("delay.json","w")
54     f.write(delay_json)
55     return jsonify(delay), 201
56
57 @app.route('/a1ric/load', methods=['PUT'])
58 def write_load_file():
59     if not request.json or not 'load' in request.json:
60         abort(400)
61     load = {
62         'load': request.json['load'],
63     }
64     load_json = json.dumps(load)
65     f = open("load.json","w")
66     f.write(load_json)
67     return jsonify(load), 201
68
69 if __name__ == '__main__':
70     app.run(debug=True, host='0.0.0.0', port=10080)