import errno
import logging
import time
-import yaml
+from copy import copy
from threading import Event
from functools import wraps
r.append(dd)
return r
+ def get_daemons_with_volatile_status(self) -> Iterator[Tuple[str, Dict[str, orchestrator.DaemonDescription]]]:
+ for host, dm in self.daemons.items():
+ if host in self.mgr.offline_hosts:
+ def set_offline(dd: orchestrator.DaemonDescription) -> orchestrator.DaemonDescription:
+ ret = copy(dd)
+ ret.status = -1
+ ret.status_desc = 'host is offline'
+ return ret
+ yield host, {name: set_offline(d) for name, d in dm.items()}
+ else:
+ yield host, dm
+
def get_daemons_by_service(self, service_name):
# type: (str) -> List[orchestrator.DaemonDescription]
result = [] # type: List[orchestrator.DaemonDescription]
self._refresh_host_daemons(host)
# <service_map>
sm = {} # type: Dict[str, orchestrator.ServiceDescription]
- for h, dm in self.cache.daemons.items():
+ for h, dm in self.cache.get_daemons_with_volatile_status():
for name, dd in dm.items():
if service_type and service_type != dd.daemon_type:
continue
for hostname, hi in self.inventory.items():
self._refresh_host_daemons(hostname)
result = []
- for h, dm in self.cache.daemons.items():
+ for h, dm in self.cache.get_daemons_with_volatile_status():
if host and h != host:
continue
for name, dd in dm.items():
c[k] = datetime.datetime.strptime(c[k], DATEFMT)
return cls(**c)
+ def __copy__(self):
+ # feel free to change this:
+ return DaemonDescription.from_json(self.to_json())
+
class ServiceDescription(object):
"""
For responding to queries about the status of a particular service,
raise_if_exception, _cli_write_command, TrivialReadCompletion, OrchestratorError, \
NoOrchestrator, OrchestratorValidationError, NFSServiceSpec, \
RGWSpec, InventoryFilter, InventoryHost, HostSpec, CLICommandMeta, \
- ServiceDescription, IscsiServiceSpec
+ ServiceDescription, DaemonDescription, IscsiServiceSpec
def nice_delta(now, t, suffix=''):
if t:
refresh=refresh)
self._orchestrator_wait([completion])
raise_if_exception(completion)
- daemons = completion.result
+ daemons: List[DaemonDescription] = completion.result
def ukn(s):
return '<unknown>' if s is None else s
table.left_padding_width = 0
table.right_padding_width = 2
for s in sorted(daemons, key=lambda s: s.name()):
- status = {
- -1: 'error',
- 0: 'stopped',
- 1: 'running',
- None: '<unknown>'
- }[s.status]
+ if s.status_desc:
+ status = s.status_desc
+ else:
+ status = {
+ -1: 'error',
+ 0: 'stopped',
+ 1: 'running',
+ None: '<unknown>'
+ }[s.status]
if s.status == 1 and s.started:
status += ' (%s)' % to_pretty_timedelta(now - s.started)