From: John Mulligan Date: Sat, 18 Nov 2023 18:59:19 +0000 (-0500) Subject: cephadm: add sidecars_from_dropin function X-Git-Tag: v19.3.0~284^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1991cd6de845c65d8ab3b887a154f1e671d9b9f2;p=ceph.git cephadm: add sidecars_from_dropin function 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 --- diff --git a/src/cephadm/cephadmlib/systemd_unit.py b/src/cephadm/cephadmlib/systemd_unit.py index f44fd2b8fcd5..b0f62b9cbfac 100644 --- a/src/cephadm/cephadmlib/systemd_unit.py +++ b/src/cephadm/cephadmlib/systemd_unit.py @@ -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 + )