@@ -205,7 +205,7 @@ def _connect(self, client, host, port, sock=None, retries=1):
205205 # of SSH failure
206206 except paramiko .SSHException , ex :
207207 logger .error ("General SSH error - %s" , ex )
208- raise SSHException (ex .message )
208+ raise SSHException (ex .message , host )
209209
210210 def exec_command (self , command , sudo = False , user = None , ** kwargs ):
211211 """Wrapper to :mod:`paramiko.SSHClient.exec_command`
@@ -493,15 +493,13 @@ def run_command(self, *args, **kwargs):
493493 'cmd' : <greenlet>}}
494494
495495 """
496- stop_on_errors = kwargs ['stop_on_errors' ] \
497- if 'stop_on_errors' in kwargs else True
498- del kwargs ['stop_on_errors' ]
496+ stop_on_errors = kwargs .pop ('stop_on_errors' , True )
499497 cmds = [self .pool .spawn (self ._exec_command , host , * args , ** kwargs )
500498 for host in self .hosts ]
501499 output = {}
502500 for cmd in cmds :
503501 try :
504- output = self .get_output (cmd )
502+ self .get_output (cmd , output )
505503 except Exception , ex :
506504 if stop_on_errors :
507505 raise ex
@@ -536,12 +534,11 @@ def _exec_command(self, host, *args, **kwargs):
536534 proxy_port = self .proxy_port )
537535 return self .host_clients [host ].exec_command (* args , ** kwargs )
538536
539- def get_output (self , cmd ):
537+ def get_output (self , cmd , output ):
540538 """Get output from command.
541539
542- :param commands: (Optional) Override commands to get output from.\
543- Uses running commands in pool if not given.
544- :type commands: :mod:`gevent.Greenlet`
540+ :param cmd: Command to get output from
541+ :type cmd: :mod:`gevent.Greenlet`
545542 :rtype: Dictionary with host as key as in:
546543
547544 ::
@@ -568,10 +565,15 @@ def get_output(self, cmd):
568565 >>> self.get_exit_code(output[host])
569566 0
570567 """
571- output = {}
572568 try :
573569 (channel , host , stdout , stderr ) = cmd .get ()
574570 except Exception , ex :
571+ try :
572+ host = ex .args [1 ]
573+ except IndexError :
574+ logger .error ("Got exception with no host argument - cannot update output data with %s" , ex )
575+ raise ex
576+ output .setdefault (host , {})
575577 output [host ].update ({'exit_code' : None ,
576578 'channel' : None ,
577579 'stdout' : None ,
@@ -585,7 +587,6 @@ def get_output(self, cmd):
585587 'stdout' : stdout ,
586588 'stderr' : stderr ,
587589 'cmd' : cmd , })
588- return output
589590
590591 def get_exit_code (self , host_output ):
591592 """Get exit code from host output if available
0 commit comments