X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=near-rt-ric-simulator%2Fsrc%2F1.1.x-alpha.2%2Fmain.py;fp=near-rt-ric-simulator%2Fsrc%2F1.1.x-alpha.2%2Fmain.py;h=0000000000000000000000000000000000000000;hb=2d07867317ef49df4cd003899dcc7fe4c01b0352;hp=ddba11e3c08ffb63b1dda151961c73d0adec638a;hpb=7d31c11783b82cb058005242e3d2d0c932c9a04d;p=sim%2Fa1-interface.git diff --git a/near-rt-ric-simulator/src/1.1.x-alpha.2/main.py b/near-rt-ric-simulator/src/1.1.x-alpha.2/main.py deleted file mode 100644 index ddba11e..0000000 --- a/near-rt-ric-simulator/src/1.1.x-alpha.2/main.py +++ /dev/null @@ -1,140 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -import connexion -import fileinput -import json -import sys -import os - - -from pathlib import Path -from flask import Flask, escape, request, make_response -from jsonschema import validate -from var_declaration import policy_instances, policy_types, policy_status, policy_type_per_instance, hosts_set -from maincommon import * - -check_apipath() - -app = connexion.App(__name__, specification_dir=apipath) - -@app.route('/policytypes/', methods=['PUT','DELETE']) -def policy_type(policyTypeId): - if request.method == 'PUT': - data = request.data.decode("utf-8") - data = data.replace("'", "\"") - data = json.loads(data) - policy_types[policyTypeId] = data - return ('The policy type was either created or updated for policy type id: ' + policyTypeId, 200) - elif request.method == 'DELETE': - if policyTypeId in policy_types.keys(): - policy_types.pop(policyTypeId) - return make_response("policy type successfully deleted for policy type id: " + policyTypeId, 200) - else: - return make_response("No policy type defined for the specified id", 404) - -@app.route('/', methods=['GET']) -def test(): - return("Everything is fine", 200) - -@app.route('/deleteinstances', methods=['DELETE']) -def delete_instances(): - global policy_instances - global policy_status - global policy_type_per_instance - policy_instances.clear() - policy_status.clear() - policy_type_per_instance.clear() - return("All policy instances deleted", 200) - -@app.route('/deletetypes', methods=['DELETE']) -def delete_types(): - global policy_types - policy_types.clear() - return("All policy types deleted", 200) - -@app.route('//', methods=['PUT']) -def set_status(policyId, enforceStatus): - if policyId in policy_instances.keys(): - if policy_type_per_instance[policyId] == "UNDEFINED": - ps = {} - ps["policyId"] = policyId - ps["enforceStatus"] = enforceStatus - else: - policy_type_id = policy_type_per_instance[policyId] - status_schema = policy_types[policy_type_id]["statusSchema"] - ps = {} - ps["policyId"] = policyId - ps["enforceStatus"] = enforceStatus - try: - validate(instance=ps, schema=status_schema) - except: - return(set_error(None, "The json does not validate against the status schema.", 400, None, None, None, None, None)) - policy_status.pop(policyId) - policy_status[policyId] = ps - return("Status updated for policy: " + policyId, 200) - -@app.route('///', methods=['PUT']) -def set_status_with_reason(policyId, enforceStatus, enforceReason): - if policyId in policy_instances.keys(): - if policy_type_per_instance[policyId] == "UNDEFINED": - ps = {} - ps["policyId"] = policyId - ps["enforceStatus"] = enforceStatus - ps["enforceReason"] = enforceReason - else: - policy_type_id = policy_type_per_instance[policyId] - status_schema = policy_types[policy_type_id]["statusSchema"] - ps = {} - ps["policyId"] = policyId - ps["enforceStatus"] = enforceStatus - ps["enforceReason"] = enforceReason - try: - validate(instance=ps, schema=status_schema) - except: - return(set_error(None, "The json does not validate against the status schema.", 400, None, None, None, None, None)) - policy_status.pop(policyId) - policy_status[policyId] = ps - return("Status updated for policy: " + policyId, 200) - -#Metrics function - -@app.route('/counter/', methods=['GET']) -def getCounter(countername): - if (countername == "num_instances"): - return str(len(policy_instances)),200 - elif (countername == "num_types"): - return str(len(policy_types)),200 - elif (countername == "interface"): - p=Path(os.getcwd()) - pp=p.parts - return str(pp[len(pp)-1]),200 - elif (countername == "remote_hosts"): - hosts=",".join(hosts_set) - return str(hosts),200 - else: - return "Counter name: "+countername+" not found.",404 - - -port_number = 2222 -if len(sys.argv) >= 2: - if isinstance(sys.argv[1], int): - port_number = sys.argv[1] - -app.add_api('a1-openapi.yaml') - -app.run(port=port_number, host="127.0.0.1", threaded=False) \ No newline at end of file