Fix issues in Slice selection
[optf/osdf.git] / apps / pci / optimizers / config_request.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2018 AT&T Intellectual Property
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16 # -------------------------------------------------------------------------
17 #
18
19 from apps.pci.optimizers.config.config_client import ConfigClient
20
21
22 def request(req_object, osdf_config, flat_policies):
23     """Process a configdb request from a Client (build Conductor API call, make the call, return result)
24
25     :param req_object: Request parameters from the client
26     :param osdf_config: Configuration specific to OSDF application (core + deployment)
27     :param flat_policies: policies related to PCI Opt (fetched based on request)
28     :return: response from ConfigDB (accounting for redirects from Conductor service
29     """
30     cell_list_response = {}
31
32     network_id = req_object['cellInfo']['networkId']
33
34     cell_list_response['network_id'] = network_id
35
36     config = osdf_config.deployment
37
38     config_client = ConfigClient.create(config['configClientType'])
39
40     cell_resp = config_client.get_cell_list(network_id)
41
42     cell_list = []
43     count = 0
44     for cell_id in cell_resp:
45         cell_info = {
46             'cell_id': cell_id,
47             'id': count,
48             'nbr_list': config_client.get_nbr_list(network_id, cell_id)
49         }
50         cell_list.append(cell_info)
51         count += 1
52
53     cell_list_response['cell_list'] = cell_list
54
55     return cell_resp, cell_list_response