]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr, pybind/mgr: pass inbuf (ceph -i <file>) to modules 22634/head
authorDan Mick <dan.mick@redhat.com>
Wed, 20 Jun 2018 03:36:08 +0000 (20:36 -0700)
committerDan Mick <dan.mick@redhat.com>
Fri, 22 Jun 2018 21:55:34 +0000 (14:55 -0700)
Modules may wish to receive bulk data; allow it

Signed-off-by: Dan Mick <dan.mick@redhat.com>
21 files changed:
src/mgr/ActivePyModule.cc
src/mgr/ActivePyModule.h
src/mgr/ActivePyModules.cc
src/mgr/ActivePyModules.h
src/mgr/DaemonServer.cc
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h
src/pybind/mgr/balancer/module.py
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/hello/module.py
src/pybind/mgr/influx/module.py
src/pybind/mgr/iostat/module.py
src/pybind/mgr/mgr_module.py
src/pybind/mgr/prometheus/module.py
src/pybind/mgr/restful/module.py
src/pybind/mgr/selftest/module.py
src/pybind/mgr/smart/module.py
src/pybind/mgr/status/module.py
src/pybind/mgr/telegraf/module.py
src/pybind/mgr/telemetry/module.py
src/pybind/mgr/zabbix/module.py

index 2f52dd622620acaa90fcb56ceaa653fbe44455a8..42ad021d02d1b22ea3682ebd9419acbce9614109 100644 (file)
@@ -104,6 +104,7 @@ void ActivePyModule::notify_clog(const LogEntry &log_entry)
 
 int ActivePyModule::handle_command(
   const cmdmap_t &cmdmap,
+  const bufferlist &inbuf,
   std::stringstream *ds,
   std::stringstream *ss)
 {
@@ -122,9 +123,12 @@ int ActivePyModule::handle_command(
   PyFormatter f;
   cmdmap_dump(cmdmap, &f);
   PyObject *py_cmd = f.get();
+  string instr;
+  inbuf.copy(0, inbuf.length(), instr);
 
   auto pResult = PyObject_CallMethod(pClassInstance,
-      const_cast<char*>("handle_command"), const_cast<char*>("(O)"), py_cmd);
+      const_cast<char*>("handle_command"), const_cast<char*>("s#O"),
+      instr.c_str(), instr.length(), py_cmd);
 
   Py_DECREF(py_cmd);
 
index 85d50807a053d4fd22a85e7b76e1757ffde579d4..ebb1ba182be02d4dd72e437525bc1b7c51bc8187 100644 (file)
@@ -54,6 +54,7 @@ public:
 
   int handle_command(
     const cmdmap_t &cmdmap,
+    const bufferlist &inbuf,
     std::stringstream *ds,
     std::stringstream *ss);
 
index 707a6333c9288e03a5ea30e02660f8446ff16afc..fba63b62ab892cba8f5c86640fa8c44e7f788b4e 100644 (file)
@@ -774,6 +774,7 @@ void ActivePyModules::set_health_checks(const std::string& module_name,
 int ActivePyModules::handle_command(
   std::string const &module_name,
   const cmdmap_t &cmdmap,
+  const bufferlist &inbuf,
   std::stringstream *ds,
   std::stringstream *ss)
 {
@@ -785,7 +786,7 @@ int ActivePyModules::handle_command(
   }
 
   lock.Unlock();
-  return mod_iter->second->handle_command(cmdmap, ds, ss);
+  return mod_iter->second->handle_command(cmdmap, inbuf, ds, ss);
 }
 
 void ActivePyModules::get_health_checks(health_check_map_t *checks)
index c10a087c4e2cc2d2d236029f5ebcd6e79631ba8b..322f2bf10f0d7e3b22c234ea2f76f28e0e90428c 100644 (file)
@@ -96,6 +96,7 @@ public:
   int handle_command(
     const std::string &module_name,
     const cmdmap_t &cmdmap,
+    const bufferlist &inbuf,
     std::stringstream *ds,
     std::stringstream *ss);
 
index f8c7747984666ee4e6d1ab485237c2caccd42f22..388b6ca24845e722260c777aeee80d6bc3281605 100644 (file)
@@ -1979,7 +1979,8 @@ bool DaemonServer::handle_command(MCommand *m)
     }
 
     std::stringstream ds;
-    int r = py_modules.handle_command(handler_name, cmdctx->cmdmap, &ds, &ss);
+    bufferlist inbl = cmdctx->m->get_data();
+    int r = py_modules.handle_command(handler_name, cmdctx->cmdmap, inbl, &ds, &ss);
     cmdctx->odata.append(ds);
     cmdctx->reply(r, ss);
   }));
index af1fdebbb9034ff98495b1544c6aa226589a35cd..036d824717979256c9a8ee50a664875164cb180e 100644 (file)
@@ -287,11 +287,12 @@ std::set<std::string> PyModuleRegistry::probe_modules() const
 int PyModuleRegistry::handle_command(
   std::string const &module_name,
   const cmdmap_t &cmdmap,
+  const bufferlist &inbuf,
   std::stringstream *ds,
   std::stringstream *ss)
 {
   if (active_modules) {
-    return active_modules->handle_command(module_name, cmdmap, ds, ss);
+    return active_modules->handle_command(module_name, cmdmap, inbuf, ds, ss);
   } else {
     // We do not expect to be called before active modules is up, but
     // it's straightfoward to handle this case so let's do it.
index 97eff9d4c00caf45f4445ba179959627f0a0e161..241ba55ad11c3dde7df1c0fbc4f2746bbe2e50e2 100644 (file)
@@ -140,6 +140,7 @@ public:
   int handle_command(
     std::string const &module_name,
     const cmdmap_t &cmdmap,
+    const bufferlist &inbuf,
     std::stringstream *ds,
     std::stringstream *ss);
 
index b6466ef53d94b452b899916993edb4e725b72861..d939a549554e52d57230b20c111a2f26c5e7a862 100644 (file)
@@ -291,7 +291,7 @@ class Module(MgrModule):
         super(Module, self).__init__(*args, **kwargs)
         self.event = Event()
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         self.log.warn("Handling command: '%s'" % str(command))
         if command['prefix'] == 'balancer status':
             s = {
index 17b4cd67cf74ddc7f0c729b85b0a80782162a77c..cd91d2a1a2ef3e9eff3dbb6b895b1e8592cd9980 100644 (file)
@@ -312,7 +312,7 @@ class Module(MgrModule, SSLCherryPyConfig):
         logger.info('Stopping engine...')
         self.shutdown_event.set()
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         res = handle_option_command(cmd)
         if res[0] != -errno.ENOSYS:
             return res
index ce8590d9faf8d93605c61329119c2b63374d3d90..37f9e2df2f039a40b10b33e88190c774d782ed55 100644 (file)
@@ -18,7 +18,7 @@ class Hello(MgrModule):
         },
     ]
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         self.log.info("hello_world_info")
         self.log.debug("hello_world_debug")
         self.log.error("hello_world_error")
index 999902620ad06cf36fdb0e70f9e266c7fdcb2786..4d111e57af186eda10071df0c9c90ecdf53eaa3e 100644 (file)
@@ -326,7 +326,7 @@ class Module(MgrModule):
         self.run = False
         self.event.set()
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         if cmd['prefix'] == 'influx config-show':
             return 0, json.dumps(self.config), ''
         elif cmd['prefix'] == 'influx config-set':
index e9f7c3eb92b95ee4692e034c7b4f8d07129918a3..9133fafae2e706f2facab148ef2a77fe7e54068a 100644 (file)
@@ -22,7 +22,7 @@ class Module(MgrModule):
         super(Module, self).__init__(*args, **kwargs)
 
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         rd = 0
         wr = 0
         total = 0
index 1db2e71a425e39db33fc903fd8c6bfbf6f4f0ff1..35b2f92699eeb27828205c61579668812b8393c9 100644 (file)
@@ -516,7 +516,7 @@ class MgrModule(ceph_module.BaseMgrModule):
         """
         self._ceph_set_health_checks(checks)
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         """
         Called by ceph-mgr to request the plugin to handle one
         of the commands that it declared in self.COMMANDS
@@ -525,6 +525,7 @@ class MgrModule(ceph_module.BaseMgrModule):
         output string.  The output buffer is for data results,
         the output string is for informative text.
 
+        :param string inbuf: content of any "-i <file>" supplied to ceph cli
         :param dict cmd: from Ceph's cmdmap_t
 
         :return: 3-tuple of (int, str, str)
index 88a8e3dad52bcd9242ac1d926342a1ee20555989..85724a9dc361ada97dbcaac51334d27990e51e64 100644 (file)
@@ -649,7 +649,7 @@ class Module(MgrModule):
         ]
         return 0, json.dumps(ret), ""
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         if cmd['prefix'] == 'prometheus self-test':
             self.collect()
             self.get_file_sd_config()
index 8856987cd37a6585dec008aaac25a9541b4df2e4..c4683219b3bb5033367d4598801a4c241129dd25 100644 (file)
@@ -405,7 +405,7 @@ class Module(MgrModule):
         )
 
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         self.log.warn("Handling command: '%s'" % str(command))
         if command['prefix'] == "restful create-key":
             if command['key_name'] in self.keys:
index dfc57ae5c2bfdbf57e46125a33775651270b70c4..8ba36f622f65d7316c1c5989512aa5ca3f061646 100644 (file)
@@ -67,7 +67,7 @@ class Module(MgrModule):
         self._event = threading.Event()
         self._workload = None
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         if command['prefix'] == 'mgr self-test run':
             self._self_test()
             return 0, '', 'Self-test succeeded'
index 8b2d54c176776598a64d1ac3badba4e4933bd7a8..3df9356ea1b4abbe763dad076680ed1d3d71c485 100644 (file)
@@ -17,7 +17,7 @@ class Module(MgrModule):
         },
     ]
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         self.log.error("handle_command")
 
         if cmd['prefix'] == 'osd smart get':
index b4a0f25e0af70db7447cbee7b9d113573f323ba6..cd02925de3aee094eea6416390bb3469755a9e01 100644 (file)
@@ -303,7 +303,7 @@ class Module(MgrModule):
 
         return 0, osd_table.get_string(), ""
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         self.log.error("handle_command")
 
         if cmd['prefix'] == "fs status":
index 32d5a9f39cd63bbf349a23623c8c81309de04733..aad35b47224e12e8285b486f60b93ffce5be7b9a 100644 (file)
@@ -268,7 +268,7 @@ class Module(MgrModule):
         self.run = False
         self.event.set()
 
-    def handle_command(self, cmd):
+    def handle_command(self, inbuf, cmd):
         if cmd['prefix'] == 'telegraf config-show':
             return 0, json.dumps(self.config), ''
         elif cmd['prefix'] == 'telegraf config-set':
index f83ddfe26c2134ba9761c711a8e5c627bdd18945..c3e24f150e04754ad9d3038cb7b6f2c384116659 100644 (file)
@@ -287,7 +287,7 @@ class Module(MgrModule):
 
         requests.put(url=self.config['url'], json=report, proxies=proxies)
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         if command['prefix'] == 'telemetry config-show':
             return 0, json.dumps(self.config), ''
         elif command['prefix'] == 'telemetry config-set':
index df319f7b05ca0e551d2bf5ce6d058529179f1e43..43199fe3ddf77a483dcc373f398524413996e11c 100644 (file)
@@ -279,7 +279,7 @@ class Module(MgrModule):
 
         return False
 
-    def handle_command(self, command):
+    def handle_command(self, inbuf, command):
         if command['prefix'] == 'zabbix config-show':
             return 0, json.dumps(self.config), ''
         elif command['prefix'] == 'zabbix config-set':