]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard_v2: Service class base code
authorRicardo Dias <rdias@suse.com>
Wed, 21 Feb 2018 16:05:40 +0000 (16:05 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:13 +0000 (13:07 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard_v2/module.py
src/pybind/mgr/dashboard_v2/services/__init__.py [new file with mode: 0644]
src/pybind/mgr/dashboard_v2/tox.ini

index ce228f33cb9beee10ea5e6c15a067a6c147ad3ab..ff6ee5e8b68396ad18c011aab23609816beb305b 100644 (file)
@@ -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 (file)
index 0000000..46ca798
--- /dev/null
@@ -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
index d4650d1995bd5bbef37fccfc97a1f11c40cc96f8..1039e3089de1222c448138094fc164d550268500 100644 (file)
@@ -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 .