summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorbrian-lamar <brian.lamar@gmail.com>2011-02-11 11:05:49 -0500
committerbrian-lamar <brian.lamar@gmail.com>2011-02-11 11:05:49 -0500
commit24ad2cc21abbab494a3be18a7f09a6c1d9210804 (patch)
treee083ba00f9a48622c8a8a99d6ef79d79c717df98 /nova/utils.py
parent590f5f1793c1f829101b4edbacbc79eac7acd2ef (diff)
parentd6736026aa11a536d1c0f342d89bca063b43b3ff (diff)
downloadnova-24ad2cc21abbab494a3be18a7f09a6c1d9210804.tar.gz
nova-24ad2cc21abbab494a3be18a7f09a6c1d9210804.tar.xz
nova-24ad2cc21abbab494a3be18a7f09a6c1d9210804.zip
Merged to trunk and fixed merge conflict in Authors.
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 5f5225289..8d7ff1f64 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -152,6 +152,42 @@ def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
return result
+def ssh_execute(ssh, cmd, process_input=None,
+ addl_env=None, check_exit_code=True):
+ LOG.debug(_("Running cmd (SSH): %s"), cmd)
+ if addl_env:
+ raise exception.Error("Environment not supported over SSH")
+
+ if process_input:
+ # This is (probably) fixable if we need it...
+ raise exception.Error("process_input not supported over SSH")
+
+ stdin_stream, stdout_stream, stderr_stream = ssh.exec_command(cmd)
+ channel = stdout_stream.channel
+
+ #stdin.write('process_input would go here')
+ #stdin.flush()
+
+ # NOTE(justinsb): This seems suspicious...
+ # ...other SSH clients have buffering issues with this approach
+ stdout = stdout_stream.read()
+ stderr = stderr_stream.read()
+ stdin_stream.close()
+
+ exit_status = channel.recv_exit_status()
+
+ # exit_status == -1 if no exit code was returned
+ if exit_status != -1:
+ LOG.debug(_("Result was %s") % exit_status)
+ if check_exit_code and exit_status != 0:
+ raise exception.ProcessExecutionError(exit_code=exit_status,
+ stdout=stdout,
+ stderr=stderr,
+ cmd=cmd)
+
+ return (stdout, stderr)
+
+
def abspath(s):
return os.path.join(os.path.dirname(__file__), s)