| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
__all__ = ['__version__', 'ServiceTypes'] |
| 14 |
|
| 15 |
from typing import TYPE_CHECKING, Optional |
| 16 |
|
| 17 |
import pbr.version |
| 18 |
|
| 19 |
from os_service_types.service_types import ServiceTypes |
| 20 |
|
| 21 |
if TYPE_CHECKING: |
| 22 |
from requests import sessions |
| 23 |
|
| 24 |
__version__ = pbr.version.VersionInfo('os-service-types').version_string() |
| 25 |
_service_type_manager = None |
| 26 |
|
| 27 |
|
| 28 |
def get_service_types( |
| 29 |
session: Optional['sessions.Session'] = None, |
| 30 |
only_remote: bool = False, |
| 31 |
warn: bool = False, |
| 32 |
) -> ServiceTypes: |
| 33 |
"""Return singleton instance of the ServiceTypes object. |
| 34 |
|
| 35 |
Parameters are all passed through to the |
| 36 |
:class:`~os_service_types.service_types.ServiceTypes` constructor. |
| 37 |
|
| 38 |
.. note:: |
| 39 |
|
| 40 |
Only one singleton is kept, so if instances with different parameter |
| 41 |
values are desired, directly calling the constructor is necessary. |
| 42 |
|
| 43 |
:returns: Singleton instance of |
| 44 |
:class:`~os_service_types.service_types.ServiceTypes` |
| 45 |
""" |
| 46 |
global _service_type_manager |
| 47 |
if not _service_type_manager: |
| 48 |
_service_type_manager = ServiceTypes( |
| 49 |
session, only_remote=only_remote, warn=warn |
| 50 |
) |
| 51 |
return _service_type_manager |