From 24c744d7d38019eaf8f994f8d0c83fd776b2b6af Mon Sep 17 00:00:00 2001 From: Alessandro Fulgini Date: Sun, 3 Dec 2023 18:16:48 +0100 Subject: [PATCH 1/3] Alias generate systemd options `stop_timeout` and `time` Closes #683 Option `time` was used before Podman v4, then it was renamed `stop_timeout`. Accept both names (the newer takes prirority) and set the correct CLI argument name based on the detected Podman version. Signed-off-by: Alessandro Fulgini --- plugins/module_utils/podman/common.py | 10 ++++++---- plugins/modules/podman_container.py | 10 ++++------ plugins/modules/podman_pod.py | 8 +++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/module_utils/podman/common.py b/plugins/module_utils/podman/common.py index ea5b4502..4da578be 100644 --- a/plugins/module_utils/podman/common.py +++ b/plugins/module_utils/podman/common.py @@ -52,12 +52,14 @@ def run_generate_systemd_command(module, module_params, name, version): sysconf['restart_policy']]) if sysconf.get('restart_sec') is not None: command.extend(['--restart-sec=%s' % sysconf['restart_sec']]) - if sysconf.get('stop_timeout') is not None: - command.extend(['--stop-timeout=%s' % sysconf['stop_timeout']]) + if sysconf.get('stop_timeout') is not None or sysconf.get('time') is not None: + # Select correct parameter name based on version + arg_name = 'stop_timeout' if gt4ver else 'time' + arg_value = sysconf.get('stop_timeout') if sysconf.get('stop_timeout') is not None else sysconf.get('time') + command.extend(['--%s=%s' % (arg_name, arg_value)]) + del arg_name, arg_value if sysconf.get('start_timeout') is not None: command.extend(['--start-timeout=%s' % sysconf['start_timeout']]) - if sysconf.get('time'): - command.extend(['--time', str(sysconf['time'])]) if sysconf.get('no_header'): command.extend(['--no-header']) if sysconf.get('names', True): diff --git a/plugins/modules/podman_container.py b/plugins/modules/podman_container.py index 47492bec..0fc62e64 100644 --- a/plugins/modules/podman_container.py +++ b/plugins/modules/podman_container.py @@ -336,14 +336,12 @@ type: int required: false stop_timeout: - description: Override the default stop timeout for the container with the given value. - type: int - required: false - time: description: - - Override the default stop timeout for the container with the given value. + - Override the default stop timeout for the container with the given value. Called `time` before version 4. type: int required: false + aliases: + - time no_header: description: - Do not generate the header including meta data such as the Podman version and the timestamp. @@ -891,7 +889,7 @@ generate_systemd: path: /tmp/ restart_policy: always - time: 120 + stop_timeout: 120 names: true container_prefix: ainer diff --git a/plugins/modules/podman_pod.py b/plugins/modules/podman_pod.py index 5dd3e1df..7b57fd30 100644 --- a/plugins/modules/podman_pod.py +++ b/plugins/modules/podman_pod.py @@ -160,14 +160,12 @@ type: int required: false stop_timeout: - description: Override the default stop timeout for the container with the given value. - type: int - required: false - time: description: - - Override the default stop timeout for the container with the given value. + - Override the default stop timeout for the container with the given value. Called `time` before version 4. type: int required: false + aliases: + - time no_header: description: - Do not generate the header including meta data such as the Podman version and the timestamp. From cb26f6fde3d1c8978288b3a575f696e15db8e4f4 Mon Sep 17 00:00:00 2001 From: Alessandro Fulgini Date: Sun, 3 Dec 2023 22:04:50 +0100 Subject: [PATCH 2/3] Fix typo in parameter name `--stop-timeout` Signed-off-by: Alessandro Fulgini --- plugins/module_utils/podman/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/podman/common.py b/plugins/module_utils/podman/common.py index 4da578be..8ea214ea 100644 --- a/plugins/module_utils/podman/common.py +++ b/plugins/module_utils/podman/common.py @@ -52,9 +52,9 @@ def run_generate_systemd_command(module, module_params, name, version): sysconf['restart_policy']]) if sysconf.get('restart_sec') is not None: command.extend(['--restart-sec=%s' % sysconf['restart_sec']]) - if sysconf.get('stop_timeout') is not None or sysconf.get('time') is not None: + if (sysconf.get('stop_timeout') is not None) or (sysconf.get('time') is not None): # Select correct parameter name based on version - arg_name = 'stop_timeout' if gt4ver else 'time' + arg_name = 'stop-timeout' if gt4ver else 'time' arg_value = sysconf.get('stop_timeout') if sysconf.get('stop_timeout') is not None else sysconf.get('time') command.extend(['--%s=%s' % (arg_name, arg_value)]) del arg_name, arg_value From 772bfda471e43e68f3537adaeec8a49b95f3a76e Mon Sep 17 00:00:00 2001 From: Alessandro Fulgini Date: Mon, 4 Dec 2023 19:20:15 +0100 Subject: [PATCH 3/3] Don't delete temporary variables at the end of block Co-authored-by: Sergey <6213510+sshnaidm@users.noreply.github.com> --- plugins/module_utils/podman/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/module_utils/podman/common.py b/plugins/module_utils/podman/common.py index 8ea214ea..2eefcb2d 100644 --- a/plugins/module_utils/podman/common.py +++ b/plugins/module_utils/podman/common.py @@ -57,7 +57,6 @@ def run_generate_systemd_command(module, module_params, name, version): arg_name = 'stop-timeout' if gt4ver else 'time' arg_value = sysconf.get('stop_timeout') if sysconf.get('stop_timeout') is not None else sysconf.get('time') command.extend(['--%s=%s' % (arg_name, arg_value)]) - del arg_name, arg_value if sysconf.get('start_timeout') is not None: command.extend(['--start-timeout=%s' % sysconf['start_timeout']]) if sysconf.get('no_header'):