From 3f4d80c7e3a17cb13cdec2b6cedfded853ba564a Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 8 Jun 2016 14:22:42 +0100 Subject: [PATCH] pybind: expose mgr commands 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 --- src/pybind/ceph_argparse.py | 10 ++++++++- src/pybind/rados/rados.pyx | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 8f4786d53cd..c3aef846e19 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -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 diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 741d54fdff0..571de5ce8d9 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -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, + _cmd, _cmdlen, + _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) -- 2.39.5