Skip to content

Commit cb832c9

Browse files
authored
Use replace option to recreate a container (#613)
In recreating container use `--replace` option. Signed-off-by: Sagi Shnaidman <[email protected]>
1 parent ff12ccd commit cb832c9

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

plugins/module_utils/podman/podman_container_lib.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def construct_command_from_params(self):
208208
"""
209209
if self.action in ['start', 'stop', 'delete', 'restart']:
210210
return self.start_stop_delete()
211-
if self.action in ['create', 'run']:
211+
if self.action in ['create', 'run', 'recreate']:
212212
cmd = [self.action, '--name', self.params['name']]
213213
all_param_methods = [func for func in dir(self)
214214
if callable(getattr(self, func))
@@ -1443,11 +1443,14 @@ def _perform_action(self, action):
14431443
action {str} -- action to perform - start, create, stop, run,
14441444
delete, restart
14451445
"""
1446-
b_command = PodmanModuleParams(action,
1446+
b_command = PodmanModuleParams(action if action != 'recreate' else 'create',
14471447
self.module_params,
14481448
self.version,
14491449
self.module,
14501450
).construct_command_from_params()
1451+
if action == 'recreate':
1452+
action = 'create'
1453+
b_command.insert(1, b'--replace')
14511454
if action == 'create':
14521455
b_command.remove(b'--detach=True')
14531456
full_cmd = " ".join([self.module_params['executable']]
@@ -1498,11 +1501,7 @@ def create(self):
14981501

14991502
def recreate(self):
15001503
"""Recreate the container."""
1501-
if self.running:
1502-
self.stop()
1503-
if not self.info['HostConfig']['AutoRemove']:
1504-
self.delete()
1505-
self.create()
1504+
self._perform_action('recreate')
15061505

15071506
def recreate_run(self):
15081507
"""Recreate and run the container."""

0 commit comments

Comments
 (0)