]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: add 'hello world' mgr module skeleton 19491/head
authorYaarit Hatuka <yaarithatuka@gmail.com>
Wed, 13 Dec 2017 15:17:57 +0000 (10:17 -0500)
committerYaarit Hatuka <yaarithatuka@gmail.com>
Wed, 25 Apr 2018 14:37:09 +0000 (10:37 -0400)
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 <yaarithatuka@gmail.com>
doc/mgr/hello.rst [new file with mode: 0644]
doc/mgr/index.rst
src/pybind/mgr/hello/__init__.py [new file with mode: 0644]
src/pybind/mgr/hello/module.py [new file with mode: 0644]

diff --git a/doc/mgr/hello.rst b/doc/mgr/hello.rst
new file mode 100644 (file)
index 0000000..2c55b66
--- /dev/null
@@ -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``.
index 30f9516060b23cb5c093c42e8e9df7fdfe3e4aea..21fe2bed9927600d8732cde12118210b8e47887a 100644 (file)
@@ -34,4 +34,5 @@ sensible.
     Zabbix plugin <zabbix>
     Prometheus plugin <prometheus>
     Influx plugin <influx>
+    Hello plugin <hello>
 
diff --git a/src/pybind/mgr/hello/__init__.py b/src/pybind/mgr/hello/__init__.py
new file mode 100644 (file)
index 0000000..129920c
--- /dev/null
@@ -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 (file)
index 0000000..ce8590d
--- /dev/null
@@ -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