From 954c0b9c900bff73384e724bf5ff3df585c8498d Mon Sep 17 00:00:00 2001 From: John Spray Date: Sat, 4 Feb 2017 21:47:32 +0000 Subject: [PATCH] mgr: expose `tell` (MMonCommand) functionality To enable plugins to talk directly to daemons when they want to. Signed-off-by: John Spray --- src/mgr/PyState.cc | 51 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/mgr/PyState.cc b/src/mgr/PyState.cc index 1836282f270e6..20f9336c0c0bc 100644 --- a/src/mgr/PyState.cc +++ b/src/mgr/PyState.cc @@ -82,11 +82,18 @@ static PyObject* ceph_send_command(PyObject *self, PyObject *args) { char *handle = nullptr; + + // Like mon, osd, mds + char *type = nullptr; + + // Like "23" for an OSD or "myid" for an MDS + char *name = nullptr; + char *cmd_json = nullptr; char *tag = nullptr; PyObject *completion = nullptr; - if (!PyArg_ParseTuple(args, "sOss:ceph_send_command", - &handle, &completion, &cmd_json, &tag)) { + if (!PyArg_ParseTuple(args, "sOssss:ceph_send_command", + &handle, &completion, &type, &name, &cmd_json, &tag)) { return nullptr; } @@ -99,12 +106,40 @@ ceph_send_command(PyObject *self, PyObject *args) Py_DECREF(set_fn); auto c = new MonCommandCompletion(completion, tag); - global_handle->get_monc().start_mon_command( - {cmd_json}, - {}, - &c->outbl, - &c->outs, - c); + if (std::string(type) == "mon") { + global_handle->get_monc().start_mon_command( + {cmd_json}, + {}, + &c->outbl, + &c->outs, + c); + } else if (std::string(type) == "osd") { + std::string err; + uint64_t osd_id = strict_strtoll(name, 10, &err); + if (!err.empty()) { + // TODO: raise exception + return nullptr; + } + + ceph_tid_t tid; + global_handle()->get_objecter().osd_command( + osd_id, + {cmd_json}, + {}, + &tid, + &c->outbl, + &c->outs, + c); + } else if (std::string(type) == "mds") { + // TODO: expose a Client instance + return nullptr; + } else if (std::string(type) == "pg") { + // TODO: expose objecter::pg_command + return nullptr; + } else { + // TODO: raise exception + return nullptr; + } Py_RETURN_NONE; } -- 2.39.5