summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs/openshiftstoragelibs/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'openshift-storage-libs/openshiftstoragelibs/command.py')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/command.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/command.py b/openshift-storage-libs/openshiftstoragelibs/command.py
new file mode 100644
index 00000000..06912915
--- /dev/null
+++ b/openshift-storage-libs/openshiftstoragelibs/command.py
@@ -0,0 +1,23 @@
+from glusto.core import Glusto as g
+
+
+def cmd_run(cmd, hostname, raise_on_error=True):
+ """Glusto's command runner wrapper.
+
+ Args:
+ cmd (str): Shell command to run on the specified hostname.
+ hostname (str): hostname where Glusto should run specified command.
+ raise_on_error (bool): defines whether we should raise exception
+ in case command execution failed.
+ Returns:
+ str: Stripped shell command's stdout value if not None.
+ """
+ ret, out, err = g.run(hostname, cmd, "root")
+ if raise_on_error:
+ msg = ("Failed to execute command '%s' on '%s' node. Got non-zero "
+ "return code '%s'. Err: %s" % (cmd, hostname, ret, err))
+ assert int(ret) == 0, msg
+
+ out = out.strip() if out else out
+
+ return out