]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/offline_watcher.py
b80f5104eca4ceb3e750179779696fd1fa27136b
2 from typing
import List
, Optional
, TYPE_CHECKING
4 import multiprocessing
as mp
8 from cephadm
.module
import CephadmOrchestrator
10 logger
= logging
.getLogger(__name__
)
13 class OfflineHostWatcher(threading
.Thread
):
14 def __init__(self
, mgr
: "CephadmOrchestrator") -> None:
16 self
.hosts
: Optional
[List
[str]] = None
17 self
.new_hosts
: Optional
[List
[str]] = None
19 self
.event
= threading
.Event()
20 super(OfflineHostWatcher
, self
).__init
__(target
=self
.run
)
22 def run(self
) -> None:
23 self
.thread_pool
= mp
.pool
.ThreadPool(10)
25 # only need to take action if we have hosts to check
26 if self
.hosts
or self
.new_hosts
:
28 self
.hosts
= self
.new_hosts
30 logger
.debug(f
'OfflineHostDetector: Checking if hosts: {self.hosts} are offline.')
31 assert self
.hosts
is not None
32 self
.thread_pool
.map(self
.check_host
, self
.hosts
)
35 self
.thread_pool
.close()
36 self
.thread_pool
.join()
38 def check_host(self
, host
: str) -> None:
39 if host
not in self
.mgr
.offline_hosts
:
41 self
.mgr
.ssh
.check_execute_command(host
, ['true'])
43 logger
.debug(f
'OfflineHostDetector: detected {host} to be offline')
44 # kick serve loop in case corrective action must be taken for offline host
45 self
.mgr
._kick
_serve
_loop
()
47 def set_hosts(self
, hosts
: List
[str]) -> None:
49 if (not self
.hosts
or self
.hosts
!= hosts
) and hosts
:
50 self
.new_hosts
= hosts
52 f
'OfflineHostDetector: Hosts to check if offline swapped to: {self.new_hosts}.')
55 def wakeup(self
) -> None:
58 def shutdown(self
) -> None: