Skip to content

Commit

Permalink
cephadm:expose gather-facts orch api
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) orch api

Signed-off-by: Avan Thakkar <athakkar@redhat.com>
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
  • Loading branch information
Aashish Sharma committed Jun 14, 2021
1 parent ffb87fa commit 32c78cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/pybind/mgr/cephadm/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,24 @@ def get_hosts(self):
"""
return list(self.inventory.all_specs())

@handle_orch_error
@forall_hosts
def get_gather_facts(self, hostname:str):
# type: (str) -> List[str]
"""
Return a list of host metadata managed by the orchestrator.
Notes:
- skip async: manager reads from cache.
"""
out, err, code = CephadmServe(self)._run_cephadm(hostname, cephadmNoImage, "gather-facts",
error_ok=True)

if code:
raise OrchestratorError('Gather facts failed: %s' % '\n'.join(out + err))

return json.loads(out)

@handle_orch_error
def add_host_label(self, host: str, label: str) -> str:
self.inventory.add_label(host, label)
Expand Down
7 changes: 7 additions & 0 deletions src/pybind/mgr/orchestrator/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ def _get_hosts(self, format: Format = Format.plain) -> HandleCommandResult:
output = table.get_string()
return HandleCommandResult(stdout=output)

@_cli_read_command('orch host gather facts')
def _get_hosts_gather_facts(self, hostname) -> HandleCommandResult:
"""List hosts metadata"""
completion = self.get_gather_facts(hostname)
raise_if_exception(completion)
return HandleCommandResult(stdout=completion.result_str())

@_cli_write_command('orch host label add')
def _host_label_add(self, hostname: str, label: str) -> HandleCommandResult:
"""Add a host label"""
Expand Down

0 comments on commit 32c78cf

Please sign in to comment.