]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: add MgrModule.mon_command helper
authorJohn Spray <john.spray@redhat.com>
Tue, 27 Nov 2018 03:38:34 +0000 (21:38 -0600)
committerSage Weil <sage@redhat.com>
Tue, 27 Nov 2018 03:43:43 +0000 (21:43 -0600)
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 <john.spray@redhat.com>
src/pybind/mgr/mgr_module.py

index a99df4cdfddeaee8f68d253c0ce6ae5ec691fa2e..49d38a95f61d805c97c22432ebc72f658fe96e78 100644 (file)
@@ -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