1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2018-2019 Nokia.
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.
17 # This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 # platform project (RICP).
22 """The module provides implementation of Shared Data Layer (SDL) configurability."""
25 from collections import namedtuple
28 class DbBackendType(Enum):
29 """Enumeration class of supported SDL database backend types."""
34 class _Configuration():
35 """This class implements Shared Data Layer (SDL) configurability."""
36 Params = namedtuple('Params', ['db_host', 'db_port', 'db_sentinel_port',
37 'db_sentinel_master_name',
38 'db_cluster_addr_list', 'db_type'])
40 def __init__(self, fake_db_backend):
41 self.params = self._read_configuration(fake_db_backend)
46 "DB host": self.params.db_host,
47 "DB port": self.params.db_port,
48 "DB master sentinel": self.params.db_sentinel_master_name,
49 "DB sentinel port": self.params.db_sentinel_port,
50 "DB cluster address list": self.params.db_cluster_addr_list,
51 "DB type": self.params.db_type.name,
56 """Return SDL configuration."""
60 def _read_configuration(cls, fake_db_backend):
61 backend_type = DbBackendType.REDIS
63 if fake_db_backend.lower() != 'dict':
64 msg = ("Configuration error: "
65 "SDL instance was initiated with wrong "
66 "'fake_db_backend' argument value: {}. "
67 "Value 'dict' is only supported.".
68 format(fake_db_backend))
71 backend_type = DbBackendType.FAKE_DICT
73 return _Configuration.Params(db_host=os.getenv('DBAAS_SERVICE_HOST'),
74 db_port=os.getenv('DBAAS_SERVICE_PORT'),
75 db_sentinel_port=os.getenv('DBAAS_SERVICE_SENTINEL_PORT'),
76 db_sentinel_master_name=os.getenv('DBAAS_MASTER_NAME'),
77 db_cluster_addr_list=os.getenv('DBAAS_CLUSTER_ADDR_LIST'),