From 80b311d06e0ad6cea5f402cc9631f6ba1299f0a9 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 26 Nov 2018 21:38:34 -0600 Subject: [PATCH] mgr: add MgrModule.mon_command helper The flexibilty of send_command and CommandResult is needed sometimes, but lots of places just want a simpler synchronous command to the monitor. Signed-off-by: John Spray --- src/pybind/mgr/mgr_module.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index a99df4cdfdd..49d38a95f61 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -2,6 +2,7 @@ import ceph_module # noqa import logging +import json import six import threading try: @@ -9,6 +10,7 @@ try: except ImportError: from collections import defaultdict import rados +import time PG_STATES = [ "active", @@ -566,6 +568,28 @@ class MgrModule(ceph_module.BaseMgrModule): """ return self._ceph_get_daemon_status(svc_type, svc_id) + def mon_command(self, cmd_dict): + """ + Helper for modules that do simple, synchronous mon command + execution. + + See send_command for general case. + + :return: status int, out std, err str + """ + + t1 = time.time() + result = CommandResult() + self.send_command(result, "mon", "", json.dumps(cmd_dict), "") + r = result.wait() + t2 = time.time() + + self.log.debug("mon_command: '{0}' -> {1} in {2:.3f}s".format( + cmd_dict['prefix'], r[0], t2 - t1 + )) + + return r + def send_command(self, *args, **kwargs): """ Called by the plugin to send a command to the mon -- 2.39.5