Fixing ip address without mask bug (#3784) (#3803)

* change ip6 type to list of str and fix problem with setting addresses without netmask

* change ip6 type to list of str and fix problem with setting addresses without netmask

* Add changelog fragment

* add suggestions

* fix no mask using bug

* Make change independed from feature branch

(cherry picked from commit aae3ae1a8e)

Co-authored-by: Alex Groshev <38885591+haddystuff@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-11-30 06:01:50 +01:00 committed by GitHub
parent 3d1ca5638b
commit b85ff2a997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 10 deletions

View file

@ -70,7 +70,7 @@ options:
ip4:
description:
- List of IPv4 addresses to this interface.
- Use the format C(192.0.2.24/24).
- Use the format C(192.0.2.24/24) or C(192.0.2.24).
- If defined and I(method4) is not specified, automatically set C(ipv4.method) to C(manual).
type: list
elements: str
@ -144,7 +144,7 @@ options:
ip6:
description:
- The IPv6 address to this interface.
- Use the format C(abbe::cafe).
- Use the format C(abbe::cafe/128 or abbe::cafe).
- If defined and I(method6) is not specified, automatically set C(ipv6.method) to C(manual).
type: str
gw6:
@ -1011,6 +1011,16 @@ EXAMPLES = r'''
- 192.0.3.100/24
state: present
- name: Add second ip6 address
community.general.nmcli:
conn_name: my-eth1
ifname: eth1
type: ethernet
ip6:
- 2001:db8::cafe
- 2002:db8::cafe
state: present
- name: Add VxLan
community.general.nmcli:
type: vxlan
@ -1255,7 +1265,7 @@ class Nmcli(object):
# IP address options.
if self.ip_conn_type and not self.master:
options.update({
'ipv4.addresses': self.ip4,
'ipv4.addresses': self.enforce_ipv4_cidr_notation(self.ip4),
'ipv4.dhcp-client-id': self.dhcp_client_id,
'ipv4.dns': self.dns4,
'ipv4.dns-search': self.dns4_search,
@ -1268,7 +1278,7 @@ class Nmcli(object):
'ipv4.never-default': self.never_default4,
'ipv4.method': self.ipv4_method,
'ipv4.may-fail': self.may_fail4,
'ipv6.addresses': self.ip6,
'ipv6.addresses': self.enforce_ipv6_cidr_notation(self.ip6),
'ipv6.dns': self.dns6,
'ipv6.dns-search': self.dns6_search,
'ipv6.ignore-auto-dns': self.dns6_ignore_auto,
@ -1458,6 +1468,21 @@ class Nmcli(object):
'sit',
)
@staticmethod
def enforce_ipv4_cidr_notation(ip4_addresses):
if ip4_addresses is None:
return None
return [address if '/' in address else address + '/32' for address in ip4_addresses]
@staticmethod
def enforce_ipv6_cidr_notation(ip6_address):
if ip6_address is None:
return None
elif '/' in ip6_address:
return ip6_address
else:
return ip6_address + '/128'
@staticmethod
def bool_to_string(boolean):
if boolean: