Sumithra | 0736c9f | 2021-01-05 03:33:28 -0800 | [diff] [blame] | 1 | import flask |
| 2 | import json |
| 3 | from flask import Flask, render_template |
| 4 | from flask import request |
| 5 | from flask import jsonify |
| 6 | import requests |
| 7 | import threading |
| 8 | import time |
| 9 | |
| 10 | app = flask.Flask(__name__) |
| 11 | app.config["DEBUG"] = True |
| 12 | |
| 13 | |
| 14 | def 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 | |
| 26 | def 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 | |
| 38 | def 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 | |
| 50 | def 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 | |
| 62 | def 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 | |
Niranjana | 9ed698d | 2022-03-17 09:03:08 +0000 | [diff] [blame] | 73 | def get_pm_data_for_snssai(snssai): |
| 74 | if str(snssai) == 'SM.PrbUsedDl.01-06E442': |
| 75 | with open('pm_data_01_06E442.json') as pm_data: |
| 76 | data = json.load(pm_data) |
| 77 | else: |
| 78 | with open('pm_data_01_B989BD.json') as pm_data: |
| 79 | data = json.load(pm_data) |
| 80 | if not data: |
| 81 | return {"Error": "Unable to read file"}, 503 |
| 82 | return data, None |
| 83 | |
Sumithra | 0736c9f | 2021-01-05 03:33:28 -0800 | [diff] [blame] | 84 | |
| 85 | @app.route("/api/sdnc-config-db/v4/du-list/<snssai>", methods=["GET"]) |
| 86 | def get_du_list(snssai): |
| 87 | data, status = get_du_list_for_nssai(snssai) |
| 88 | if not status: |
| 89 | return jsonify(data) |
| 90 | return data, 503 |
| 91 | |
| 92 | |
| 93 | @app.route("/api/sdnc-config-db/v4/du-cell-list/<snssai>", methods=["GET"]) |
| 94 | def get_du_cell_list(snssai): |
| 95 | data, status = get_du_cell_list_for_nssai(snssai) |
| 96 | if not status: |
| 97 | return jsonify(data) |
| 98 | return data, 503 |
| 99 | |
| 100 | |
| 101 | @app.route("/api/sdnc-config-db/v4/slice-config/<snssai>", methods=["GET"]) |
| 102 | def get_slice_config(snssai): |
| 103 | data, status = get_slice_config_for_nssai(snssai) |
| 104 | if not status: |
| 105 | return jsonify(data) |
| 106 | return data, 503 |
| 107 | |
| 108 | |
| 109 | @app.route("/api/sdnc-config-db/v4/profile-config/<snssai>", methods=["GET"]) |
| 110 | def get_profile_config(snssai): |
| 111 | data, status = get_profile_config_for_nssai(snssai) |
| 112 | if not status: |
| 113 | return jsonify(data) |
| 114 | return data, 503 |
| 115 | |
| 116 | |
| 117 | @app.route("/api/sdnc-config-db/v4/subscriber-details/<snssai>", |
| 118 | methods=["GET"]) |
| 119 | def get_subscriber_details(snssai): |
| 120 | data, status = get_subscriber_details_for_nssai(snssai) |
| 121 | if not status: |
| 122 | return jsonify(data) |
| 123 | return data, 503 |
| 124 | |
Niranjana | 9ed698d | 2022-03-17 09:03:08 +0000 | [diff] [blame] | 125 | @app.route("/datalake/v1/exposure/pm_data", |
| 126 | methods=["POST"]) |
| 127 | def get_pm_data(): |
| 128 | request_data = request.get_json() |
| 129 | snssai = None |
| 130 | if request_data: |
| 131 | if 'snssai' in request_data: |
| 132 | snssai = request_data['snssai'] |
| 133 | data, status = get_pm_data_for_snssai(snssai) |
| 134 | if not status: |
| 135 | return jsonify(data) |
| 136 | return data, 503 |
Sumithra | 0736c9f | 2021-01-05 03:33:28 -0800 | [diff] [blame] | 137 | |
| 138 | app.run(host='0.0.0.0') |