From 140761f8a2df10c45eb02041fad5e8237bf57c20 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 19 Jun 2018 20:36:08 -0700 Subject: [PATCH] mgr, pybind/mgr: pass inbuf (ceph -i ) to modules Modules may wish to receive bulk data; allow it Signed-off-by: Dan Mick --- src/mgr/ActivePyModule.cc | 6 +++++- src/mgr/ActivePyModule.h | 1 + src/mgr/ActivePyModules.cc | 3 ++- src/mgr/ActivePyModules.h | 1 + src/mgr/DaemonServer.cc | 3 ++- src/mgr/PyModuleRegistry.cc | 3 ++- src/mgr/PyModuleRegistry.h | 1 + src/pybind/mgr/balancer/module.py | 2 +- src/pybind/mgr/dashboard/module.py | 2 +- src/pybind/mgr/hello/module.py | 2 +- src/pybind/mgr/influx/module.py | 2 +- src/pybind/mgr/iostat/module.py | 2 +- src/pybind/mgr/mgr_module.py | 3 ++- src/pybind/mgr/prometheus/module.py | 2 +- src/pybind/mgr/restful/module.py | 2 +- src/pybind/mgr/selftest/module.py | 2 +- src/pybind/mgr/smart/module.py | 2 +- src/pybind/mgr/status/module.py | 2 +- src/pybind/mgr/telegraf/module.py | 2 +- src/pybind/mgr/telemetry/module.py | 2 +- src/pybind/mgr/zabbix/module.py | 2 +- 21 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/mgr/ActivePyModule.cc b/src/mgr/ActivePyModule.cc index 2f52dd622620a..42ad021d02d1b 100644 --- a/src/mgr/ActivePyModule.cc +++ b/src/mgr/ActivePyModule.cc @@ -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("handle_command"), const_cast("(O)"), py_cmd); + const_cast("handle_command"), const_cast("s#O"), + instr.c_str(), instr.length(), py_cmd); Py_DECREF(py_cmd); diff --git a/src/mgr/ActivePyModule.h b/src/mgr/ActivePyModule.h index 85d50807a053d..ebb1ba182be02 100644 --- a/src/mgr/ActivePyModule.h +++ b/src/mgr/ActivePyModule.h @@ -54,6 +54,7 @@ public: int handle_command( const cmdmap_t &cmdmap, + const bufferlist &inbuf, std::stringstream *ds, std::stringstream *ss); diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 707a6333c9288..fba63b62ab892 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -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) diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index c10a087c4e2cc..322f2bf10f0d7 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -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); diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index f8c7747984666..388b6ca24845e 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -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); })); diff --git a/src/mgr/PyModuleRegistry.cc b/src/mgr/PyModuleRegistry.cc index af1fdebbb9034..036d824717979 100644 --- a/src/mgr/PyModuleRegistry.cc +++ b/src/mgr/PyModuleRegistry.cc @@ -287,11 +287,12 @@ std::set 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. diff --git a/src/mgr/PyModuleRegistry.h b/src/mgr/PyModuleRegistry.h index 97eff9d4c00ca..241ba55ad11c3 100644 --- a/src/mgr/PyModuleRegistry.h +++ b/src/mgr/PyModuleRegistry.h @@ -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); diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index b6466ef53d94b..d939a549554e5 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -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 = { diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 17b4cd67cf74d..cd91d2a1a2ef3 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -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 diff --git a/src/pybind/mgr/hello/module.py b/src/pybind/mgr/hello/module.py index ce8590d9faf8d..37f9e2df2f039 100644 --- a/src/pybind/mgr/hello/module.py +++ b/src/pybind/mgr/hello/module.py @@ -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") diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index 999902620ad06..4d111e57af186 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -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': diff --git a/src/pybind/mgr/iostat/module.py b/src/pybind/mgr/iostat/module.py index e9f7c3eb92b95..9133fafae2e70 100644 --- a/src/pybind/mgr/iostat/module.py +++ b/src/pybind/mgr/iostat/module.py @@ -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 diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 1db2e71a425e3..35b2f92699eeb 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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 " supplied to ceph cli :param dict cmd: from Ceph's cmdmap_t :return: 3-tuple of (int, str, str) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 88a8e3dad52bc..85724a9dc361a 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -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() diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index 8856987cd37a6..c4683219b3bb5 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -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: diff --git a/src/pybind/mgr/selftest/module.py b/src/pybind/mgr/selftest/module.py index dfc57ae5c2bfd..8ba36f622f65d 100644 --- a/src/pybind/mgr/selftest/module.py +++ b/src/pybind/mgr/selftest/module.py @@ -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' diff --git a/src/pybind/mgr/smart/module.py b/src/pybind/mgr/smart/module.py index 8b2d54c176776..3df9356ea1b4a 100644 --- a/src/pybind/mgr/smart/module.py +++ b/src/pybind/mgr/smart/module.py @@ -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': diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index b4a0f25e0af70..cd02925de3aee 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -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": diff --git a/src/pybind/mgr/telegraf/module.py b/src/pybind/mgr/telegraf/module.py index 32d5a9f39cd63..aad35b47224e1 100644 --- a/src/pybind/mgr/telegraf/module.py +++ b/src/pybind/mgr/telegraf/module.py @@ -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': diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index f83ddfe26c213..c3e24f150e047 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -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': diff --git a/src/pybind/mgr/zabbix/module.py b/src/pybind/mgr/zabbix/module.py index df319f7b05ca0..43199fe3ddf77 100644 --- a/src/pybind/mgr/zabbix/module.py +++ b/src/pybind/mgr/zabbix/module.py @@ -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': -- 2.39.5