Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / ext / action_helpers / python / kwilczynski / README.markdown
diff --git a/ext/action_helpers/python/kwilczynski/README.markdown b/ext/action_helpers/python/kwilczynski/README.markdown
new file mode 100644 (file)
index 0000000..d73f3fb
--- /dev/null
@@ -0,0 +1,46 @@
+A simple helper to assist with writing MCollective actions in Python.
+
+Given an action as below:
+
+<pre>
+action "echo" do
+   validate :message, String
+
+   implemented_by "/tmp/echo.py"
+end
+</pre>
+
+The following Python script will implement the echo action externally
+replying with _message_ and current _time_.
+
+<pre>
+#!/usr/bin/env python
+
+import sys
+import time
+import mcollective_action as mc
+
+if __name__ == '__main__':
+    mc = mc.MCollectiveAction()
+    request = mc.request()
+    mc.message = request['data']['message']
+    mc.time = time.strftime('%c')
+    mc.info("Some text to info log in the server")
+
+    sys.exit(0)
+</pre>
+
+Calling it with _mco rpc_ results in:
+
+<pre>
+$ mco rpc test echo message="Hello World"
+Determining the amount of hosts matching filter for 2 seconds .... 1
+
+ * [ ============================================================> ] 1 / 1
+
+
+host.example.com              : OK
+    {:message=>"Hello World", :time=>"Tue Mar 15 19:20:53 +0000 2011"}
+</pre>
+
+This implementation was successfully tested with Python 2.4 and 2.6.