Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ipv6. mtu, vlan to network and fix CI #154

Merged
merged 2 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions plugins/modules/podman_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
description:
- Allocate container IP from range
type: str
ipv6:
description:
- Enable IPv6 (Dual Stack) networking. You must pass a IPv6 subnet.
The subnet option must be used with the ipv6 option.
type: bool
subnet:
description:
- Subnet in CIDR format
Expand All @@ -57,6 +62,21 @@
description:
- Create a Macvlan connection based on this device
type: str
opt:
description:
- Add network options. Currently 'vlan' and 'mtu' are supported.
type: dict
suboptions:
mtu:
description:
- MTU size for bridge network interface.
type: int
required: false
vlan:
description:
- VLAN tag for bridge which enables vlan_filtering.
type: int
required: false
debug:
description:
- Return additional information which can be helpful for investigations.
Expand Down Expand Up @@ -140,7 +160,6 @@
]
"""

# noqa: F402
import json # noqa: F402
from distutils.version import LooseVersion # noqa: F402
import os # noqa: F402
Expand Down Expand Up @@ -218,12 +237,22 @@ def addparam_subnet(self, c):
def addparam_ip_range(self, c):
return c + ['--ip-range', self.params['ip_range']]

def addparam_ipv6(self, c):
return c + ['--ipv6']

def addparam_macvlan(self, c):
return c + ['--macvlan', self.params['macvlan']]

def addparam_internal(self, c):
return c + ['--internal=%s' % self.params['internal']]

def addparam_opt(self, c):
for opt in self.params['opt'].items():
c += ['--opt',
b"=".join([to_bytes(k, errors='surrogate_or_strict')
for k in opt])]
return c

def addparam_disable_dns(self, c):
return c + ['--disable-dns=%s' % self.params['disable_dns']]

Expand Down Expand Up @@ -331,6 +360,20 @@ def diffparam_macvlan(self):
before = after = ''
return self._diff_update_and_compare('macvlan', before, after)

def diffparam_opt(self):
vlan_before = self.info['plugins'][0].get('vlan')
vlan_after = self.params['opt'].get('vlan') if self.params['opt'] else None
if vlan_before or vlan_after:
before, after = {'vlan': vlan_before}, {'vlan': vlan_after}
else:
before, after = {}, {}
mtu_before = self.info['plugins'][0].get('mtu')
mtu_after = self.params['opt'].get('mtu') if self.params['opt'] else None
if mtu_before or mtu_after:
before.update({'mtu': mtu_before})
after.update({'mtu': mtu_after})
return self._diff_update_and_compare('opt', before, after)

def is_different(self):
diff_func_list = [func for func in dir(self)
if callable(getattr(self, func)) and func.startswith(
Expand Down Expand Up @@ -548,14 +591,20 @@ def main():
gateway=dict(type='str', required=False),
internal=dict(type='bool', required=False),
ip_range=dict(type='str', required=False),
ipv6=dict(type='bool', required=False),
subnet=dict(type='str', required=False),
macvlan=dict(type='str', required=False),
opt=dict(type='dict', required=False,
options=dict(
mtu=dict(type='int', required=False),
vlan=dict(type='int', required=False))),
executable=dict(type='str', required=False, default='podman'),
debug=dict(type='bool', default=False),
recreate=dict(type='bool', default=False),
),
required_by=dict( # for IP range to set 'subnet' is required
required_by=dict( # for IP range and GW to set 'subnet' is required
ip_range=('subnet'),
gateway=('subnet'),
))

PodmanNetworkManager(module).execute()
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/targets/podman_network/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
name: "{{ network_name }}"
state: present
gateway: 10.100.100.100
subnet: 10.100.100.0/24
register: info6

- name: Check info
Expand All @@ -126,6 +127,7 @@
name: "{{ network_name }}"
state: present
gateway: 10.100.100.100
subnet: 10.100.100.0/24
register: info7

- name: Check info
Expand Down Expand Up @@ -192,6 +194,13 @@
that:
- info13 is not changed

- name: Create network with ipv6 subnet
containers.podman.podman_network:
name: "{{ network_name }}"
state: present
subnet: 2001:cafe::/64
ipv6: true

- name: Make sure network doesn't exist
containers.podman.podman_network:
name: "{{ network_name }}"
Expand Down