]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: expose gather-facts api method
authorAvan Thakkar <athakkar@localhost.localdomain>
Fri, 11 Jun 2021 11:07:10 +0000 (16:37 +0530)
committerNizamudeen A <nia@redhat.com>
Tue, 12 Oct 2021 06:00:47 +0000 (11:30 +0530)
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>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_facts.py [new file with mode: 0644]
src/pybind/mgr/dashboard/services/orchestrator.py
src/pybind/mgr/orchestrator/_interface.py

index 41476c1c99207f1ddf9c75b039d754fb5d2cd206..fcf2ac174c9b30f441d347b556eb58fb0f15369f 100644 (file)
@@ -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 (file)
index 0000000..79e6db0
--- /dev/null
@@ -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}]
index 44309a84939173938e9b52bda5fda4b21dd4f18c..88a6cb3a8608530ca44d8ab47c53bcf16e14dfe8 100644 (file)
@@ -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)
index 158299885b1cb84de5f7cc7305c7803e9006f723..91925a59e6843b8c0b84e67dd0d944043ea18e7c 100644 (file)
@@ -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