From 62cb512e4740f1f78f516b4f2179c1123fae1b36 Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 26 Jul 2017 12:31:13 -0400 Subject: [PATCH] pybind: update MgrModule for ceph_state->ceph_module & tidy up the places where ceph_state was getting used outside of MgrModule. Signed-off-by: John Spray --- src/pybind/mgr/dashboard/module.py | 3 +- src/pybind/mgr/dashboard/rbd_ls.py | 4 +-- src/pybind/mgr/mgr_module.py | 54 +++++++++++++++++------------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 13e418489ba..e2c40a01adf 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -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() diff --git a/src/pybind/mgr/dashboard/rbd_ls.py b/src/pybind/mgr/dashboard/rbd_ls.py index 6588766a7da..87315a91bb4 100644 --- a/src/pybind/mgr/dashboard/rbd_ls.py +++ b/src/pybind/mgr/dashboard/rbd_ls.py @@ -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']] diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 22ee148a1c9..fdcd24a9203 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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): """ -- 2.39.5