:param handle_stdout_line_func: Callback function which is called dynamically each time a new stdout line is received. :type handle_stdout_line_func: ``func`` :param handle_stderr_line_func: Callback function which is called dynamical
(
self,
hosts,
user=None,
password=None,
pkey_file=None,
pkey_material=None,
port=22,
bastion_host=None,
concurrency=10,
raise_on_any_error=False,
connect=True,
passphrase=None,
handle_stdout_line_func=None,
handle_stderr_line_func=None,
sudo_password=False,
)
| 40 | CONNECT_ERROR = "Cannot connect to host." |
| 41 | |
| 42 | def __init__( |
| 43 | self, |
| 44 | hosts, |
| 45 | user=None, |
| 46 | password=None, |
| 47 | pkey_file=None, |
| 48 | pkey_material=None, |
| 49 | port=22, |
| 50 | bastion_host=None, |
| 51 | concurrency=10, |
| 52 | raise_on_any_error=False, |
| 53 | connect=True, |
| 54 | passphrase=None, |
| 55 | handle_stdout_line_func=None, |
| 56 | handle_stderr_line_func=None, |
| 57 | sudo_password=False, |
| 58 | ): |
| 59 | """ |
| 60 | :param handle_stdout_line_func: Callback function which is called dynamically each time a |
| 61 | new stdout line is received. |
| 62 | :type handle_stdout_line_func: ``func`` |
| 63 | |
| 64 | :param handle_stderr_line_func: Callback function which is called dynamically each time a |
| 65 | new stderr line is received. |
| 66 | :type handle_stderr_line_func: ``func`` |
| 67 | """ |
| 68 | self._ssh_user = user |
| 69 | self._ssh_key_file = pkey_file |
| 70 | self._ssh_key_material = pkey_material |
| 71 | self._ssh_password = password |
| 72 | self._hosts = hosts |
| 73 | self._successful_connects = 0 |
| 74 | self._ssh_port = port |
| 75 | self._bastion_host = bastion_host |
| 76 | self._passphrase = passphrase |
| 77 | self._handle_stdout_line_func = handle_stdout_line_func |
| 78 | self._handle_stderr_line_func = handle_stderr_line_func |
| 79 | self._sudo_password = sudo_password |
| 80 | |
| 81 | if not hosts: |
| 82 | raise Exception("Need an non-empty list of hosts to talk to.") |
| 83 | |
| 84 | self._pool = concurrency_lib.get_green_pool_class()(concurrency) |
| 85 | self._hosts_client = {} |
| 86 | self._bad_hosts = {} |
| 87 | self._scan_interval = 0.1 |
| 88 | |
| 89 | if connect: |
| 90 | connect_results = self.connect(raise_on_any_error=raise_on_any_error) |
| 91 | extra = {"_connect_results": connect_results} |
| 92 | LOG.debug("Connect to hosts complete.", extra=extra) |
| 93 | |
| 94 | def connect(self, raise_on_any_error=False): |
| 95 | """ |