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 # -------------------------------------------------------------------------
22 from conductor.data.plugins.inventory_provider.candidates.candidate import Candidate
26 return list(filter(None, x))[0]
29 ATTRIBUTE_AGGREGATION = {
30 "max_bandwidth": copy_first,
34 "resource_sharing_level": copy_first,
35 "s_nssai": copy_first,
36 "plmn_id_list": copy_first,
37 "availability": copy_first,
39 "reliability": copy_first,
40 "max_number_of_ues": copy_first,
41 "exp_data_rate_ul": min,
42 "exp_data_rate_dl": min,
43 "ue_mobility_level": copy_first,
44 "coverage_area_ta_list": copy_first,
45 "activity_factor": copy_first,
46 "survival_time": copy_first,
47 "max_number_of_conns": copy_first
51 class SliceProfilesCandidate(Candidate):
53 def __init__(self, **kwargs):
54 super().__init__(kwargs["info"])
55 self.subnet_requirements = kwargs["subnet_requirements"]
56 if "slice_requirements" in kwargs:
57 self.slice_requirements = kwargs["slice_requirements"]
59 self.slice_requirements = None
60 self.other = kwargs["default_fields"]
62 def convert_nested_dict_to_dict(self):
63 nested_dict = self.__dict__
65 if not self.slice_requirements:
66 self.slice_requirements = get_slice_requirements(self.subnet_requirements)
68 slice_profile_candidate = copy.deepcopy(nested_dict)
69 slice_profile_candidate.pop("slice_requirements")
70 slice_profile_candidate.pop("subnet_requirements")
71 slice_profile_candidate.pop("other")
72 slice_profile_candidate.update(self.slice_requirements)
73 for subnet, slice_profile in self.subnet_requirements.items():
74 subnet_req = {f'{subnet}_{key}': value for key, value in slice_profile.items()}
75 slice_profile_candidate.update(subnet_req)
77 slice_profile_candidate.update(self.other)
79 return slice_profile_candidate
82 def get_slice_requirements(subnet_requirements):
83 slice_requirements_keys = set()
84 for slice_profile in subnet_requirements.values():
85 slice_requirements_keys.update(slice_profile.keys())
87 slice_profile_tuples = {}
88 for key in slice_requirements_keys:
90 for slice_profile in subnet_requirements.values():
91 attributes.append(slice_profile.get(key))
92 slice_profile_tuples[key] = attributes
94 return {attr: ATTRIBUTE_AGGREGATION[attr](values) for attr, values in slice_profile_tuples.items()}