]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: convert list_daemons to use new iterator func
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 27 Jan 2025 20:32:37 +0000 (15:32 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 11 Feb 2025 21:08:05 +0000 (16:08 -0500)
Convert list_daemons to use the new daemons_matching iteration function
provided by cephadmlib.listing module.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py

index 86b8deca24d2ccb87b7f97df5154d92165603740..983a8349b2ca73ce646774dcc600553aebbb4df0 100755 (executable)
@@ -193,6 +193,7 @@ from cephadmlib.daemons import (
     NodeProxy,
 )
 from cephadmlib.agent import http_query
+from cephadmlib.listing import daemons_matching, LegacyDaemonEntry
 
 
 FuncT = TypeVar('FuncT', bound=Callable)
@@ -3414,70 +3415,36 @@ def list_daemons(
     seen_memusage_cid_len, seen_memusage = parsed_container_mem_usage(ctx)
     seen_cpuperc_cid_len, seen_cpuperc = parsed_container_cpu_perc(ctx)
 
-    for i in os.listdir(data_dir):
-        if i in ['mon', 'osd', 'mds', 'mgr', 'rgw']:
-            if type_of_daemon and type_of_daemon != i:
-                continue
-            daemon_type = i
-            for j in os.listdir(os.path.join(data_dir, i)):
-                if '-' not in j:
-                    continue
-                (cluster, daemon_id) = j.split('-', 1)
-                fsid = get_legacy_daemon_fsid(
+    daemon_entries = daemons_matching(
+        ctx,
+        legacy_dir,
+        daemon_name=daemon_name,
+        daemon_type=type_of_daemon,
+    )
+    for entry in daemon_entries:
+        if isinstance(entry, LegacyDaemonEntry):
+            status = cast(Dict[str, Any], entry.status)
+            if detail:
+                _update_legacy_status(
+                    status, ctx, entry.name, legacy_cache,
+                )
+            ls.append(status)
+        else:
+            status = cast(Dict[str, Any], entry.status)
+            if detail:
+                _update_daemon_and_container_status(
+                    status,
                     ctx,
-                    cluster,
-                    daemon_type,
-                    daemon_id,
-                    legacy_dir=legacy_dir,
+                    entry.identity,
+                    data_dir,
+                    seen_versions,
+                    seen_digests,
+                    seen_memusage_cid_len,
+                    seen_memusage,
+                    seen_cpuperc_cid_len,
+                    seen_cpuperc,
                 )
-                legacy_unit_name = 'ceph-%s@%s' % (daemon_type, daemon_id)
-                val: Dict[str, Any] = {
-                    'style': 'legacy',
-                    'name': '%s.%s' % (daemon_type, daemon_id),
-                    'fsid': fsid if fsid is not None else 'unknown',
-                    'systemd_unit': legacy_unit_name,
-                }
-                if detail:
-                    _update_legacy_status(
-                        val, ctx, legacy_unit_name, legacy_cache
-                    )
-                ls.append(val)
-        elif is_fsid(i):
-            fsid = str(i)  # convince mypy that fsid is a str here
-            for j in os.listdir(os.path.join(data_dir, i)):
-                if not (
-                    '.' in j
-                    and os.path.isdir(os.path.join(data_dir, fsid, j))
-                ):
-                    continue
-                name = j
-                if daemon_name and name != daemon_name:
-                    continue
-                (daemon_type, daemon_id) = j.split('.', 1)
-                if type_of_daemon and type_of_daemon != daemon_type:
-                    continue
-                identity = DaemonIdentity.from_name(fsid, name)
-                val = {
-                    'style': 'cephadm:v1',
-                    'name': name,
-                    'fsid': fsid,
-                    'systemd_unit': identity.unit_name,
-                }
-                if detail:
-                    _update_daemon_and_container_status(
-                        val,
-                        ctx,
-                        identity,
-                        data_dir,
-                        seen_versions,
-                        seen_digests,
-                        seen_memusage_cid_len,
-                        seen_memusage,
-                        seen_cpuperc_cid_len,
-                        seen_cpuperc,
-                    )
-
-                ls.append(val)
+            ls.append(status)
     return ls