2 # -------------------------------------------------------------------------
3 # Copyright (C) 2020 Wipro Limited.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # -------------------------------------------------------------------------
20 QUERY_PARAMS = {'service_instance': ["service-instance-id", "service-instance-name", "environment-context",
21 "workload-context", "model-invariant-id", "model-version-id", "widget-model-id",
22 "widget-model-version", "service-instance-location-id", "orchestration-status"],
27 def convert_hyphen_to_under_score(hyphened_dict):
28 converted_dict = dict()
30 for key in hyphened_dict:
32 converted_dict[key.replace('-', '_').lower()] = hyphened_dict[key]
34 converted_dict[key] = hyphened_dict[key]
35 if 'resource_version' in converted_dict:
36 converted_dict.pop('resource_version')
40 def add_query_params(filtering_attributes):
41 if not filtering_attributes:
44 for key, value in filtering_attributes.items():
45 url = f'{url}{key}={value}&'
49 def add_query_params_and_depth(filtering_attributes, depth):
50 url_with_query_params = add_query_params(filtering_attributes)
51 if url_with_query_params:
52 return f"{url_with_query_params}depth={depth}"
54 return f"?depth={depth}"
57 def get_first_level_and_second_level_filter(filtering_attributes, aai_node):
58 second_level_filters = dict()
59 valid_query_params = QUERY_PARAMS.get(aai_node)
60 for key in list(filtering_attributes):
61 if key not in valid_query_params:
62 second_level_filters[key] = filtering_attributes[key]
63 del filtering_attributes[key]
64 return second_level_filters
67 def get_inv_values_for_second_level_filter(second_level_filters, nssi_instance):
68 if not second_level_filters:
70 inventory_attributes = dict()
71 for key in list(second_level_filters):
72 inventory_attributes[key] = nssi_instance.get(key)
73 return inventory_attributes
76 def get_instance_info(nxi_instance):
78 nxi_dict['instance_id'] = nxi_instance.get('service-instance-id')
79 nxi_dict['instance_name'] = nxi_instance.get('service-instance-name')
80 if nxi_instance.get('workload-context'):
81 nxi_dict['domain'] = nxi_instance.get('workload-context')
85 def get_nst_info(nst_instance):
87 nst_dict['model_invariant_id'] = nst_instance.get('model-invariant-id')
88 nst_dict['model_type'] = nst_instance.get('model-type')
89 nst_dict['model_role'] = nst_instance.get('model-role')
93 def get_model_ver_info(model_version):
94 for key in list(model_version):
95 if "model-elements" in key:
96 del model_version["model-elements"]
100 def get_profiles(profile_instances, profile_type):
101 profile_type_plural = profile_type + 's'
102 return [x[profile_type_plural][profile_type][0] for x in profile_instances]