@@ -204,7 +204,8 @@ def _connect(self, client, host, port, sock=None, retries=1):
204204 str (error_type ), self .host , self .port ,
205205 retries , self .num_retries ,)
206206 except paramiko .AuthenticationException , ex :
207- raise AuthenticationException (ex .message )
207+ msg = ex .message + "Host is '%s:%s'"
208+ raise AuthenticationException (msg , host , port )
208209 # SSHException is more general so should be below other types
209210 # of SSH failure
210211 except paramiko .SSHException , ex :
@@ -497,9 +498,19 @@ def run_command(self, *args, **kwargs):
497498 'cmd' : <greenlet>}}
498499
499500 """
501+ stop_on_errors = kwargs ['stop_on_errors' ] \
502+ if 'stop_on_errors' in kwargs else True
503+ del kwargs ['stop_on_errors' ]
500504 cmds = [self .pool .spawn (self ._exec_command , host , * args , ** kwargs )
501505 for host in self .hosts ]
502- return self .get_output (commands = cmds )
506+ output = {}
507+ for cmd in cmds :
508+ try :
509+ output = self .get_output (cmd )
510+ except Exception , ex :
511+ if stop_on_errors :
512+ raise ex
513+ return output
503514
504515 def exec_command (self , * args , ** kwargs ):
505516 """Run command on all hosts in parallel, honoring `self.pool_size`
@@ -530,8 +541,8 @@ def _exec_command(self, host, *args, **kwargs):
530541 proxy_port = self .proxy_port )
531542 return self .host_clients [host ].exec_command (* args , ** kwargs )
532543
533- def get_output (self , commands = None ):
534- """Get output from running commands .
544+ def get_output (self , cmd ):
545+ """Get output from command .
535546
536547 :param commands: (Optional) Override commands to get output from.\
537548 Uses running commands in pool if not given.
@@ -562,17 +573,23 @@ def get_output(self, commands=None):
562573 >>> self.get_exit_code(output[host])
563574 0
564575 """
565- if not commands :
566- commands = list (self .pool .greenlets )
567576 output = {}
568- for cmd in commands :
577+ try :
569578 (channel , host , stdout , stderr ) = cmd .get ()
570- output .setdefault (host , {})
571- output [host ].update ({'exit_code' : self ._get_exit_code (channel ),
572- 'channel' : channel ,
573- 'stdout' : stdout ,
574- 'stderr' : stderr ,
575- 'cmd' : cmd , })
579+ except Exception , ex :
580+ output [host ].update ({'exit_code' : None ,
581+ 'channel' : None ,
582+ 'stdout' : None ,
583+ 'stderr' : None ,
584+ 'cmd' : cmd ,
585+ 'exception' : ex ,})
586+ raise ex
587+ output .setdefault (host , {})
588+ output [host ].update ({'exit_code' : self ._get_exit_code (channel ),
589+ 'channel' : channel ,
590+ 'stdout' : stdout ,
591+ 'stderr' : stderr ,
592+ 'cmd' : cmd , })
576593 return output
577594
578595 def get_exit_code (self , host_output ):
0 commit comments