X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=near-rt-ric-simulator%2Fcommon%2Fcreate_rics_json.py;fp=near-rt-ric-simulator%2Fcommon%2Fcreate_rics_json.py;h=d6a095bce53e9a4f423b4f7ba4cd2657b1f2b497;hb=80a9200dc1dfc342d5debfaa5df3d28c14bc5a68;hp=0000000000000000000000000000000000000000;hpb=f217fffad3db72759708ea68892357b46b8ed4a0;p=nonrtric.git diff --git a/near-rt-ric-simulator/common/create_rics_json.py b/near-rt-ric-simulator/common/create_rics_json.py new file mode 100644 index 00000000..d6a095bc --- /dev/null +++ b/near-rt-ric-simulator/common/create_rics_json.py @@ -0,0 +1,63 @@ +# ============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 os +import json +import sys +import re + + + +#Create a ric info json, example input: ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:1,2,4 ricsim_g1_2:kista_ricsim_g1_2,stockholm_ricsim_g1_2:2 +#Format of string :: +#To indicate that no types exist, use 'NOTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:NOTYPE +#To indicate that special STD zero length name type, use 'EMPTYTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:EMPTYTYPE +#Save in indicated file + +try: + file_name = sys.argv[1] + ric_string = sys.argv[2] + ric_string=ric_string.strip() + ric_string = re.sub(' +',' ',ric_string) + ric_arr=[] + rics=ric_string.split(' ') + for i in range(len(rics)): + ricDict={} + items=rics[i].split(':') + ricDict['ricName']=items[0] + ricDict['managedElementIds']=items[1].split(',') + if (items[2] == "EMPTYTYPE"): + empty_arr=[] + empty_arr.append("") + ricDict['policyTypes']=empty_arr + elif (items[2] == "NOTYPE"): + empty_arr=[] + ricDict['policyTypes']=empty_arr + else: + ricDict['policyTypes']=items[2].split(',') + ricDict['state']=items[3] + ric_arr.append(ricDict) + + with open(file_name, 'w') as f: + json.dump(ric_arr, f) + + print(0) + +except Exception as e: + print(str(e)) + print(1) +sys.exit() \ No newline at end of file