From: John Spray Date: Tue, 27 Nov 2018 03:38:34 +0000 (-0600) Subject: mgr: add MgrModule.mon_command helper X-Git-Tag: v14.1.0~776^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=80b311d06e0ad6cea5f402cc9631f6ba1299f0a9;p=ceph-ci.git 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 --- 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