from .inventory import Inventory, SpecStore, HostCache, EventStore
from .upgrade import CEPH_UPGRADE_ORDER, CephadmUpgrade
from .template import TemplateMgr
+from .utils import forall_hosts
try:
import remoto
CEPH_TYPES = set(CEPH_UPGRADE_ORDER)
-def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]:
- @wraps(f)
- def forall_hosts_wrapper(*args) -> List[T]:
-
- # Some weired logic to make calling functions with multiple arguments work.
- if len(args) == 1:
- vals = args[0]
- self = None
- elif len(args) == 2:
- self, vals = args
- else:
- assert 'either f([...]) or self.f([...])'
-
- def do_work(arg):
- if not isinstance(arg, tuple):
- arg = (arg, )
- try:
- if self:
- return f(self, *arg)
- return f(*arg)
- except Exception as e:
- logger.exception(f'executing {f.__name__}({args}) failed.')
- raise
-
- assert CephadmOrchestrator.instance is not None
- return CephadmOrchestrator.instance._worker_pool.map(do_work, vals)
-
-
- return forall_hosts_wrapper
-
-
class CephadmCompletion(orchestrator.Completion):
def evaluate(self):
self.finalize(None)
-import re
+import logging
+from functools import wraps
+from typing import Optional, Callable, TypeVar, List
from orchestrator import OrchestratorError
-from typing import Optional
+
+T = TypeVar('T')
+logger = logging.getLogger(__name__)
+
def name_to_config_section(name: str) -> str:
"""
return daemon_type + "." + daemon_id
else:
raise OrchestratorError("unknown auth entity name")
+
+
+def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]:
+ @wraps(f)
+ def forall_hosts_wrapper(*args) -> List[T]:
+ from cephadm.module import CephadmOrchestrator
+
+ # Some weired logic to make calling functions with multiple arguments work.
+ if len(args) == 1:
+ vals = args[0]
+ self = None
+ elif len(args) == 2:
+ self, vals = args
+ else:
+ assert 'either f([...]) or self.f([...])'
+
+ def do_work(arg):
+ if not isinstance(arg, tuple):
+ arg = (arg, )
+ try:
+ if self:
+ return f(self, *arg)
+ return f(*arg)
+ except Exception as e:
+ logger.exception(f'executing {f.__name__}({args}) failed.')
+ raise
+
+ assert CephadmOrchestrator.instance is not None
+ return CephadmOrchestrator.instance._worker_pool.map(do_work, vals)
+
+
+ return forall_hosts_wrapper
\ No newline at end of file