From 32c78cf584405f7db3dee883a426dbfa71758035 Mon Sep 17 00:00:00 2001 From: Aashish Sharma Date: Mon, 14 Jun 2021 19:13:57 +0530 Subject: [PATCH] cephadm:expose gather-facts orch api Fixes: https://tracker.ceph.com/issues/51209 This PR intends to expose host metadata(gather-facts) orch api Signed-off-by: Avan Thakkar Signed-off-by: Aashish Sharma --- src/pybind/mgr/cephadm/module.py | 18 ++++++++++++++++++ src/pybind/mgr/orchestrator/module.py | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index cde603154deb31..62b2c6e21f8ee5 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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) diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index d923d1646608ee..d317f11c279c14 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -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"""