From f41eae16af9fa6725d5b714f068fab3f946d2927 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 --- 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 41476c1c992..fcf2ac174c9 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1434,6 +1434,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 00000000000..79e6db00ce8 --- /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 44309a84939..88a6cb3a860 100644 --- a/src/pybind/mgr/dashboard/services/orchestrator.py +++ b/src/pybind/mgr/dashboard/services/orchestrator.py @@ -66,6 +66,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 158299885b1..91925a59e68 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