3 # -------------------------------------------------------------------------
4 # Copyright (c) 2015-2017 AT&T Intellectual Property
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # -------------------------------------------------------------------------
22 """Constraint/Engine Interface
24 Utility library that defines the interface between
25 the constraints and the conductor data engine.
29 from oslo_log import log
31 LOG = log.getLogger(__name__)
34 class ConstraintEngineInterface(object):
35 def __init__(self, client):
38 def get_candidate_location(self, candidate):
39 # Try calling a method (remember, "calls" are synchronous)
40 # FIXME(jdandrea): Doing this because Music calls are expensive.
41 lat = candidate.get('latitude')
42 lon = candidate.get('longitude')
44 response = (float(lat), float(lon))
47 args = {"candidate": candidate}
48 response = self.client.call(ctxt=ctxt,
49 method="get_candidate_location",
51 LOG.debug("get_candidate_location response: {}".format(response))
54 def get_candidate_zone(self, candidate, _category=None):
55 # FIXME(jdandrea): Doing this because Music calls are expensive.
56 if _category == 'region':
57 response = candidate['location_id']
58 elif _category == 'complex':
59 response = candidate['complex_name']
62 args = {"candidate": candidate, "category": _category}
63 response = self.client.call(ctxt=ctxt,
64 method="get_candidate_zone",
66 LOG.debug("get_candidate_zone response: {}".format(response))
69 def get_candidates_from_service(self, constraint_name,
70 constraint_type, candidate_list,
71 controller, inventory_type,
72 request, cost, demand_name):
74 args = {"constraint_name": constraint_name,
75 "constraint_type": constraint_type,
76 "candidate_list": candidate_list,
77 "controller": controller,
78 "inventory_type": inventory_type,
81 "demand_name": demand_name}
82 response = self.client.call(ctxt=ctxt,
83 method="get_candidates_from_service",
85 LOG.debug("get_candidates_from_service response: {}".format(response))
86 # response is a list of (candidate, cost) tuples
89 def get_inventory_group_candidates(self, candidate_list,
90 demand_name, resolved_candidate):
91 # return a list of the "pair" candidates for the given candidate
93 args = {"candidate_list": candidate_list,
94 "demand_name": demand_name,
95 "resolved_candidate": resolved_candidate}
96 response = self.client.call(ctxt=ctxt,
97 method="get_inventory_group_candidates",
99 LOG.debug("get_inventory_group_candidates \
100 response: {}".format(response))
103 def get_candidates_by_attributes(self, demand_name,
104 candidate_list, properties):
106 args = {"candidate_list": candidate_list,
107 "properties": properties,
108 "demand_name": demand_name}
109 response = self.client.call(ctxt=ctxt,
110 method="get_candidates_by_attributes",
112 LOG.debug("get_candidates_by_attribute response: {}".format(response))
113 # response is a list of (candidate, cost) tuples