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 17, 2021
1 parent 9dabec8 commit 0f8485f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pybind/mgr/cephadm/module.py
Expand Up @@ -1490,6 +1490,21 @@ def get_hosts(self):
"""
return list(self.inventory.all_specs())

@handle_orch_error
def get_gather_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)]
gather_facts = []
for h in self.cache.get_hosts():
gather_facts.append(self.cache.get_facts(h))
return gather_facts

@handle_orch_error
def add_host_label(self, host: str, label: str) -> str:
self.inventory.add_label(host, label)
Expand Down
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 gather_facts(self, hostname: Optional[str] = None) -> List[Dict[str, Any]]:
return self.api.get_gather_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_gather_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 0f8485f

Please sign in to comment.