Skip to content

Commit

Permalink
fix #656: do not force network removal by default
Browse files Browse the repository at this point in the history
* Remove `-f` flag when removing network with `podman network rm`, so
  that containers using the network won't be removed by default.
* Add `force` option (default False) to `podman_network`, which uses `-f`
  and removes containers using the network

Signed-off-by: Chris Xiao <[email protected]>
  • Loading branch information
chrisx8 committed Oct 29, 2023
1 parent b65a3de commit 580dfc0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions plugins/modules/podman_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


Expand Down Expand Up @@ -37,6 +38,11 @@
description:
- Driver to manage the network (default "bridge")
type: str
force:
description:
- Remove all containers that use the network.
If the container is running, it is stopped and removed.
type: bool
gateway:
description:
- IPv4 or IPv6 gateway for the subnet
Expand Down Expand Up @@ -219,14 +225,15 @@ def construct_command_from_params(self):
list -- list of byte strings for Popen command
"""
if self.action in ['delete']:
return self._simple_action()
return self._delete_action()
if self.action in ['create']:
return self._create_action()

def _simple_action(self):
if self.action == 'delete':
cmd = ['rm', '-f', self.params['name']]
return [to_bytes(i, errors='surrogate_or_strict') for i in cmd]
def _delete_action(self):
cmd = ['rm', self.params['name']]
if self.params.get('force', False):
cmd += ['--force']
return [to_bytes(i, errors='surrogate_or_strict') for i in cmd]

def _create_action(self):
cmd = [self.action, self.params['name']]
Expand Down Expand Up @@ -648,6 +655,7 @@ def main():
name=dict(type='str', required=True),
disable_dns=dict(type='bool', required=False),
driver=dict(type='str', required=False),
force=dict(type='bool', required=False),
gateway=dict(type='str', required=False),
internal=dict(type='bool', required=False),
ip_range=dict(type='str', required=False),
Expand Down

0 comments on commit 580dfc0

Please sign in to comment.