import threading
import time
-from orchestrator import DaemonDescriptionStatus
+from orchestrator import DaemonDescriptionStatus, OrchestratorError
from orchestrator._interface import daemon_type_to_service
from ceph.utils import datetime_now, http_req
from ceph.deployment.inventory import Devices
"""
try:
results = self.mgr.node_proxy_cache.fullreport(**kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.criticals(**kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.summary(**kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('memory', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('network', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('processors', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('storage', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('power', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.common('fans', **kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
"""
try:
results = self.mgr.node_proxy_cache.firmwares(**kw)
- except KeyError:
+ except (KeyError, OrchestratorError):
raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
return results
def _is_unknown_status(self, statuses: ValuesView) -> bool:
return self._has_health_value(statuses, 'unknown') and not self._is_error_status(statuses)
+ def _resolve_hosts(self, **kw: Any) -> List[str]:
+ hostname = kw.get('hostname')
+ if hostname is None:
+ return list(self.data.keys())
+ if hostname not in self.data:
+ raise OrchestratorError(
+ f"Host '{hostname}' has no node-proxy data (unknown host or node-proxy not running)."
+ )
+ return [hostname]
+
def fullreport(self, **kw: Any) -> Dict[str, Any]:
"""
Retrieves the full report for the specified hostname.
:return: The full report data for the specified hostname(s).
:rtype: dict
"""
- hostname = kw.get('hostname')
- hosts = [hostname] if hostname else self.data.keys()
+ hosts = self._resolve_hosts(**kw)
return {host: self.data[host] for host in hosts}
def summary(self, **kw: Any) -> Dict[str, Any]:
host or all hosts and their components.
:rtype: Dict[str, Dict[str, str]]
"""
- hostname = kw.get('hostname')
- hosts = [hostname] if hostname else self.data.keys()
-
+ hosts = self._resolve_hosts(**kw)
_result: Dict[str, Any] = {}
for host in hosts:
:return: Endpoint information for the specified host(s).
:rtype: Union[Dict[str, Any], Any]
"""
- hostname = kw.get('hostname')
+ hosts = self._resolve_hosts(**kw)
_result = {}
- hosts = [hostname] if hostname else self.data.keys()
for host in hosts:
try:
:return: A dictionary containing firmware information for each host.
:rtype: Dict[str, Any]
"""
- hostname = kw.get('hostname')
- hosts = [hostname] if hostname else self.data.keys()
-
+ hosts = self._resolve_hosts(**kw)
return {host: self.data[host]['firmwares'] for host in hosts}
def get_critical_from_host(self, hostname: str) -> Dict[str, Any]:
+ if hostname not in self.data:
+ raise OrchestratorError(
+ f"Host '{hostname}' has no node-proxy data (unknown host or node-proxy not running)."
+ )
results: Dict[str, Any] = {}
for component, component_data in self.data[hostname]['status'].items():
:return: A dictionary containing critical information for each host.
:rtype: List[Dict[str, Any]]
"""
- hostname = kw.get('hostname')
+ hosts = self._resolve_hosts(**kw)
results: Dict[str, Any] = {}
- hosts = [hostname] if hostname else self.data.keys()
for host in hosts:
results[host] = self.get_critical_from_host(host)
return results