1 # -------------------------------------------------------------------------
2 # Copyright (c) 2018 AT&T Intellectual Property
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # -------------------------------------------------------------------------
19 from datetime import datetime as dt
21 from osdf.logging.osdf_logging import debug_log
22 from osdf.utils.interfaces import RestClient
25 def request(req_object, osdf_config, flat_policies):
27 Process a configdb request from a Client (build Conductor API call, make the call, return result)
28 :param req_object: Request parameters from the client
29 :param osdf_config: Configuration specific to OSDF application (core + deployment)
30 :param flat_policies: policies related to PCI Opt (fetched based on request)
31 :return: response from ConfigDB (accounting for redirects from Conductor service
33 cell_list_response = {}
34 config = osdf_config.deployment
35 local_config = osdf_config.core
36 uid, passwd = config['configDbUserName'], config['configDbPassword']
37 req_id = req_object['requestInfo']['requestId']
38 transaction_id = req_object['requestInfo']['transactionId']
39 headers = dict(transaction_id=transaction_id)
41 network_id = req_object['cellInfo']['networkId']
43 cell_list_response['network_id'] = network_id
45 ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
47 rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers)
49 cell_list_url = '{}/{}/{}/{}'.format(config['configDbUrl'], config['configDbGetCellListUrl'], network_id, ts)
51 cell_list_resp = rc.request(raw_response=True, url=cell_list_url)
52 cell_resp = cell_list_resp.json()
56 for cell_id in cell_resp:
57 cell_info = {'cell_id': cell_id, 'id': count}
58 nbr_list_url = '{}/{}/{}/{}'.format(config['configDbUrl'], config['configDbGetNbrListUrl'], cell_id, ts)
59 nbr_list_raw = rc.request(url=nbr_list_url, raw_response=True)
60 cell_info['nbr_list'] = get_neighbor_list(nbr_list_raw.json())
61 cell_list.append(cell_info)
64 cell_list_response['cell_list'] = cell_list
65 return cell_resp, cell_list_response
68 def get_neighbor_list(nbr_list_response):
69 return nbr_list_response.get('nbrList', [])