Release ricsdl new version 1.0.2
[ric-plt/sdlpy.git] / ricsdl-package / ricsdl / configuration.py
1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2018-2019 Nokia.
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 # This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 # platform project (RICP).
19 #
20
21
22 """The module provides implementation of Shared Data Layer (SDL) configurability."""
23 import os
24 from collections import namedtuple
25
26
27 class _Configuration():
28     """This class implements Shared Data Layer (SDL) configurability."""
29     Params = namedtuple('Params', ['db_host', 'db_port', 'db_sentinel_port',
30                                    'db_sentinel_master_name'])
31
32     def __init__(self):
33         self.params = self._read_configuration()
34
35     def __str__(self):
36         return str(
37             {
38                 "DB host": self.params.db_host,
39                 "DB port": self.params.db_port,
40                 "DB master sentinel": self.params.db_sentinel_master_name,
41                 "DB sentinel port": self.params.db_sentinel_port
42             }
43         )
44
45     def get_params(self):
46         """Return SDL configuration."""
47         return self.params
48
49     @classmethod
50     def _read_configuration(cls):
51         return _Configuration.Params(db_host=os.getenv('DBAAS_SERVICE_HOST'),
52                                      db_port=os.getenv('DBAAS_SERVICE_PORT'),
53                                      db_sentinel_port=os.getenv('DBAAS_SERVICE_SENTINEL_PORT'),
54                                      db_sentinel_master_name=os.getenv('DBAAS_MASTER_NAME'))