]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add sidecars_from_dropin function
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 18 Nov 2023 18:59:19 +0000 (13:59 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 2 Jan 2024 14:30:21 +0000 (09:30 -0500)
Add a sidecars_from_dropin function that takes a minimal PathInfo object
and returns a PathInfo populated with sidecars information based on
reading the content of the dropin file. This will be useful when we need
information on configured sidecars but are not on the deploy path.

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

index f44fd2b8fcd543910fd1aa20700296a8367f3b1e..b0f62b9cbfacded59b3a0a567db07f9280cbe2ec 100644 (file)
@@ -211,3 +211,30 @@ def update_files(
     _install_extended_systemd_services(
         ctx, pathinfo, ident, bool(init_container_ids)
     )
+
+
+def sidecars_from_dropin(
+    pathinfo: PathInfo, missing_ok: bool = False
+) -> PathInfo:
+    """Read the list of sidecars for a service from the service's drop in file."""
+    # This is useful in the cases where the sidecars would be determined from
+    # input data (deployment) but we lack the original deployment data (rm
+    # daemon).
+    sidecars = []
+    try:
+        with open(pathinfo.drop_in_file) as fh:
+            lines = fh.readlines()
+    except FileNotFoundError:
+        if missing_ok:
+            return pathinfo
+        raise
+    for line in lines:
+        if not line.startswith('Wants='):
+            continue
+        for item in line[6:].strip().split():
+            si, category = DaemonSubIdentity.from_service_name(item)
+            if category == 'sidecar':
+                sidecars.append(si)
+    return PathInfo(
+        pathinfo.default_unit_file.parent, pathinfo.identity, sidecars
+    )