]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: allow list daemons by service_name 34160/head
authorKiefer Chang <kiefer.chang@suse.com>
Tue, 10 Mar 2020 11:43:42 +0000 (19:43 +0800)
committerSage Weil <sage@redhat.com>
Tue, 24 Mar 2020 22:27:02 +0000 (17:27 -0500)
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 <kiefer.chang@suse.com>
(cherry picked from commit 079c9fd7718ceb17660da61d46019c53012e0f0c)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py
src/pybind/mgr/rook/module.py
src/pybind/mgr/test_orchestrator/module.py

index 2ebf9d29bfdcf122cbaedcb16cf83e120a09489c..9131f0160fc1d223a772d78bf384f10ac3f18aa6 100644 (file)
@@ -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
index d72d8af97eb7bffacd39190434fcbe6a7426f0e7..6077fcdb7b354fb7ceb0c277d6ee77f8aebf3fe8 100644 (file)
@@ -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.
index b200334930fe4d6bbc3057d72bd2d5bf47baae8b..314bb53e0a2cb0e5ff9dae790e3590ad1a902d24 100644 (file)
@@ -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)
index cabc5080a790a08c7cc14cb1b2fcf9d083a6b7cd..1fe17a60ab4f0fb1f293f029ffc900e2475e8d76 100644 (file)
@@ -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']
index 276d0894655ae1362246baf6ec8effc22161eecc..c01c80b19ca67dbb50dfa6874ac82dbec6d058c2 100644 (file)
@@ -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: