]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind: update MgrModule for ceph_state->ceph_module
authorJohn Spray <john.spray@redhat.com>
Wed, 26 Jul 2017 16:31:13 +0000 (12:31 -0400)
committerJohn Spray <john.spray@redhat.com>
Wed, 1 Nov 2017 12:20:19 +0000 (08:20 -0400)
& tidy up the places where ceph_state was getting
used outside of MgrModule.

Signed-off-by: John Spray <john.spray@redhat.com>
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/dashboard/rbd_ls.py
src/pybind/mgr/mgr_module.py

index 13e418489bad80f0e8624b86fdc3b2d5e388d7ec..e2c40a01adfcbee33f3d77d71ec69ba10a046bec 100644 (file)
@@ -114,8 +114,7 @@ class Module(MgrModule):
         if self._rados:
             return self._rados
 
-        from mgr_module import ceph_state
-        ctx_capsule = ceph_state.get_context()
+        ctx_capsule = self.get_context()
         self._rados = rados.Rados(context=ctx_capsule)
         self._rados.connect()
 
index 6588766a7dad18962e8de2d5dff28f84b093bc6e..87315a91bb41a11482e3de84d17c1ce5eaf6cc46 100644 (file)
@@ -6,8 +6,8 @@ from remote_view_cache import RemoteViewCache
 
 class RbdPoolLs(RemoteViewCache):
     def _get(self):
-        from mgr_module import ceph_state
-        ctx_capsule = ceph_state.get_context()
+        ctx_capsule = self._module.get_context()
+
 
         osd_map = self._module.get_sync_object(OsdMap).data
         osd_pools = [pool['pool_name'] for pool in osd_map['pools']]
index 22ee148a1c941ca57740de86940f99c3085bcdb2..fdcd24a92030cb2926b5596fa25be5dcdb433c38 100644 (file)
@@ -1,8 +1,9 @@
 
-import ceph_state  #noqa
+import ceph_module  # noqa
 import ceph_osdmap  #noqa
 import ceph_osdmap_incremental  #noqa
 import ceph_crushmap  #noqa
+
 import json
 import logging
 import threading
@@ -115,7 +116,7 @@ class CRUSHMap(object):
         return { int(k): v for k, v in uglymap.get('weights', {}).iteritems() }
 
 
-class MgrModule(object):
+class MgrModule(ceph_module.BaseMgrModule):
     COMMANDS = []
 
     # Priority definitions for perf counters
@@ -135,17 +136,18 @@ class MgrModule(object):
     PERFCOUNTER_HISTOGRAM = 0x10
     PERFCOUNTER_TYPE_MASK = ~2
 
-    def __init__(self, handle):
-        self._handle = handle
-        self._logger = logging.getLogger(handle)
+    def __init__(self, module_name, py_modules_ptr, this_ptr):
+        super(MgrModule, self).__init__(py_modules_ptr, this_ptr)
+        self._logger = logging.getLogger(module_name)
 
         # Don't filter any logs at the python level, leave it to C++
         self._logger.setLevel(logging.DEBUG)
 
         # FIXME: we should learn the log level from C++ land, and then
-        # avoid calling ceph_state.log when we know a message is of
+        # avoid calling the C++ level log when we know a message is of
         # an insufficient level to be ultimately output
 
+        module_inst = self
         class CPlusPlusHandler(logging.Handler):
             def emit(self, record):
                 if record.levelno <= logging.DEBUG:
@@ -157,11 +159,11 @@ class MgrModule(object):
                 else:
                     ceph_level = 0
 
-                ceph_state.log(handle, ceph_level, self.format(record))
+                module_inst._ceph_log(ceph_level, self.format(record))
 
         self._logger.addHandler(CPlusPlusHandler())
 
-        self._version = ceph_state.get_version()
+        self._version = self._ceph_get_version()
 
         self._perf_schema_cache = None
 
@@ -184,6 +186,12 @@ class MgrModule(object):
     def version(self):
         return self._version
 
+    def get_context(self):
+        """
+        :return: a Python capsule containing a C++ CephContext pointer
+        """
+        return self._ceph_get_context()
+
     def notify(self, notify_type, notify_id):
         """
         Called by the ceph-mgr service to notify the Python plugin
@@ -215,7 +223,7 @@ class MgrModule(object):
         """
         Called by the plugin to load some cluster state from ceph-mgr
         """
-        return ceph_state.get(self._handle, data_name)
+        return self._ceph_get(data_name)
 
     def get_server(self, hostname):
         """
@@ -224,7 +232,7 @@ class MgrModule(object):
 
         :param hostname: a hostame
         """
-        return ceph_state.get_server(self._handle, hostname)
+        return self._ceph_get_server(hostname)
 
     def get_perf_schema(self, svc_type, svc_name):
         """
@@ -236,7 +244,7 @@ class MgrModule(object):
         :param svc_name:
         :return: list of dicts describing the counters requested
         """
-        return ceph_state.get_perf_schema(self._handle, svc_type, svc_name)
+        return self._ceph_get_perf_schema(svc_type, svc_name)
 
     def get_counter(self, svc_type, svc_name, path):
         """
@@ -248,14 +256,14 @@ class MgrModule(object):
         :param path:
         :return: A list of two-element lists containing time and value
         """
-        return ceph_state.get_counter(self._handle, svc_type, svc_name, path)
+        return self._ceph_get_counter(svc_type, svc_name, path)
 
     def list_servers(self):
         """
         Like ``get_server``, but instead of returning information
         about just one node, return all the nodes in an array.
         """
-        return ceph_state.get_server(self._handle, None)
+        return self._ceph_get_server(None)
 
     def get_metadata(self, svc_type, svc_id):
         """
@@ -265,7 +273,7 @@ class MgrModule(object):
         :param svc_id: string
         :return: dict
         """
-        return ceph_state.get_metadata(self._handle, svc_type, svc_id)
+        return self._ceph_get_metadata(svc_type, svc_id)
 
     def get_daemon_status(self, svc_type, svc_id):
         """
@@ -275,14 +283,14 @@ class MgrModule(object):
         :param svc_id: string
         :return: dict
         """
-        return ceph_state.get_daemon_status(self._handle, svc_type, svc_id)
+        return self._ceph_get_daemon_status(svc_type, svc_id)
 
     def send_command(self, *args, **kwargs):
         """
         Called by the plugin to send a command to the mon
         cluster.
         """
-        ceph_state.send_command(self._handle, *args, **kwargs)
+        self._ceph_send_command(*args, **kwargs)
 
     def set_health_checks(self, checks):
         """
@@ -306,7 +314,7 @@ class MgrModule(object):
 
         :param list: dict of health check dicts
         """
-        ceph_state.set_health_checks(self._handle, checks)
+        self._ceph_set_health_checks(checks)
 
     def handle_command(self, cmd):
         """
@@ -332,7 +340,7 @@ class MgrModule(object):
 
         :return: str
         """
-        return ceph_state.get_mgr_id()
+        return self._ceph_get_mgr_id()
 
     def get_config(self, key, default=None):
         """
@@ -341,7 +349,7 @@ class MgrModule(object):
         :param key: str
         :return: str
         """
-        r = ceph_state.get_config(self._handle, key)
+        r = self._ceph_get_config(key)
         if r is None:
             return default
         else:
@@ -354,7 +362,7 @@ class MgrModule(object):
         :param key_prefix: str
         :return: str
         """
-        return ceph_state.get_config_prefix(self._handle, key_prefix)
+        return self._ceph_get_config_prefix(key_prefix)
 
     def get_localized_config(self, key, default=None):
         """
@@ -378,7 +386,7 @@ class MgrModule(object):
         :param key: str
         :param val: str
         """
-        ceph_state.set_config(self._handle, key, val)
+        self._ceph_set_config(key, val)
 
     def set_localized_config(self, key, val):
         """
@@ -387,7 +395,7 @@ class MgrModule(object):
         :param default: str
         :return: str
         """
-        return self.set_config(self.get_mgr_id() + '/' + key, val)
+        return self._ceph_set_config(self.get_mgr_id() + '/' + key, val)
 
     def set_config_json(self, key, val):
         """
@@ -396,7 +404,7 @@ class MgrModule(object):
         :param key: str
         :param val: json-serializable object
         """
-        self.set_config(key, json.dumps(val))
+        self._ceph_set_config(key, json.dumps(val))
 
     def get_config_json(self, key):
         """