Skip to content

Commit

Permalink
Import the "call" function from ffs into xapi.storage.common
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/xapi/storage/__init__.py
@@ -0,0 +1 @@
#!/usr/bin/env python
28 changes: 28 additions & 0 deletions python/xapi/storage/common.py
@@ -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

0 comments on commit a9536b8

Please sign in to comment.