Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephadm: expose gather-facts api method #41816

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/pybind/mgr/cephadm/module.py
Expand Up @@ -1490,6 +1490,19 @@ def get_hosts(self):
"""
return list(self.inventory.all_specs())

@handle_orch_error
def get_facts(self, hostname: Optional[str] = None) -> List[Dict[str, Any]]:
"""
Return a list of hosts metadata(gather_facts) managed by the orchestrator.

Notes:
- skip async: manager reads from cache.
"""
if hostname:
return [self.cache.get_facts(hostname)]

return [self.cache.get_facts(hostname) for hostname in self.cache.get_hosts()]

@handle_orch_error
def add_host_label(self, host: str, label: str) -> str:
self.inventory.add_label(host, label)
Expand Down
12 changes: 12 additions & 0 deletions src/pybind/mgr/cephadm/tests/test_facts.py
@@ -0,0 +1,12 @@
import pytest

from ..inventory import HostCache
from ..import CephadmOrchestrator


@pytest.fixture()
def test_facts():
facts = {'node-1.ceph.com', {'bios_version': 'F2', 'cpu_cores': 16}}
HostCache.facts = facts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

ret_facts = CephadmOrchestrator.get_facts('node-1.ceph.com')
assert ret_facts == [{'bios_version': 'F2', 'cpu_cores': 16}]
4 changes: 4 additions & 0 deletions src/pybind/mgr/dashboard/services/orchestrator.py
Expand Up @@ -62,6 +62,10 @@ def get(self, hostname: str) -> Optional[HostSpec]:
hosts = [host for host in self.list() if host.hostname == hostname]
return hosts[0] if hosts else None

@wait_api_result
def get_facts(self, hostname: Optional[str] = None) -> List[Dict[str, Any]]:
return self.api.get_facts(hostname)

@wait_api_result
def add(self, hostname: str, addr: str, labels: List[str], status: str):
return self.api.add_host(HostSpec(hostname, addr=addr, labels=labels, status=status))
Expand Down
6 changes: 6 additions & 0 deletions src/pybind/mgr/orchestrator/_interface.py
Expand Up @@ -368,6 +368,12 @@ def get_hosts(self) -> OrchResult[List[HostSpec]]:
"""
raise NotImplementedError()

def get_facts(self, hostname: Optional[str] = None) -> OrchResult[List[Dict[str, Any]]]:
"""
Return hosts metadata(gather_facts).
"""
raise NotImplementedError()

def add_host_label(self, host: str, label: str) -> OrchResult[str]:
"""
Add a host label
Expand Down