From 4296962edc8838c1340abf0fdb6ea3e2f744f668 Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 7 Jun 2017 12:48:40 -0400 Subject: [PATCH] mgr/dashboard: keep a global librados instance ...so that classes that need one aren't creating their own all the time. Signed-off-by: John Spray --- src/pybind/mgr/dashboard/module.py | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 7b0e17b295825..948449f9b50d8 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -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: -- 2.39.5