1 # -------------------------------------------------------------------------
2 # Copyright (c) 2020 Huawei Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
21 BASE_DIR = os.path.dirname(__file__)
23 This application generates NST SELECTION API calls using the information received from SO
27 def get_nst_solution(request_json):
28 # the file is in the same folder for now will move it to the conf folder of the has once its integrated there...
29 config_input_json = os.path.join(BASE_DIR, 'conf/configIinputs.json')
31 with open(config_input_json, 'r') as openfile:
32 serviceProfile = request_json["serviceProfile"]
35 serviceProfileParameters = serviceProfile["serviceProfileParameters"]
36 nst_object = json.load(openfile)
37 for nst in nst_object[resourceName]:
38 [(nstName, nstList)] = nst.items()
39 individual_nst = dict()
41 for constraint_name in serviceProfileParameters:
42 value = serviceProfileParameters[constraint_name]
43 constraint_value = nstList.get(constraint_name)
44 if (not constraint_value):
50 individual_nst["NSTName"] = nstList.get("name")
51 individual_nst["UUID"] = nstList.get("modeluuid")
52 individual_nst["invariantUUID"] = nstList.get("modelinvariantuuid")
53 individual_nst["individual_nst"] = 1
54 nstSolutionList.append(individual_nst)
56 return nstSolutionList
57 except Exception as err:
61 def process_nst_selection( request_json, osdf_config):
63 Process a PCI request from a Client (build config-db, policy and API call, make the call, return result)
64 :param req_object: Request parameters from the client
65 :param osdf_config: Configuration specific to OSDF application (core + deployment)
66 :return: response from NST Opt
68 solution = get_nst_solution(request_json)
71 "requestId" : request_json['requestInfo']['requestId'],
72 "transactionId" : request_json['requestInfo']['transactionId'],
73 "statusMessage" : " ",
74 "requestStatus" : "accepted",
75 "solutions" : solution