From 221e3e01c74f522986ac92ec35b3f60eeaabe0bf Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Mon, 15 Feb 2021 04:21:56 -0500 Subject: [PATCH] pybind/mirroring: interface to fetch mirror daemon status Signed-off-by: Venky Shankar --- .../mgr/mirroring/fs/snapshot_mirror.py | 31 +++++++++++++++++++ src/pybind/mgr/mirroring/module.py | 6 ++++ 2 files changed, 37 insertions(+) diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index e9e3e321964..44aafb49237 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -599,3 +599,34 @@ class FSSnapshotMirror: return fspolicy.summary() except MirrorException as me: return me.args[0], '', me.args[1] + + def daemon_status(self, filesystem): + try: + with self.lock: + if not self.filesystem_exist(filesystem): + raise MirrorException(-errno.ENOENT, f'filesystem {filesystem} does not exist') + fspolicy = self.pool_policy.get(filesystem, None) + if not fspolicy: + raise MirrorException(-errno.EINVAL, f'filesystem {filesystem} is not mirrored') + daemons = {} + sm = self.mgr.get('service_map') + daemon_entry = sm['services'].get('cephfs-mirror', None) + if daemon_entry: + for daemon_key in daemon_entry['daemons']: + try: + daemon_id = int(daemon_key) + daemon_status = self.mgr.get_daemon_status('cephfs-mirror', daemon_key) + if not daemon_status: + # temporary, should get updated soon + log.debug(f'daemon status not yet availble for daemon_id {daemon_id}') + continue + try: + daemons[daemon_id] = json.loads(daemon_status['status_json']) + except KeyError: + # temporary, should get updated soon + log.debug(f'daemon status not yet available for daemon_id {daemon_id}') + except ValueError: + pass + return 0, json.dumps(daemons), '' + except MirrorException as me: + return me.args[0], '', me.args[1] diff --git a/src/pybind/mgr/mirroring/module.py b/src/pybind/mgr/mirroring/module.py index 5549e9926af..0ff3c084b9d 100644 --- a/src/pybind/mgr/mirroring/module.py +++ b/src/pybind/mgr/mirroring/module.py @@ -68,3 +68,9 @@ class Module(MgrModule): fs_name: str): """Get current instance to directory map for a filesystem""" return self.fs_snapshot_mirror.show_distribution(fs_name) + + @CLIReadCommand('fs snapshot mirror daemon status') + def snapshot_mirror_daemon_status(self, + fs_name: str): + """Get mirror daemon status""" + return self.fs_snapshot_mirror.daemon_status(fs_name) -- 2.39.5