From: Ricardo Dias Date: Wed, 21 Feb 2018 16:05:40 +0000 (+0000) Subject: mgr/dashboard_v2: Service class base code X-Git-Tag: v13.0.2~84^2~41 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a881e435e916dab25b04f96c3897e37a014ac1d4;p=ceph.git mgr/dashboard_v2: Service class base code Signed-off-by: Ricardo Dias --- diff --git a/src/pybind/mgr/dashboard_v2/module.py b/src/pybind/mgr/dashboard_v2/module.py index ce228f33cb9be..ff6ee5e8b6839 100644 --- a/src/pybind/mgr/dashboard_v2/module.py +++ b/src/pybind/mgr/dashboard_v2/module.py @@ -23,6 +23,7 @@ if 'COVERAGE_ENABLED' in os.environ: from .controllers.auth import Auth from .tools import load_controllers, json_error_page, SessionExpireAtBrowserCloseTool, \ NotificationQueue +from .services import Service from . import logger @@ -67,6 +68,8 @@ class Module(MgrModule): self._url_prefix = '' def configure_cherrypy(self): + Service.mgr = self # injects module instance into Service class + server_addr = self.get_localized_config('server_addr', '::') server_port = self.get_localized_config('server_port', '8080') if server_addr is None: diff --git a/src/pybind/mgr/dashboard_v2/services/__init__.py b/src/pybind/mgr/dashboard_v2/services/__init__.py new file mode 100644 index 0000000000000..46ca798bdb981 --- /dev/null +++ b/src/pybind/mgr/dashboard_v2/services/__init__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from six import add_metaclass + + +class ServiceMeta(type): + @property + def mgr(cls): + """ + :return: Returns the MgrModule instance of this Ceph dashboard module. + """ + return cls._mgr_module + + @mgr.setter + def mgr(cls, value): + """ + :param value: The MgrModule instance of the Ceph dashboard module. + """ + cls._mgr_module = value + + +@add_metaclass(ServiceMeta) +class Service(object): + """ + Base class for all services. + """ + _mgr_module = None + + @property + def mgr(self): + """ + :return: Returns the MgrModule instance of this Ceph module. + """ + return self._mgr_module diff --git a/src/pybind/mgr/dashboard_v2/tox.ini b/src/pybind/mgr/dashboard_v2/tox.ini index d4650d1995bd5..1039e3089de12 100644 --- a/src/pybind/mgr/dashboard_v2/tox.ini +++ b/src/pybind/mgr/dashboard_v2/tox.ini @@ -72,5 +72,5 @@ setenv = LD_LIBRARY_PATH = {toxinidir}/../../../../build/lib deps=-r{toxinidir}/requirements.txt commands= - pylint --rcfile=.pylintrc --jobs=5 . module.py tools.py controllers tests + pylint --rcfile=.pylintrc --jobs=5 . module.py tools.py controllers tests services pycodestyle --max-line-length=100 --exclude=python2.7,.tox,venv,frontend --ignore=E402,E121,E123,E126,E226,E24,E704,W503 .