]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/utils.py
5 from functools
import wraps
6 from typing
import Optional
, Callable
, TypeVar
, List
, NewType
, TYPE_CHECKING
7 from orchestrator
import OrchestratorError
10 from cephadm
import CephadmOrchestrator
13 logger
= logging
.getLogger(__name__
)
15 ConfEntity
= NewType('ConfEntity', str)
16 AuthEntity
= NewType('AuthEntity', str)
19 class CephadmNoImage(Enum
):
23 # Used for _run_cephadm used for check-host etc that don't require an --image parameter
24 cephadmNoImage
= CephadmNoImage
.token
27 def name_to_config_section(name
: str) -> ConfEntity
:
29 Map from daemon names to ceph entity names (as seen in config)
31 daemon_type
= name
.split('.', 1)[0]
32 if daemon_type
in ['rgw', 'rbd-mirror', 'nfs', 'crash', 'iscsi']:
33 return ConfEntity('client.' + name
)
34 elif daemon_type
in ['mon', 'osd', 'mds', 'mgr', 'client']:
35 return ConfEntity(name
)
37 return ConfEntity('mon')
40 def name_to_auth_entity(daemon_type
: str,
45 Map from daemon names/host to ceph entity names (as seen in config)
47 if daemon_type
in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]:
48 return AuthEntity('client.' + daemon_type
+ "." + daemon_id
)
49 elif daemon_type
== 'crash':
51 raise OrchestratorError("Host not provided to generate <crash> auth entity name")
52 return AuthEntity('client.' + daemon_type
+ "." + host
)
53 elif daemon_type
== 'mon':
54 return AuthEntity('mon.')
55 elif daemon_type
== 'mgr':
56 return AuthEntity(daemon_type
+ "." + daemon_id
)
57 elif daemon_type
in ['osd', 'mds', 'client']:
58 return AuthEntity(daemon_type
+ "." + daemon_id
)
60 raise OrchestratorError("unknown auth entity name")
63 def forall_hosts(f
: Callable
[..., T
]) -> Callable
[..., List
[T
]]:
65 def forall_hosts_wrapper(*args
) -> List
[T
]:
66 from cephadm
.module
import CephadmOrchestrator
68 # Some weired logic to make calling functions with multiple arguments work.
75 assert 'either f([...]) or self.f([...])'
78 if not isinstance(arg
, tuple):
84 except Exception as e
:
85 logger
.exception(f
'executing {f.__name__}({args}) failed.')
88 assert CephadmOrchestrator
.instance
is not None
89 return CephadmOrchestrator
.instance
._worker
_pool
.map(do_work
, vals
)
91 return forall_hosts_wrapper
94 def get_cluster_health(mgr
: 'CephadmOrchestrator') -> str:
95 # check cluster health
96 ret
, out
, err
= mgr
.check_mon_command({
102 except Exception as e
:
103 raise OrchestratorError('failed to parse health status')