From 45edc336255c2cfcf8681052ab7d4614b0612416 Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Fri, 11 Jun 2021 16:37:10 +0530 Subject: [PATCH] cephadm: expose gather-facts api method Fixes: https://tracker.ceph.com/issues/51209 This PR intends to expose host metadata(gather-facts) api method Signed-off-by: Avan Thakkar Signed-off-by: Aashish Sharma (cherry picked from commit f41eae16af9fa6725d5b714f068fab3f946d2927) --- src/pybind/mgr/cephadm/module.py | 13 +++++++++++++ src/pybind/mgr/cephadm/tests/test_facts.py | 12 ++++++++++++ src/pybind/mgr/dashboard/services/orchestrator.py | 4 ++++ src/pybind/mgr/orchestrator/_interface.py | 6 ++++++ 4 files changed, 35 insertions(+) create mode 100644 src/pybind/mgr/cephadm/tests/test_facts.py diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 3aefee82208f5..5e5d83ce9d0b1 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1577,6 +1577,19 @@ Then run the following: """ 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) diff --git a/src/pybind/mgr/cephadm/tests/test_facts.py b/src/pybind/mgr/cephadm/tests/test_facts.py new file mode 100644 index 0000000000000..79e6db00ce83c --- /dev/null +++ b/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}] diff --git a/src/pybind/mgr/dashboard/services/orchestrator.py b/src/pybind/mgr/dashboard/services/orchestrator.py index 8891e8e3d3c6b..88ebdb78d17ce 100644 --- a/src/pybind/mgr/dashboard/services/orchestrator.py +++ b/src/pybind/mgr/dashboard/services/orchestrator.py @@ -67,6 +67,10 @@ class HostManger(ResourceManager): def add(self, hostname: str, addr: str, labels: List[str]): return self.api.add_host(HostSpec(hostname, addr=addr, labels=labels)) + @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 remove(self, hostname: str): return self.api.remove_host(hostname) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 34beb5e2a3fb6..5840eb245d3fe 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -376,6 +376,12 @@ class Orchestrator(object): """ 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 -- 2.39.5