summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-02-15 15:01:41 -0500
committerBrian Waldon <brian.waldon@rackspace.com>2011-02-15 15:01:41 -0500
commit8074ecf9f8e8d4e24909e2255e40da4c5fa9ce9e (patch)
treea7f13616e6d7cd393b717e7c59766d43b9a07c8c /nova/utils.py
parent4a4a3f04b78ba2cbaa0d02ecf0f7cd3cf580901b (diff)
parent273e6703a9e4f7e3b7810f204ffb6bb0f86602bd (diff)
downloadnova-8074ecf9f8e8d4e24909e2255e40da4c5fa9ce9e.tar.gz
nova-8074ecf9f8e8d4e24909e2255e40da4c5fa9ce9e.tar.xz
nova-8074ecf9f8e8d4e24909e2255e40da4c5fa9ce9e.zip
merging trunk back in; updating Authors conflict
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 5f5225289..ba71ebf39 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -25,7 +25,6 @@ import inspect
import json
import os
import random
-import subprocess
import socket
import struct
import sys
@@ -36,6 +35,7 @@ import netaddr
from eventlet import event
from eventlet import greenthread
+from eventlet.green import subprocess
from nova import exception
from nova.exception import ProcessExecutionError
@@ -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)