]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: expose mgr commands
authorJohn Spray <john.spray@redhat.com>
Wed, 8 Jun 2016 13:22:42 +0000 (14:22 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 29 Sep 2016 16:26:55 +0000 (17:26 +0100)
This is "tell mgr" at the moment but it should
be a slicker syntax later (ceph.in is awkward
to refactor just now)

Signed-off-by: John Spray <john.spray@redhat.com>
src/pybind/ceph_argparse.py
src/pybind/rados/rados.pyx

index 8f4786d53cd2942426bb7acf07b3f6dccba46879..c3aef846e19e658889cef69ac8ef1c0d292afc31 100644 (file)
@@ -388,11 +388,15 @@ class CephName(CephArgtype):
         if s == '*':
             self.val = s
             return
+        elif s == "mgr":
+            self.nametype = "mgr"
+            self.val = s
+            return
         if s.find('.') == -1:
             raise ArgumentFormat('CephName: no . in {0}'.format(s))
         else:
             t, i = s.split('.', 1)
-            if t not in ('osd', 'mon', 'client', 'mds'):
+            if t not in ('osd', 'mon', 'client', 'mds', 'mgr'):
                 raise ArgumentValid('unknown type ' + t)
             if t == 'osd':
                 if i != '*':
@@ -1228,6 +1232,10 @@ def send_command(cluster, target=('mon', ''), cmd=None, inbuf=b'', timeout=0,
             ret, outbuf, outs = run_in_thread(
                 cluster.osd_command, osdid, cmd, inbuf, timeout)
 
+        elif target[0] == 'mgr':
+            ret, outbuf, outs = run_in_thread(
+                cluster.mgr_command, cmd, inbuf, timeout)
+
         elif target[0] == 'pg':
             pgid = target[1]
             # pgid will already be in the command for the pg <pgid>
index 741d54fdff0f2827555167e3be0ba8a63524c6ef..571de5ce8d91714d1691f203a1e8129517fbeff8 100644 (file)
@@ -155,6 +155,10 @@ cdef extern from "rados/librados.h" nogil:
                           const char *inbuf, size_t inbuflen,
                           char **outbuf, size_t *outbuflen,
                           char **outs, size_t *outslen)
+    int rados_mgr_command(rados_t cluster, const char **cmd, size_t cmdlen,
+                          const char *inbuf, size_t inbuflen,
+                          char **outbuf, size_t *outbuflen,
+                          char **outs, size_t *outslen)
     int rados_mon_command_target(rados_t cluster, const char *name, const char **cmd, size_t cmdlen,
                                  const char *inbuf, size_t inbuflen,
                                  char **outbuf, size_t *outbuflen,
@@ -1225,6 +1229,47 @@ Rados object in state %s." % self.state)
         finally:
             free(_cmd)
 
+    def mgr_command(self, cmd, inbuf, timeout=0):
+        """
+        returns (int ret, string outbuf, string outs)
+        """
+        # NOTE(sileht): timeout is ignored because C API doesn't provide
+        # timeout argument, but we keep it for backward compat with old python binding
+        self.require_state("connected")
+
+        cmd = cstr_list(cmd, 'cmd')
+        inbuf = cstr(inbuf, 'inbuf')
+
+        cdef:
+            char **_cmd = to_bytes_array(cmd)
+            size_t _cmdlen = len(cmd)
+
+            char *_inbuf = inbuf
+            size_t _inbuf_len = len(inbuf)
+
+            char *_outbuf
+            size_t _outbuf_len
+            char *_outs
+            size_t _outs_len
+
+        try:
+            with nogil:
+                ret = rados_mgr_command(self.cluster,
+                                        <const char **>_cmd, _cmdlen,
+                                        <const char*>_inbuf, _inbuf_len,
+                                        &_outbuf, &_outbuf_len,
+                                        &_outs, &_outs_len)
+
+            my_outs = decode_cstr(_outs[:_outs_len])
+            my_outbuf = _outbuf[:_outbuf_len]
+            if _outs_len:
+                rados_buffer_free(_outs)
+            if _outbuf_len:
+                rados_buffer_free(_outbuf)
+            return (ret, my_outbuf, my_outs)
+        finally:
+            free(_cmd)
+
     def pg_command(self, pgid, cmd, inbuf, timeout=0):
         """
         pg_command(pgid, cmd, inbuf, outbuf, outbuflen, outs, outslen)