@@ -199,7 +199,8 @@ def _connect(self, client, host, port, sock=None, retries=1):
199199 str (error_type ), self .host , self .port ,
200200 retries , self .num_retries ,)
201201 except paramiko .AuthenticationException , ex :
202- raise AuthenticationException (ex .message )
202+ msg = ex .message + "Host is '%s:%s'"
203+ raise AuthenticationException (msg , host , port )
203204 # SSHException is more general so should be below other types
204205 # of SSH failure
205206 except paramiko .SSHException , ex :
@@ -492,9 +493,19 @@ def run_command(self, *args, **kwargs):
492493 'cmd' : <greenlet>}}
493494
494495 """
496+ stop_on_errors = kwargs ['stop_on_errors' ] \
497+ if 'stop_on_errors' in kwargs else True
498+ del kwargs ['stop_on_errors' ]
495499 cmds = [self .pool .spawn (self ._exec_command , host , * args , ** kwargs )
496500 for host in self .hosts ]
497- return self .get_output (commands = cmds )
501+ output = {}
502+ for cmd in cmds :
503+ try :
504+ output = self .get_output (cmd )
505+ except Exception , ex :
506+ if stop_on_errors :
507+ raise ex
508+ return output
498509
499510 def exec_command (self , * args , ** kwargs ):
500511 """Run command on all hosts in parallel, honoring `self.pool_size`
@@ -525,8 +536,8 @@ def _exec_command(self, host, *args, **kwargs):
525536 proxy_port = self .proxy_port )
526537 return self .host_clients [host ].exec_command (* args , ** kwargs )
527538
528- def get_output (self , commands = None ):
529- """Get output from running commands .
539+ def get_output (self , cmd ):
540+ """Get output from command .
530541
531542 :param commands: (Optional) Override commands to get output from.\
532543 Uses running commands in pool if not given.
@@ -557,17 +568,23 @@ def get_output(self, commands=None):
557568 >>> self.get_exit_code(output[host])
558569 0
559570 """
560- if not commands :
561- commands = list (self .pool .greenlets )
562571 output = {}
563- for cmd in commands :
572+ try :
564573 (channel , host , stdout , stderr ) = cmd .get ()
565- output .setdefault (host , {})
566- output [host ].update ({'exit_code' : self ._get_exit_code (channel ),
567- 'channel' : channel ,
568- 'stdout' : stdout ,
569- 'stderr' : stderr ,
570- 'cmd' : cmd , })
574+ except Exception , ex :
575+ output [host ].update ({'exit_code' : None ,
576+ 'channel' : None ,
577+ 'stdout' : None ,
578+ 'stderr' : None ,
579+ 'cmd' : cmd ,
580+ 'exception' : ex ,})
581+ raise ex
582+ output .setdefault (host , {})
583+ output [host ].update ({'exit_code' : self ._get_exit_code (channel ),
584+ 'channel' : channel ,
585+ 'stdout' : stdout ,
586+ 'stderr' : stderr ,
587+ 'cmd' : cmd , })
571588 return output
572589
573590 def get_exit_code (self , host_output ):
0 commit comments