|
41 | 41 | NUM_RETRIES = 3 |
42 | 42 |
|
43 | 43 | logger = logging.getLogger(__name__) |
44 | | - |
45 | | -def _setup_logger(_logger): |
46 | | - """Setup default logger""" |
47 | | - _handler = logging.StreamHandler() |
48 | | - log_format = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s - %(message)s') |
49 | | - _handler.setFormatter(log_format) |
50 | | - _logger.addHandler(handler) |
51 | | - _logger.setLevel(logging.DEBUG) |
52 | 44 |
|
53 | 45 | class UnknownHostException(Exception): |
54 | 46 | """Raised when a host is unknown (dns failure)""" |
@@ -122,10 +114,7 @@ def __init__(self, host, |
122 | 114 | 'hostname' in host_config |
123 | 115 | else host) |
124 | 116 | _user = host_config['user'] if 'user' in host_config else None |
125 | | - if user: |
126 | | - user = user |
127 | | - else: |
128 | | - user = _user |
| 117 | + user = user if user else _user |
129 | 118 | client = paramiko.SSHClient() |
130 | 119 | client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy()) |
131 | 120 | self.forward_ssh_agent = forward_ssh_agent |
@@ -489,24 +478,3 @@ def _copy_file(self, host, local_file, remote_file): |
489 | 478 | port=self.port, pkey=self.pkey, |
490 | 479 | forward_ssh_agent=self.forward_ssh_agent) |
491 | 480 | return self.host_clients[host].copy_file(local_file, remote_file) |
492 | | - |
493 | | - |
494 | | -def test(): |
495 | | - client = SSHClient('localhost') |
496 | | - channel, host, stdout, stderr = client.exec_command('ls -ltrh') |
497 | | - for line in stdout: |
498 | | - print line.strip() |
499 | | - client.copy_file('../test', 'test_dir/test') |
500 | | - |
501 | | -def test_parallel(): |
502 | | - client = ParallelSSHClient(['localhost']) |
503 | | - cmds = client.exec_command('ls -ltrh') |
504 | | - output = [client.get_stdout(cmd, return_buffers=True) for cmd in cmds] |
505 | | - print output |
506 | | - cmds = client.copy_file('../test', 'test_dir/test') |
507 | | - client.pool.join() |
508 | | - |
509 | | -if __name__ == "__main__": |
510 | | - _setup_logger(logger) |
511 | | - test() |
512 | | - test_parallel() |
0 commit comments