Skip to content

Commit

Permalink
cephadm: expose gather-facts api method
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/51209

This PR intends to expose host metadata(gather-facts) api method

Signed-off-by: Avan Thakkar <athakkar@redhat.com>
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
  • Loading branch information
Avan Thakkar committed Jun 22, 2021
1 parent addf4a8 commit f103702
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
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
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

0 comments on commit f103702

Please sign in to comment.