@@ -210,7 +210,7 @@ def __init__(self, hosts,
210210
211211 For individual commands the status of channel can be checked ::
212212
213- output[host][' channel'] .closed
213+ output[host]. channel.closed
214214 False
215215
216216 which returns ``True`` if command has finished.
@@ -234,7 +234,7 @@ def __init__(self, hosts,
234234
235235 client.get_exit_codes(output)
236236 for host in output:
237- print(output[host][' exit_code'] )
237+ print(output[host]. exit_code)
238238 0
239239 0
240240
@@ -243,7 +243,7 @@ def __init__(self, hosts,
243243 .. code-block:: python
244244
245245 for host in output:
246- for line in output[host][' stdout'] :
246+ for line in output[host]. stdout:
247247 print(line)
248248 [myhost1] ls: cannot access /tmp/aasdfasdf: No such file or directory
249249 [myhost2] ls: cannot access /tmp/aasdfasdf: No such file or directory
@@ -406,18 +406,22 @@ def run_command(self, *args, **kwargs):
406406 **Print stdout for each command**
407407
408408 .. code-block:: python
409-
409+
410+ from __future__ import print_function
411+
410412 for host in output:
411- for line in output[host][' stdout'] :
413+ for line in output[host]. stdout:
412414 print(line)
413415
414416 **Get exit codes after command has finished**
415417
416418 .. code-block:: python
417-
419+
420+ from __future__ import print_function
421+
418422 client.get_exit_codes(output)
419423 for host in output:
420- print(output[host][' exit_code'] )
424+ print(output[host]. exit_code)
421425 0
422426 0
423427
@@ -426,9 +430,9 @@ def run_command(self, *args, **kwargs):
426430 .. code-block:: python
427431
428432 client.join(output)
429- print(output[host][' exit_code'] )
433+ print(output[host]. exit_code)
430434 0
431- for line in output[host][' stdout'] :
435+ for line in output[host]. stdout:
432436 print(line)
433437
434438 **Run with sudo**
@@ -448,9 +452,11 @@ def run_command(self, *args, **kwargs):
448452 `Enabling Host Logger` above.
449453
450454 .. code-block:: python
451-
455+
456+ from __future__ import print_function
457+
452458 for host in output:
453- stdout = list(output[host][' stdout'] )
459+ stdout = list(output[host]stdout)
454460 print("Complete stdout for host %s is %s" % (host, stdout,))
455461
456462 **Command with per-host arguments**
@@ -544,7 +550,7 @@ def run_command(self, *args, **kwargs):
544550 print("Started %s commands in %s" % (len(cmds), end-start,))
545551 start = datetime.datetime.now()
546552 for _output in output:
547- for line in _output[host][' stdout'] :
553+ for line in _output[host]. stdout:
548554 print(line)
549555 end = datetime.datetime.now()
550556 print("All commands finished in %s" % (end-start,))
@@ -560,12 +566,15 @@ def run_command(self, *args, **kwargs):
560566
561567 ::
562568
563- {'myhost1': {'exit_code': exit code if ready else None,
564- 'channel' : SSH channel of command,
565- 'stdout' : <iterable>,
566- 'stderr' : <iterable>,
567- 'cmd' : <greenlet>},
568- 'exception' : None}
569+ {'myhost1':
570+ host=myhost1
571+ exit_code=exit code if ready else None
572+ channel=SSH channel of command
573+ stdout=<iterable>
574+ stderr=<iterable>
575+ stdin=<file-like writable channel>
576+ cmd=<greenlet>
577+ exception=None}
569578
570579 **Do not stop on errors, return per-host exceptions in output**
571580
@@ -577,24 +586,26 @@ def run_command(self, *args, **kwargs):
577586
578587 .. code-block:: python
579588
580- {'myhost1': {'exit_code': None,
581- 'channel' : None,
582- 'stdout' : None,
583- 'stderr' : None,
584- 'cmd' : None,
585- 'exception' : ConnectionErrorException(
586- "Error connecting to host '%s:%s' - %s - retry %s/%s",
587- host, port, 'Connection refused', 3, 3)}}
589+ {'myhost1':
590+ host=myhost1
591+ exit_code=None
592+ channel=None
593+ stdout=None
594+ stderr=None
595+ cmd=None
596+ exception=ConnectionErrorException(
597+ "Error connecting to host '%s:%s' - %s - retry %s/%s",
598+ host, port, 'Connection refused', 3, 3)}
588599
589600 **Using stdin**
590601
591602 .. code-block:: python
592603
593604 output = client.run_command('read')
594- stdin = output['localhost'][' stdin']
605+ stdin = output['localhost']. stdin
595606 stdin.write("writing to stdin\\ n")
596607 stdin.flush()
597- for line in output['localhost'][' stdout'] :
608+ for line in output['localhost']. stdout:
598609 print(line)
599610
600611 writing to stdin
@@ -682,7 +693,7 @@ def get_output(self, cmd, output):
682693
683694 output = client.get_output()
684695 for host in output:
685- for line in output[host][' stdout'] :
696+ for line in output[host]. stdout:
686697 print(line)
687698 <stdout>
688699 # Get exit code after command has finished
@@ -731,7 +742,7 @@ def join(self, output):
731742 and retrieve exit codes"""
732743 for host in output :
733744 output [host ].cmd .join ()
734- if output [host ].channel :
745+ if output [host ].channel is not None :
735746 output [host ].channel .recv_exit_status ()
736747 self .get_exit_codes (output )
737748
@@ -743,7 +754,7 @@ def finished(self, output):
743754 """
744755 for host in output :
745756 chan = output [host ]['channel' ]
746- if chan and not chan .closed :
757+ if chan is not None and not chan .closed :
747758 return False
748759 return True
749760
@@ -883,7 +894,7 @@ def _copy_remote_file(self, host, remote_file, local_file, recurse,
883894 remote_file , file_w_suffix , recurse = recurse )
884895
885896 def _make_ssh_client (self , host ):
886- if not host in self .host_clients or not self .host_clients [host ]:
897+ if not host in self .host_clients or self .host_clients [host ] is None :
887898 _user , _port , _password , _pkey = self ._get_host_config_values (host )
888899 self .host_clients [host ] = SSHClient (
889900 host , user = _user , password = _password , port = _port , pkey = _pkey ,
0 commit comments