]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add a new context getter for rank
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 15 Jul 2024 19:14:13 +0000 (15:14 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 20 Aug 2024 13:42:12 +0000 (09:42 -0400)
Add a new context getter function to fetch a daemon's rank and rank
generation value.

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

index 0bd0c0e5e6c45fad54a26a39e21109e8ab532c6b..7b99abeaa5f5556c85f5fd354f3452c41654110b 100644 (file)
@@ -136,6 +136,24 @@ def fetch_endpoints(ctx: CephadmContext) -> List[EndPoint]:
     return endpoints
 
 
+def fetch_rank_info(ctx: CephadmContext) -> Optional[Tuple[int, int]]:
+    """Return the daemon's rank and rank generation values as a tuple of ints
+    if available. Return None if rank information is not available.
+    """
+    meta = getattr(ctx, 'meta_properties', None)
+    if meta is None:
+        return None
+    # We must either return both rank *and* rank_generation together or
+    # nothing at all.
+    try:
+        rank, gen = meta['rank'], meta['rank_generation']
+    except KeyError:
+        return None
+    if rank is None or gen is None:
+        return None
+    return int(rank), int(gen)
+
+
 def get_config_and_keyring(ctx):
     # type: (CephadmContext) -> Tuple[Optional[str], Optional[str]]
     config = None