Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import the "call" function from ffs into xapi.storage.common
This is useful for very simple storage backends. Signed-off-by: David Scott <dave.scott@eu.citrix.com>
- Loading branch information
David Scott
committed
Sep 10, 2015
1 parent
ed82b3f
commit a9536b8
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#!/usr/bin/env python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
|
||
from xapi.storage import log | ||
import xapi | ||
import subprocess | ||
|
||
|
||
# [call dbg cmd_args] executes [cmd_args] | ||
# if [error] and exit code != expRc, log and throws a BackendError | ||
# if [simple], returns only stdout | ||
|
||
|
||
def call(dbg, cmd_args, error=True, simple=True, expRc=0): | ||
log.debug("%s: Running cmd %s" % (dbg, cmd_args)) | ||
p = subprocess.Popen( | ||
cmd_args, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
close_fds=True) | ||
stdout, stderr = p.communicate() | ||
if error and p.returncode != expRc: | ||
log.error("%s: %s exitted with code %d: %s" % | ||
(dbg, " ".join(cmd_args), p.returncode, stderr)) | ||
raise xapi.InternalError("%s exitted with non-zero code %d: %s" | ||
% (" ".join(cmd_args), p.returncode, stderr)) | ||
if simple: | ||
return stdout | ||
return stdout, stderr, p.returncode |