Connect to hosts in hosts list. Returns status of connect as a dict. :param raise_on_any_error: Optional Raise an exception even if connecting to one of the hosts fails. :type raise_on_any_error: ``boolean`` :rtype: ``dict`` of ``
(self, raise_on_any_error=False)
| 92 | LOG.debug("Connect to hosts complete.", extra=extra) |
| 93 | |
| 94 | def connect(self, raise_on_any_error=False): |
| 95 | """ |
| 96 | Connect to hosts in hosts list. Returns status of connect as a dict. |
| 97 | |
| 98 | :param raise_on_any_error: Optional Raise an exception even if connecting to one |
| 99 | of the hosts fails. |
| 100 | :type raise_on_any_error: ``boolean`` |
| 101 | |
| 102 | :rtype: ``dict`` of ``str`` to ``dict`` |
| 103 | """ |
| 104 | results = {} |
| 105 | |
| 106 | for host in self._hosts: |
| 107 | while not concurrency_lib.is_green_pool_free(self._pool): |
| 108 | concurrency_lib.sleep(self._scan_interval) |
| 109 | self._pool.spawn( |
| 110 | self._connect, |
| 111 | host=host, |
| 112 | results=results, |
| 113 | raise_on_any_error=raise_on_any_error, |
| 114 | ) |
| 115 | |
| 116 | concurrency_lib.green_pool_wait_all(self._pool) |
| 117 | |
| 118 | if self._successful_connects < 1: |
| 119 | # We definitely have to raise an exception in this case. |
| 120 | LOG.error( |
| 121 | "Unable to connect to any of the hosts.", |
| 122 | extra={"connect_results": results}, |
| 123 | ) |
| 124 | msg = ( |
| 125 | "Unable to connect to any one of the hosts: %s.\n\n connect_errors=%s" |
| 126 | % ( |
| 127 | self._hosts, |
| 128 | json_encode(results, indent=2), |
| 129 | ) |
| 130 | ) |
| 131 | raise NoHostsConnectedToException(msg) |
| 132 | |
| 133 | return results |
| 134 | |
| 135 | def run(self, cmd, timeout=None): |
| 136 | """ |