]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: expose `tell` (MMonCommand) functionality
authorJohn Spray <john.spray@redhat.com>
Sat, 4 Feb 2017 21:47:32 +0000 (21:47 +0000)
committerKefu Chai <kchai@redhat.com>
Wed, 3 May 2017 02:37:17 +0000 (10:37 +0800)
To enable plugins to talk directly to daemons when they
want to.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/PyState.cc

index 1836282f270e6eed52ee3d3a951f17a3d4b2dfb2..20f9336c0c0bce947120fba872ddafc50f3d5ed7 100644 (file)
@@ -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;
 }