Add NSSI candidate
[optf/has.git] / conductor / conductor / data / plugins / inventory_provider / candidates / candidate.py
1 #
2 # -------------------------------------------------------------------------
3 #   Copyright (C) 2020 Wipro Limited.
4 #
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
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17 # -------------------------------------------------------------------------
18 #
19
20 class Candidate(object):
21     def __init__(self, info):
22         self.candidate_id = info.get('candidate_id')
23         if info.get('candidate_type'):
24             self.candidate_type = info.get('candidate_type')
25         if info.get('service_resource_id'):
26             self.service_resource_id = info.get('service_resource_id')
27         self.inventory_provider = info.get('inventory_provider')
28         self.inventory_type = info.get('inventory_type')
29         self.uniqueness = info.get('uniqueness')
30         self.cost = info.get('cost')
31
32     def convert_nested_dict_to_dict(self):
33         candidate = dict()
34         nested_dict = self.__dict__
35         keys = nested_dict.keys()
36         for key in keys:
37             if type(nested_dict.get(key)) == dict:
38                 candidate.update(nested_dict.get(key, {}))
39             else:
40                 candidate[key] = nested_dict.get(key, "")
41         return candidate
42
43     @staticmethod
44     def build_candidate_info(inv_prov, inv_type, cost, uniqueness, id, service_resource_id=None):
45         info = dict()
46         info['candidate_id'] = id
47         # info['candidate_type']
48         info['inventory_provider'] = inv_prov
49         info['inventory_type'] = inv_type
50         info['uniqueness'] = uniqueness
51         info['cost'] = cost
52         info['service_resource_id'] = service_resource_id
53         return info