From b19e11a6c8b21588f6b3e029a408ea334f7ecbe6 Mon Sep 17 00:00:00 2001 From: Yaarit Hatuka Date: Wed, 13 Dec 2017 10:17:57 -0500 Subject: [PATCH] pybind/mgr: add 'hello world' mgr module skeleton This simple 'hello' mgr module prints 'hello world' to stdout and to out/mgr.x.log; for documentation purposes. Also added /doc/mgr/hello.rst. Signed-off-by: Yaarit Hatuka --- doc/mgr/hello.rst | 39 ++++++++++++++++++++++++++++++++ doc/mgr/index.rst | 1 + src/pybind/mgr/hello/__init__.py | 1 + src/pybind/mgr/hello/module.py | 34 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 doc/mgr/hello.rst create mode 100644 src/pybind/mgr/hello/__init__.py create mode 100644 src/pybind/mgr/hello/module.py diff --git a/doc/mgr/hello.rst b/doc/mgr/hello.rst new file mode 100644 index 0000000000000..2c55b66cf29a0 --- /dev/null +++ b/doc/mgr/hello.rst @@ -0,0 +1,39 @@ +hello world +=========== + +This is a simple module skeleton for documentation purposes. + +Enabling +-------- + +The *hello* module is enabled with:: + + ceph mgr module enable hello + +To check that it is enabled, run:: + + ceph mgr module ls + +After editing the module file (found in ``src/pybind/mgr/hello/module.py``), you can see changes by running:: + + ceph mgr module disable hello + ceph mgr module enable hello + +or:: + + init-ceph restart mgr + +To execute the module, run:: + + ceph hello + +The log is found at:: + + build/out/mgr.x.log + + +Documenting +----------- + +After adding a new mgr module/plugin, be sure to add its documentation to ``doc/mgr/plugin_name.rst``. +Also, add a link to your new plugin into ``doc/mgr/index.rst``. diff --git a/doc/mgr/index.rst b/doc/mgr/index.rst index 30f9516060b23..21fe2bed99276 100644 --- a/doc/mgr/index.rst +++ b/doc/mgr/index.rst @@ -34,4 +34,5 @@ sensible. Zabbix plugin Prometheus plugin Influx plugin + Hello plugin diff --git a/src/pybind/mgr/hello/__init__.py b/src/pybind/mgr/hello/__init__.py new file mode 100644 index 0000000000000..129920c09133e --- /dev/null +++ b/src/pybind/mgr/hello/__init__.py @@ -0,0 +1 @@ +from .module import Hello diff --git a/src/pybind/mgr/hello/module.py b/src/pybind/mgr/hello/module.py new file mode 100644 index 0000000000000..ce8590d9faf8d --- /dev/null +++ b/src/pybind/mgr/hello/module.py @@ -0,0 +1,34 @@ + +""" +A hello world module + +See doc/mgr/hello.rst for more info. +""" + +from mgr_module import MgrModule + + +class Hello(MgrModule): + COMMANDS = [ + { + "cmd": "hello " + "name=person_name,type=CephString,req=false", + "desc": "Prints hello world to mgr.x.log", + "perm": "r" + }, + ] + + def handle_command(self, cmd): + self.log.info("hello_world_info") + self.log.debug("hello_world_debug") + self.log.error("hello_world_error") + + status_code = 0 + output_buffer = "Output buffer is for data results" + output_string = "Output string is for informative text" + message = "hello world!" + + if 'person_name' in cmd: + message = "hello, " + cmd['person_name'] + "!" + + return status_code, output_buffer, message + "\n" + output_string -- 2.39.5