]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: add daemon type predicate func to daemons_matching
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 24 Feb 2025 21:17:28 +0000 (16:17 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 27 Mar 2025 16:11:26 +0000 (12:11 -0400)
Add a predicate function [1] argument, in the style of itertools,  to
the daemons_matching function to support filtering within the "fast
path" of the daemon listing on daemon type before additional information
about a daemon/service is done.

[1] - https://en.wikipedia.org/wiki/Boolean-valued_function

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

index 44004b572af4dde715f7724f2a138ae3e66750ad..7ece41b713d0a5a11add0e2b1c1d136acaf0b72b 100644 (file)
 import os
 import logging
 
-from typing import TypedDict, Union, Optional, Iterator, List, Any, Dict, cast
+from typing import (
+    Any,
+    Callable,
+    Dict,
+    Iterator,
+    List,
+    Optional,
+    TypedDict,
+    Union,
+    cast,
+)
 
 from .context import CephadmContext
 from .daemon_identity import DaemonIdentity
@@ -191,6 +201,7 @@ def daemons_matching(
     daemon_name: Optional[str] = None,
     daemon_type: Optional[str] = None,
     fsid: Optional[str] = None,
+    daemon_type_predicate: Optional[Callable[[str], bool]] = None,
 ) -> Iterator[Union[LegacyDaemonEntry, DaemonEntry]]:
     """Iterate over the daemons configured on the current node, matching daemon
     name or daemon type if supplied.
@@ -201,6 +212,11 @@ def daemons_matching(
                 continue
             if daemon_type is not None and daemon_type != entry.daemon_type:
                 continue
+            if (
+                daemon_type_predicate is not None
+                and not daemon_type_predicate(entry.daemon_type)
+            ):
+                continue
         elif isinstance(entry, DaemonEntry):
             if fsid is not None and fsid != entry.identity.fsid:
                 continue
@@ -214,6 +230,11 @@ def daemons_matching(
                 and daemon_type != entry.identity.daemon_type
             ):
                 continue
+            if (
+                daemon_type_predicate is not None
+                and not daemon_type_predicate(entry.identity.daemon_type)
+            ):
+                continue
         else:
             raise ValueError(f'unexpected entry type: {entry}')
         yield entry