]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: expose gather-facts api method
authorAvan Thakkar <athakkar@localhost.localdomain>
Fri, 11 Jun 2021 11:07:10 +0000 (16:37 +0530)
committerAlfonso Martínez <almartin@redhat.com>
Wed, 3 Nov 2021 11:31:31 +0000 (12:31 +0100)
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>
(cherry picked from commit f41eae16af9fa6725d5b714f068fab3f946d2927)

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 3aefee82208f59ae5a1361e435368b9642ef6ddb..5e5d83ce9d0b1366b8804fe0b18e7f1211b9d305 100644 (file)
@@ -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 (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 8891e8e3d3c6bcf46fcda63eec181e971ea820dd..88ebdb78d17ce30b1358d530cb6f8b5a9d0f32f0 100644 (file)
@@ -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)
index 34beb5e2a3fb640cfef8e1f3e2296a9f8011d40c..5840eb245d3fe81de158166c8c72db8a2431096e 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