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"]
26 def convert_hyphen_to_under_score(hyphened_dict):
27 converted_dict = dict()
29 for key in hyphened_dict:
31 converted_dict[key.replace('-', '_')] = hyphened_dict[key]
33 converted_dict[key] = hyphened_dict[key]
34 if 'resource_version' in converted_dict:
35 converted_dict.pop('resource_version')
39 def add_query_params(filtering_attributes):
40 if not filtering_attributes:
43 for key, value in filtering_attributes.items():
44 url = f'{url}{key}={value}&'
48 def add_query_params_and_depth(filtering_attributes, depth):
49 url_with_query_params = add_query_params(filtering_attributes)
50 if url_with_query_params:
51 return f"{url_with_query_params}depth={depth}"
53 return f"?depth={depth}"
56 def get_first_level_and_second_level_filter(filtering_attributes, aai_node):
57 second_level_filters = dict()
58 valid_query_params = QUERY_PARAMS.get(aai_node)
59 for key in list(filtering_attributes):
60 if key not in valid_query_params:
61 second_level_filters[key] = filtering_attributes[key]
62 del filtering_attributes[key]
63 return second_level_filters
66 def get_inv_values_for_second_level_filter(second_level_filters, nssi_instance):
67 if not second_level_filters:
69 inventory_attributes = dict()
70 for key in list(second_level_filters):
71 inventory_attributes[key] = nssi_instance.get(key)
72 return inventory_attributes
75 def get_instance_info(nxi_instance):
77 nxi_dict['instance_id'] = nxi_instance.get('service-instance-id')
78 nxi_dict['instance_name'] = nxi_instance.get('service-instance-name')
79 if nxi_instance.get('service-function'):
80 nxi_dict['domain'] = nxi_instance.get('service-function')