You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pq...@apache.org on 2010/05/20 02:38:59 UTC

svn commit: r946494 - in /incubator/libcloud/trunk/libcloud: deployment.py ssh.py

Author: pquerna
Date: Thu May 20 00:38:59 2010
New Revision: 946494

URL: http://svn.apache.org/viewvc?rev=946494&view=rev
Log:
LIBCLOUD-37: Add the exit_status of a script to the ScriptDeployment class.

Suggested by: Jay Doane

Modified:
    incubator/libcloud/trunk/libcloud/deployment.py
    incubator/libcloud/trunk/libcloud/ssh.py

Modified: incubator/libcloud/trunk/libcloud/deployment.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/deployment.py?rev=946494&r1=946493&r2=946494&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/deployment.py (original)
+++ incubator/libcloud/trunk/libcloud/deployment.py Thu May 20 00:38:59 2010
@@ -79,6 +79,7 @@ class ScriptDeployment(Deployment):
         self.script = script
         self.stdout = None
         self.stderr = None
+        self.exit_status = None
         self.delete = delete
         self.name = name
         if self.name is None:
@@ -91,7 +92,7 @@ class ScriptDeployment(Deployment):
         See also L{Deployment.run}
         """
         client.put(path=self.name, chmod=755, contents=self.script)
-        self.stdout, self.stderr = client.run(self.name)
+        self.stdout, self.stderr, self.exit_status = client.run(self.name)
         if self.delete:
             client.delete(self.name)
         return node

Modified: incubator/libcloud/trunk/libcloud/ssh.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/ssh.py?rev=946494&r1=946493&r2=946494&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/ssh.py (original)
+++ incubator/libcloud/trunk/libcloud/ssh.py Thu May 20 00:38:59 2010
@@ -95,6 +95,8 @@ class BaseSSHClient(object):
 
         @type cmd: C{str}
         @keyword cmd: Command to run.
+        
+        @return C{list} of [stdout, stderr, exit_status]
         """
         raise NotImplementedError, \
             'run not implemented for this ssh client'
@@ -153,11 +155,20 @@ class ParamikoSSHClient(BaseSSHClient):
         sftp.close()
 
     def run(self, cmd):
-        stdin, stdout, stderr = self.client.exec_command(cmd)
+        # based on exec_command()
+        bufsize = -1
+        t =  self.client.get_transport()
+        chan = t.open_session()
+        chan.exec_command(cmd)
+        stdin = chan.makefile('wb', bufsize)
+        stdout = chan.makefile('rb', bufsize)
+        stderr = chan.makefile_stderr('rb', bufsize)
+        #stdin, stdout, stderr = self.client.exec_command(cmd)
         stdin.close()
+        status = chan.recv_exit_status()
         so = stdout.read()
         se = stderr.read()
-        return [so, se]
+        return [so, se, status]
 
     def close(self):
         self.client.close()