BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1 | # ============LICENSE_START=============================================== |
| 2 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 3 | # ======================================================================== |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 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. |
| 15 | # ============LICENSE_END================================================= |
| 16 | # |
| 17 | |
| 18 | import os |
| 19 | import json |
| 20 | import sys |
| 21 | import re |
| 22 | |
| 23 | |
| 24 | |
| 25 | #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 |
| 26 | #Format of string <ric-id>:<comma-separated-list-of-me's>:<comma-separated-list-of-policy-type-ids> |
| 27 | #To indicate that no types exist, use 'NOTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:NOTYPE |
| 28 | #To indicate that special STD zero length name type, use 'EMPTYTYPE'. Ex. ricsim_g1_1:kista_ricsim_g1_1,stockholm_ricsim_g1_1:EMPTYTYPE |
| 29 | #Save in indicated file |
| 30 | |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 31 | #arg: <file-name-for-result> <api-version> <list-ric-info> |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 32 | try: |
| 33 | file_name = sys.argv[1] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 34 | api_version=sys.argv[2] |
| 35 | ric_string = sys.argv[3] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 36 | ric_string=ric_string.strip() |
| 37 | ric_string = re.sub(' +',' ',ric_string) |
| 38 | ric_arr=[] |
| 39 | rics=ric_string.split(' ') |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 40 | if (api_version == "V2"): |
| 41 | param_ric='ric_id' |
| 42 | param_me='managed_element_ids' |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 43 | param_policy_type='policytype_ids' |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 44 | param_state='state' |
raviteja.karumuri | 64755e0 | 2024-05-29 18:20:42 +0100 | [diff] [blame] | 45 | elif (api_version == "V3"): |
| 46 | param_ric='ricId' |
| 47 | param_me='managedElementIds' |
| 48 | param_policy_type='policyTypeIds' |
| 49 | param_state='state' |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 50 | else: |
| 51 | param_ric='ricName' |
| 52 | param_me='managedElementIds' |
| 53 | param_policy_type='policyTypes' |
| 54 | param_state='state' |
| 55 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 56 | for i in range(len(rics)): |
| 57 | ricDict={} |
| 58 | items=rics[i].split(':') |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 59 | ricDict[param_ric]=items[0] |
| 60 | ricDict[param_me]=items[1].split(',') |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 61 | if (items[2] == "EMPTYTYPE"): |
| 62 | empty_arr=[] |
| 63 | empty_arr.append("") |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 64 | ricDict[param_policy_type]=empty_arr |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 65 | elif (items[2] == "NOTYPE"): |
| 66 | empty_arr=[] |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 67 | ricDict[param_policy_type]=empty_arr |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 68 | else: |
BjornMagnussonXA | 4207b83 | 2020-11-03 09:52:49 +0100 | [diff] [blame] | 69 | ricDict[param_policy_type]=items[2].split(',') |
| 70 | ricDict[param_state]=items[3] |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 71 | ric_arr.append(ricDict) |
| 72 | |
| 73 | with open(file_name, 'w') as f: |
| 74 | json.dump(ric_arr, f) |
| 75 | |
| 76 | print(0) |
| 77 | |
| 78 | except Exception as e: |
| 79 | print(str(e)) |
| 80 | print(1) |
| 81 | sys.exit() |