Skip to content

Commit

Permalink
Revert "Use replace option to recreate a container (#613)" (#616)
Browse files Browse the repository at this point in the history
This reverts commit cb832c9.
We lose flexibility in recreating workflow, replace actually
does the same in Podman - stops and removes/creates.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
  • Loading branch information
sshnaidm committed Aug 7, 2023
1 parent cb832c9 commit aeec6b9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def construct_command_from_params(self):
"""
if self.action in ['start', 'stop', 'delete', 'restart']:
return self.start_stop_delete()
if self.action in ['create', 'run', 'recreate']:
if self.action in ['create', 'run']:
cmd = [self.action, '--name', self.params['name']]
all_param_methods = [func for func in dir(self)
if callable(getattr(self, func))
Expand Down Expand Up @@ -1443,14 +1443,11 @@ def _perform_action(self, action):
action {str} -- action to perform - start, create, stop, run,
delete, restart
"""
b_command = PodmanModuleParams(action if action != 'recreate' else 'create',
b_command = PodmanModuleParams(action,
self.module_params,
self.version,
self.module,
).construct_command_from_params()
if action == 'recreate':
action = 'create'
b_command.insert(1, b'--replace')
if action == 'create':
b_command.remove(b'--detach=True')
full_cmd = " ".join([self.module_params['executable']]
Expand Down Expand Up @@ -1501,7 +1498,11 @@ def create(self):

def recreate(self):
"""Recreate the container."""
self._perform_action('recreate')
if self.running:
self.stop()
if not self.info['HostConfig']['AutoRemove']:
self.delete()
self.create()

def recreate_run(self):
"""Recreate and run the container."""
Expand Down

0 comments on commit aeec6b9

Please sign in to comment.