From ae8a2183c11ad077e65334d8f05c445f0fb36921 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 1 Nov 2023 17:58:19 -0400 Subject: [PATCH] cephadm: switch to using template files Switch off of the embedded template strings to using the recently added template files. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 70 ++-------------------------- src/cephadm/cephadmlib/templating.py | 3 -- 2 files changed, 5 insertions(+), 68 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 8f189becaa1..8b44e1c8f54 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -3387,61 +3387,15 @@ def install_base_units(ctx, fsid): """ % (fsid, ' '.join(targets), '|'.join(targets))) -_TMPL_DAEMON_UNIT = """# generated by cephadm -[Unit] -Description=Ceph %i for {{fsid}} - -# According to: -# http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget -# these can be removed once ceph-mon will dynamically change network -# configuration. -After=network-online.target local-fs.target time-sync.target{% if has_docker_engine %} docker.service{% endif %} -Wants=network-online.target local-fs.target time-sync.target -{%- if has_docker_engine %} -Requires=docker.service -{%- endif %} - -PartOf=ceph-{{fsid}}.target -Before=ceph-{{fsid}}.target - -[Service] -LimitNOFILE=1048576 -LimitNPROC=1048576 -EnvironmentFile=-/etc/environment -ExecStart=/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.run -ExecStop=-/bin/bash -c 'bash {{ctx.data_dir}}/{{fsid}}/%i/unit.stop' -ExecStopPost=-/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.poststop -KillMode=none -Restart=on-failure -RestartSec=10s -TimeoutStartSec=200 -TimeoutStopSec=120 -StartLimitInterval=30min -StartLimitBurst=5 -{%- if has_podman_engine %} -ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid -ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid -Type=forking -PIDFile=%t/%n-pid -{%- if has_podman_split_version %} -Delegate=yes -{%- endif %} -{%- endif %} - -[Install] -WantedBy=ceph-{{fsid}}.target -""" - - def get_unit_file(ctx: CephadmContext, fsid: str) -> str: has_docker_engine = isinstance(ctx.container_engine, Docker) has_podman_engine = isinstance(ctx.container_engine, Podman) has_podman_split_version = ( has_podman_engine and ctx.container_engine.supports_split_cgroups ) - return templating.template_str( + return templating.render( ctx, - _TMPL_DAEMON_UNIT, + templating.Templates.ceph_service, fsid=fsid, has_docker_engine=has_docker_engine, has_podman_engine=has_podman_engine, @@ -3619,23 +3573,9 @@ class CephadmAgent(DaemonForm): return ('set -e\n' + f'{py3} {binary_path} agent --fsid {self.fsid} --daemon-id {self.daemon_id} &\n') def unit_file(self) -> str: - ts = """#generated by cephadm -[Unit] -Description=cephadm agent for cluster {{agent.fsid}} - -PartOf=ceph-{{agent.fsid}}.target -Before=ceph-{{agent.fsid}}.target - -[Service] -Type=forking -ExecStart=/bin/bash {{agent.daemon_dir}}/unit.run -Restart=on-failure -RestartSec=10s - -[Install] -WantedBy=ceph-{{agent.fsid}}.target -""" - return templating.template_str(self.ctx, ts, agent=self) + return templating.render( + self.ctx, templating.Templates.agent_service, agent=self + ) def shutdown(self) -> None: self.stop = True diff --git a/src/cephadm/cephadmlib/templating.py b/src/cephadm/cephadmlib/templating.py index b48b5deeaab..3b7c6f9657e 100644 --- a/src/cephadm/cephadmlib/templating.py +++ b/src/cephadm/cephadmlib/templating.py @@ -65,9 +65,6 @@ class Templater: # be used to provide a simple set of methods defaultTemplater = Templater() -# (temporary alias) template_str is currently used by the cephadm code -template_str = defaultTemplater.render_str - # alias methods as module level functions for convenience. most callers do # not need to care that these are implemented via a class render_str = defaultTemplater.render_str -- 2.39.5