From 079c9fd7718ceb17660da61d46019c53012e0f0c Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Tue, 10 Mar 2020 19:43:42 +0800 Subject: [PATCH] mgr/orch: allow list daemons by service_name Services like rgw and mds are differentiated by service_name. For example: mds.xyz vs. mds.abc. With current interface, we can't list all daemons belonged to mds.xyz only. Add service_name as a new argument to filter daemons by it. Fixes: https://tracker.ceph.com/issues/44541 Signed-off-by: Kiefer Chang --- src/pybind/mgr/cephadm/module.py | 8 +++++--- src/pybind/mgr/orchestrator/_interface.py | 4 ++-- src/pybind/mgr/orchestrator/module.py | 6 ++++-- src/pybind/mgr/rook/module.py | 7 ++++--- src/pybind/mgr/test_orchestrator/module.py | 4 +++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 2ebf9d29bfd..9131f0160fc 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1878,7 +1878,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return [s for n, s in sm.items()] @trivial_completion - def list_daemons(self, daemon_type=None, daemon_id=None, + def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False): if refresh: # ugly sync path, FIXME someday perhaps? @@ -1892,9 +1892,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): if host and h != host: continue for name, dd in dm.items(): - if daemon_type and daemon_type != dd.daemon_type: + if daemon_type is not None and daemon_type != dd.daemon_type: continue - if daemon_id and daemon_id != dd.daemon_id: + if daemon_id is not None and daemon_id != dd.daemon_id: + continue + if service_name is not None and service_name != dd.service_name(): continue result.append(dd) return result diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index d72d8af97eb..6077fcdb7b3 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -837,8 +837,8 @@ class Orchestrator(object): """ raise NotImplementedError() - def list_daemons(self, daemon_type=None, daemon_id=None, host=None, refresh=False): - # type: (Optional[str], Optional[str], Optional[str], bool) -> Completion + def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False): + # type: (Optional[str], Optional[str], Optional[str], Optional[str], bool) -> Completion """ Describe a daemon (of any kind) that is already configured in the orchestrator. diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index b200334930f..314bb53e0a2 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -377,13 +377,15 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule): @_cli_read_command( 'orch ps', "name=hostname,type=CephString,req=false " + "name=service_name,type=CephString,req=false " "name=daemon_type,type=CephString,req=false " "name=daemon_id,type=CephString,req=false " "name=format,type=CephChoices,strings=json|plain,req=false " "name=refresh,type=CephBool,req=false", 'List daemons known to orchestrator') - def _list_daemons(self, hostname=None, daemon_type=None, daemon_id=None, format='plain', refresh=False): - completion = self.list_daemons(daemon_type, + def _list_daemons(self, hostname=None, service_name=None, daemon_type=None, daemon_id=None, format='plain', refresh=False): + completion = self.list_daemons(service_name, + daemon_type, daemon_id=daemon_id, host=hostname, refresh=refresh) diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index cabc5080a79..1fe17a60ab4 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -358,11 +358,11 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): return [v for k, v in spec.items()] @deferred_read - def list_daemons(self, daemon_type=None, daemon_id=None, host=None, + def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False): return self._list_daemons(daemon_type, daemon_id, host, refresh) - def _list_daemons(self, daemon_type=None, daemon_id=None, host=None, + def _list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False): pods = self.rook_cluster.describe_pods(daemon_type, daemon_id, host) self.log.debug('pods %s' % pods) @@ -390,8 +390,9 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): # Unknown type -- skip it continue + if service_name is not None and service_name != sd.service_name(): + continue sd.container_image_name = p['container_image_name'] - sd.created = p['created'] sd.last_configured = p['created'] sd.last_deployed = p['created'] diff --git a/src/pybind/mgr/test_orchestrator/module.py b/src/pybind/mgr/test_orchestrator/module.py index 276d0894655..c01c80b19ca 100644 --- a/src/pybind/mgr/test_orchestrator/module.py +++ b/src/pybind/mgr/test_orchestrator/module.py @@ -220,7 +220,7 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): return list(filter(_filter_func, services)) @deferred_read - def list_daemons(self, daemon_type=None, daemon_id=None, host=None, refresh=False): + def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False): """ There is no guarantee which daemons are returned by describe_service, except that it returns the mgr we're running in. @@ -232,6 +232,8 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): daemons = self._daemons if self._daemons else self._get_ceph_daemons() def _filter_func(d): + if service_name is not None and service_name != d.service_name(): + return False if daemon_type is not None and daemon_type != d.daemon_type: return False if daemon_id is not None and daemon_id != d.daemon_id: -- 2.39.5