]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: implement command_with_stdin
authorLoic Dachary <ldachary@redhat.com>
Thu, 8 Jun 2017 17:00:05 +0000 (19:00 +0200)
committerLoic Dachary <ldachary@redhat.com>
Fri, 14 Jul 2017 17:47:00 +0000 (19:47 +0200)
Signed-off-by: Loic Dachary <loic@dachary.org>
src/ceph-disk/ceph_disk/main.py

index c5d06e079fdd1d1c26d5cbb5081bceaa41d3bc2c..e7d1799486181b29dfa71816fdf2f2e6de001b49 100755 (executable)
@@ -478,6 +478,26 @@ def command(arguments, **kwargs):
     return _bytes2str(out), _bytes2str(err), process.returncode
 
 
+def command_with_stdin(arguments, stdin):
+    LOG.info("Running command with stdin: " + " ".join(arguments))
+    process = subprocess.Popen(
+        arguments,
+        stdin=subprocess.PIPE,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE)
+    out, err = process.communicate(stdin)
+    LOG.debug(out)
+    if process.returncode != 0:
+        LOG.error(err)
+        raise SystemExit(
+            "'{cmd}' failed with status code {returncode}".format(
+                cmd=arguments,
+                returncode=process.returncode,
+            )
+        )
+    return out
+
+
 def _bytes2str(string):
     return string.decode('utf-8') if isinstance(string, bytes) else string