@@ -210,7 +210,7 @@ def _connect(self, client, host, port, sock=None, retries=1):
210210 # of SSH failure
211211 except paramiko .SSHException , ex :
212212 logger .error ("General SSH error - %s" , ex )
213- raise SSHException (ex .message )
213+ raise SSHException (ex .message , host )
214214
215215 def exec_command (self , command , sudo = False , user = None , ** kwargs ):
216216 """Wrapper to :mod:`paramiko.SSHClient.exec_command`
@@ -498,15 +498,13 @@ def run_command(self, *args, **kwargs):
498498 'cmd' : <greenlet>}}
499499
500500 """
501- stop_on_errors = kwargs ['stop_on_errors' ] \
502- if 'stop_on_errors' in kwargs else True
503- del kwargs ['stop_on_errors' ]
501+ stop_on_errors = kwargs .pop ('stop_on_errors' , True )
504502 cmds = [self .pool .spawn (self ._exec_command , host , * args , ** kwargs )
505503 for host in self .hosts ]
506504 output = {}
507505 for cmd in cmds :
508506 try :
509- output = self .get_output (cmd )
507+ self .get_output (cmd , output )
510508 except Exception , ex :
511509 if stop_on_errors :
512510 raise ex
@@ -541,12 +539,11 @@ def _exec_command(self, host, *args, **kwargs):
541539 proxy_port = self .proxy_port )
542540 return self .host_clients [host ].exec_command (* args , ** kwargs )
543541
544- def get_output (self , cmd ):
542+ def get_output (self , cmd , output ):
545543 """Get output from command.
546544
547- :param commands: (Optional) Override commands to get output from.\
548- Uses running commands in pool if not given.
549- :type commands: :mod:`gevent.Greenlet`
545+ :param cmd: Command to get output from
546+ :type cmd: :mod:`gevent.Greenlet`
550547 :rtype: Dictionary with host as key as in:
551548
552549 ::
@@ -573,10 +570,15 @@ def get_output(self, cmd):
573570 >>> self.get_exit_code(output[host])
574571 0
575572 """
576- output = {}
577573 try :
578574 (channel , host , stdout , stderr ) = cmd .get ()
579575 except Exception , ex :
576+ try :
577+ host = ex .args [1 ]
578+ except IndexError :
579+ logger .error ("Got exception with no host argument - cannot update output data with %s" , ex )
580+ raise ex
581+ output .setdefault (host , {})
580582 output [host ].update ({'exit_code' : None ,
581583 'channel' : None ,
582584 'stdout' : None ,
@@ -590,7 +592,6 @@ def get_output(self, cmd):
590592 'stdout' : stdout ,
591593 'stderr' : stderr ,
592594 'cmd' : cmd , })
593- return output
594595
595596 def get_exit_code (self , host_output ):
596597 """Get exit code from host output if available
0 commit comments