returns True if the given host is up and we are able to establish a connection using the given credentials.
(self, conn_type, hostname)
| 308 | raise libvirtError(connection.last_error) |
| 309 | |
| 310 | def host_is_up(self, conn_type, hostname): |
| 311 | """ |
| 312 | returns True if the given host is up and we are able to establish |
| 313 | a connection using the given credentials. |
| 314 | """ |
| 315 | try: |
| 316 | socket_host = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 317 | socket_host.settimeout(1) |
| 318 | if conn_type == CONN_SSH: |
| 319 | if ':' in hostname: |
| 320 | LIBVIRT_HOST, PORT = (hostname).split(":") |
| 321 | PORT = int(PORT) |
| 322 | else: |
| 323 | PORT = SSH_PORT |
| 324 | LIBVIRT_HOST = hostname |
| 325 | socket_host.connect((LIBVIRT_HOST, PORT)) |
| 326 | if conn_type == CONN_TCP: |
| 327 | socket_host.connect((hostname, TCP_PORT)) |
| 328 | if conn_type == CONN_TLS: |
| 329 | socket_host.connect((hostname, TLS_PORT)) |
| 330 | socket_host.close() |
| 331 | return True |
| 332 | except Exception as err: |
| 333 | return err |
| 334 | |
| 335 | connection_manager = wvmConnectionManager( |
| 336 | settings.LIBVIRT_KEEPALIVE_INTERVAL if hasattr(settings, 'LIBVIRT_KEEPALIVE_INTERVAL') else 5, |
no test coverage detected