From: Yaarit Hatuka Date: Wed, 13 Dec 2017 15:17:57 +0000 (-0500) Subject: pybind/mgr: add 'hello world' mgr module skeleton X-Git-Tag: v13.1.0~89^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F19491%2Fhead;p=ceph.git 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 --- diff --git a/doc/mgr/hello.rst b/doc/mgr/hello.rst new file mode 100644 index 00000000000..2c55b66cf29 --- /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 30f9516060b..21fe2bed992 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 00000000000..129920c0913 --- /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 00000000000..ce8590d9faf --- /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