blob: bcda08d5aaf4a6eacfc8dd69da82b375252a7bf8 [file] [log] [blame]
Sumithra0736c9f2021-01-05 03:33:28 -08001import flask
2import json
3from flask import Flask, render_template
4from flask import request
5from flask import jsonify
6import requests
7import threading
8import time
9
10app = flask.Flask(__name__)
11app.config["DEBUG"] = True
12
13
14def get_du_list_for_nssai(snssai):
15 if str(snssai) == '001-00110':
16 with open('du_list_001_00110.json') as du_list:
17 data = json.load(du_list)
18 else:
19 with open('du_list_001_010000.json') as du_list:
20 data = json.load(du_list)
21 if not data:
22 return {"Error": "Unable to read file"}, 503
23 return data, None
24
25
26def get_du_cell_list_for_nssai(snssai):
27 if str(snssai) == '001-00110':
28 with open('du_cell_list_001_00110.json') as du_cell_list:
29 data = json.load(du_cell_list)
30 else:
31 with open('du_cell_list_001_010000.json') as du_cell_list:
32 data = json.load(du_cell_list)
33 if not data:
34 return {"Error": "Unable to read file"}, 503
35 return data, None
36
37
38def get_slice_config_for_nssai(snssai):
39 if str(snssai) == '001-00110':
40 with open('slice_config_001_00110.json') as slice_config:
41 data = json.load(slice_config)
42 else:
43 with open('slice_config_001_010000.json') as slice_config:
44 data = json.load(slice_config)
45 if not data:
46 return {"Error": "Unable to read file"}, 503
47 return data, None
48
49
50def get_profile_config_for_nssai(snssai):
51 if str(snssai) == '001-00110':
52 with open('profile_config_001_00110.json') as profile_config:
53 data = json.load(profile_config)
54 else:
55 with open('profile_config_001_010000.json') as profile_config:
56 data = json.load(profile_config)
57 if not data:
58 return {"Error": "Unable to read file"}, 503
59 return data, None
60
61
62def get_subscriber_details_for_nssai(snssai):
63 if str(snssai) == '001-00110':
64 with open('subscriber-details_001_00110.json') as subscriber_details:
65 data = json.load(subscriber_details)
66 else:
67 with open('subscriber-details_001_010000.json') as subscriber_details:
68 data = json.load(subscriber_details)
69 if not data:
70 return {"Error": "Unable to read file"}, 503
71 return data, None
72
73
74@app.route("/api/sdnc-config-db/v4/du-list/<snssai>", methods=["GET"])
75def get_du_list(snssai):
76 data, status = get_du_list_for_nssai(snssai)
77 if not status:
78 return jsonify(data)
79 return data, 503
80
81
82@app.route("/api/sdnc-config-db/v4/du-cell-list/<snssai>", methods=["GET"])
83def get_du_cell_list(snssai):
84 data, status = get_du_cell_list_for_nssai(snssai)
85 if not status:
86 return jsonify(data)
87 return data, 503
88
89
90@app.route("/api/sdnc-config-db/v4/slice-config/<snssai>", methods=["GET"])
91def get_slice_config(snssai):
92 data, status = get_slice_config_for_nssai(snssai)
93 if not status:
94 return jsonify(data)
95 return data, 503
96
97
98@app.route("/api/sdnc-config-db/v4/profile-config/<snssai>", methods=["GET"])
99def get_profile_config(snssai):
100 data, status = get_profile_config_for_nssai(snssai)
101 if not status:
102 return jsonify(data)
103 return data, 503
104
105
106@app.route("/api/sdnc-config-db/v4/subscriber-details/<snssai>",
107 methods=["GET"])
108def get_subscriber_details(snssai):
109 data, status = get_subscriber_details_for_nssai(snssai)
110 if not status:
111 return jsonify(data)
112 return data, 503
113
114
115app.run(host='0.0.0.0')