]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: keep a global librados instance
authorJohn Spray <john.spray@redhat.com>
Wed, 7 Jun 2017 16:48:40 +0000 (12:48 -0400)
committerJohn Spray <john.spray@redhat.com>
Thu, 8 Jun 2017 15:43:15 +0000 (11:43 -0400)
...so that classes that need one aren't creating
their own all the time.

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

index 7b0e17b2958256dc9bd95f2ff875a1e1910254b1..948449f9b50d80686dbdb58f8ee1b9624bb7313b 100644 (file)
@@ -31,6 +31,7 @@ from mgr_module import MgrModule, CommandResult
 from types import OsdMap, NotFound, Config, FsMap, MonMap, \
     PgSummary, Health, MonStatus
 
+import rados
 from rbd_ls import RbdLs
 from cephfs_clients import CephFSClients
 
@@ -63,6 +64,9 @@ class Module(MgrModule):
 
         self.log_buffer = collections.deque(maxlen=LOG_BUFFER_SIZE)
 
+        # Keep a librados instance for those that need it.
+        self._rados = None
+
         # Stateful instances of RbdLs, hold cached results.  Key to dict
         # is pool name.
         self.rbd_ls = {}
@@ -75,6 +79,28 @@ class Module(MgrModule):
         self.pool_stats = defaultdict(lambda: defaultdict(
             lambda: collections.deque(maxlen=10)))
 
+    @property
+    def rados(self):
+        """
+        A librados instance to be shared by any classes within
+        this mgr module that want one.
+        """
+        if self._rados:
+            return self._rados
+
+        from mgr_module import ceph_state
+        ctx_capsule = ceph_state.get_context()
+        self._rados = rados.Rados(context=ctx_capsule)
+        self._rados.connect()
+
+        return self._rados
+
+    def get_localized_config(self, key):
+        r = self.get_config(self.get_mgr_id() + '/' + key)
+        if r is None:
+            r = self.get_config(key)
+        return r
+
     def update_pool_stats(self):
         df = global_instance().get("df")
         pool_stats = dict([(p['id'], p['stats']) for p in df['pools']])
@@ -145,6 +171,11 @@ class Module(MgrModule):
         cherrypy.engine.exit()
         log.info("Stopped server")
 
+        log.info("Stopping librados...")
+        if self._rados:
+            self._rados.shutdown()
+        log.info("Stopped librados.")
+
     def get_latest(self, daemon_type, daemon_name, stat):
         data = self.get_counter(daemon_type, daemon_name, stat)[stat]
         if data: