Skip to content

Commit

Permalink
Alias generate systemd options stop_timeout and time (#685)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Fix typo in parameter name `--stop-timeout`

Signed-off-by: Alessandro Fulgini <[email protected]>

* Don't delete temporary variables at the end of block

Co-authored-by: Sergey <[email protected]>

---------

Signed-off-by: Alessandro Fulgini <[email protected]>
Co-authored-by: Sergey <[email protected]>
  • Loading branch information
fuljo and sshnaidm authored Dec 7, 2023
1 parent e245e33 commit 4d233a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 5 additions & 4 deletions plugins/module_utils/podman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ 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)])
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):
Expand Down
10 changes: 4 additions & 6 deletions plugins/modules/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -891,7 +889,7 @@
generate_systemd:
path: /tmp/
restart_policy: always
time: 120
stop_timeout: 120
names: true
container_prefix: ainer
Expand Down
8 changes: 3 additions & 5 deletions plugins/modules/podman_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4d233a4

Please sign in to comment.