|
|
@ -24,6 +24,8 @@ requirements: [ nmcli, dbus, NetworkManager-glib ]
|
|
|
|
version_added: "2.0"
|
|
|
|
version_added: "2.0"
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Manage the network devices. Create, modify and manage various connection and device type e.g., ethernet, teams, bonds, vlans etc.
|
|
|
|
- Manage the network devices. Create, modify and manage various connection and device type e.g., ethernet, teams, bonds, vlans etc.
|
|
|
|
|
|
|
|
- "On CentOS and Fedora like systems, install dependencies as 'yum/dnf install -y python-gobject NetworkManager-glib'"
|
|
|
|
|
|
|
|
- "On Ubuntu and Debian like systems, install dependencies as 'apt-get install -y libnm-glib-dev'"
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
state:
|
|
|
|
state:
|
|
|
|
required: True
|
|
|
|
required: True
|
|
|
@ -80,6 +82,12 @@ options:
|
|
|
|
default: None
|
|
|
|
default: None
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- 'A list of upto 3 dns servers, ipv4 format e.g. To add two IPv4 DNS server addresses: "192.0.2.53 198.51.100.53"'
|
|
|
|
- 'A list of upto 3 dns servers, ipv4 format e.g. To add two IPv4 DNS server addresses: "192.0.2.53 198.51.100.53"'
|
|
|
|
|
|
|
|
dns4_search:
|
|
|
|
|
|
|
|
required: False
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- 'A list of DNS search domains.'
|
|
|
|
|
|
|
|
version_added: 2.5
|
|
|
|
ip6:
|
|
|
|
ip6:
|
|
|
|
required: False
|
|
|
|
required: False
|
|
|
|
default: None
|
|
|
|
default: None
|
|
|
@ -94,6 +102,12 @@ options:
|
|
|
|
required: False
|
|
|
|
required: False
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- 'A list of upto 3 dns servers, ipv6 format e.g. To add two IPv6 DNS server addresses: "2001:4860:4860::8888 2001:4860:4860::8844"'
|
|
|
|
- 'A list of upto 3 dns servers, ipv6 format e.g. To add two IPv6 DNS server addresses: "2001:4860:4860::8888 2001:4860:4860::8844"'
|
|
|
|
|
|
|
|
dns6_search:
|
|
|
|
|
|
|
|
required: False
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- 'A list of DNS search domains.'
|
|
|
|
|
|
|
|
version_added: 2.5
|
|
|
|
mtu:
|
|
|
|
mtu:
|
|
|
|
required: False
|
|
|
|
required: False
|
|
|
|
default: 1500
|
|
|
|
default: 1500
|
|
|
@ -485,19 +499,20 @@ EXAMPLES = '''
|
|
|
|
# - 10 Connection, device, or access point does not exist.
|
|
|
|
# - 10 Connection, device, or access point does not exist.
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
HAVE_DBUS = False
|
|
|
|
RETURN = r"""#
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import dbus
|
|
|
|
import dbus
|
|
|
|
HAVE_DBUS = True
|
|
|
|
HAVE_DBUS = True
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
HAVE_DBUS = False
|
|
|
|
|
|
|
|
|
|
|
|
HAVE_NM_CLIENT = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from gi.repository import NetworkManager, NMClient
|
|
|
|
from gi.repository import NetworkManager, NMClient
|
|
|
|
HAVE_NM_CLIENT = True
|
|
|
|
HAVE_NM_CLIENT = True
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
HAVE_NM_CLIENT = False
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
@ -521,34 +536,36 @@ class Nmcli(object):
|
|
|
|
if HAVE_DBUS:
|
|
|
|
if HAVE_DBUS:
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
# The following is going to be used in dbus code
|
|
|
|
# The following is going to be used in dbus code
|
|
|
|
DEVTYPES = {1: "Ethernet",
|
|
|
|
DEVTYPES = {
|
|
|
|
2: "Wi-Fi",
|
|
|
|
1: "Ethernet",
|
|
|
|
5: "Bluetooth",
|
|
|
|
2: "Wi-Fi",
|
|
|
|
6: "OLPC",
|
|
|
|
5: "Bluetooth",
|
|
|
|
7: "WiMAX",
|
|
|
|
6: "OLPC",
|
|
|
|
8: "Modem",
|
|
|
|
7: "WiMAX",
|
|
|
|
9: "InfiniBand",
|
|
|
|
8: "Modem",
|
|
|
|
10: "Bond",
|
|
|
|
9: "InfiniBand",
|
|
|
|
11: "VLAN",
|
|
|
|
10: "Bond",
|
|
|
|
12: "ADSL",
|
|
|
|
11: "VLAN",
|
|
|
|
13: "Bridge",
|
|
|
|
12: "ADSL",
|
|
|
|
14: "Generic",
|
|
|
|
13: "Bridge",
|
|
|
|
15: "Team"
|
|
|
|
14: "Generic",
|
|
|
|
}
|
|
|
|
15: "Team"
|
|
|
|
STATES = {0: "Unknown",
|
|
|
|
}
|
|
|
|
10: "Unmanaged",
|
|
|
|
STATES = {
|
|
|
|
20: "Unavailable",
|
|
|
|
0: "Unknown",
|
|
|
|
30: "Disconnected",
|
|
|
|
10: "Unmanaged",
|
|
|
|
40: "Prepare",
|
|
|
|
20: "Unavailable",
|
|
|
|
50: "Config",
|
|
|
|
30: "Disconnected",
|
|
|
|
60: "Need Auth",
|
|
|
|
40: "Prepare",
|
|
|
|
70: "IP Config",
|
|
|
|
50: "Config",
|
|
|
|
80: "IP Check",
|
|
|
|
60: "Need Auth",
|
|
|
|
90: "Secondaries",
|
|
|
|
70: "IP Config",
|
|
|
|
100: "Activated",
|
|
|
|
80: "IP Check",
|
|
|
|
110: "Deactivating",
|
|
|
|
90: "Secondaries",
|
|
|
|
120: "Failed"
|
|
|
|
100: "Activated",
|
|
|
|
}
|
|
|
|
110: "Deactivating",
|
|
|
|
|
|
|
|
120: "Failed"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, module):
|
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
|
|
|
self.module = module
|
|
|
@ -561,9 +578,11 @@ class Nmcli(object):
|
|
|
|
self.ip4 = module.params['ip4']
|
|
|
|
self.ip4 = module.params['ip4']
|
|
|
|
self.gw4 = module.params['gw4']
|
|
|
|
self.gw4 = module.params['gw4']
|
|
|
|
self.dns4 = ' '.join(module.params['dns4']) if module.params.get('dns4') else None
|
|
|
|
self.dns4 = ' '.join(module.params['dns4']) if module.params.get('dns4') else None
|
|
|
|
|
|
|
|
self.dns4_search = ' '.join(module.params['dns4_search']) if module.params.get('dns4_search') else None
|
|
|
|
self.ip6 = module.params['ip6']
|
|
|
|
self.ip6 = module.params['ip6']
|
|
|
|
self.gw6 = module.params['gw6']
|
|
|
|
self.gw6 = module.params['gw6']
|
|
|
|
self.dns6 = module.params['dns6']
|
|
|
|
self.dns6 = module.params['dns6']
|
|
|
|
|
|
|
|
self.dns6_search = ' '.join(module.params['dns6_search']) if module.params.get('dns6_search') else None
|
|
|
|
self.mtu = module.params['mtu']
|
|
|
|
self.mtu = module.params['mtu']
|
|
|
|
self.stp = module.params['stp']
|
|
|
|
self.stp = module.params['stp']
|
|
|
|
self.priority = module.params['priority']
|
|
|
|
self.priority = module.params['priority']
|
|
|
@ -633,7 +652,8 @@ class Nmcli(object):
|
|
|
|
setting_list.append(self.dict_to_string(config[setting_name]))
|
|
|
|
setting_list.append(self.dict_to_string(config[setting_name]))
|
|
|
|
return setting_list
|
|
|
|
return setting_list
|
|
|
|
|
|
|
|
|
|
|
|
def bool_to_string(self, boolean):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def bool_to_string(boolean):
|
|
|
|
if boolean:
|
|
|
|
if boolean:
|
|
|
|
return "yes"
|
|
|
|
return "yes"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -689,7 +709,6 @@ class Nmcli(object):
|
|
|
|
|
|
|
|
|
|
|
|
def down_connection(self):
|
|
|
|
def down_connection(self):
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'down', self.conn_name]
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'down', self.conn_name]
|
|
|
|
# if self.connection_exists():
|
|
|
|
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
def up_connection(self):
|
|
|
|
def up_connection(self):
|
|
|
@ -708,48 +727,40 @@ class Nmcli(object):
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
if self.ip4 is not None:
|
|
|
|
options = {
|
|
|
|
cmd.append('ip4')
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append('gw4')
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
if self.ip6 is not None:
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
cmd.append('ip6')
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
}
|
|
|
|
if self.gw6 is not None:
|
|
|
|
|
|
|
|
cmd.append('gw6')
|
|
|
|
for key, value in options.items():
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
if value is not None:
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
cmd.extend([key, value])
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def modify_connection_team(self):
|
|
|
|
def modify_connection_team(self):
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'mod', self.conn_name]
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'mod', self.conn_name]
|
|
|
|
# format for modifying team interface
|
|
|
|
options = {
|
|
|
|
if self.ip4 is not None:
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
cmd.append('ipv4.address')
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv4.dns': self.dns4,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append('ipv4.gateway')
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'ipv6.dns': self.dns6,
|
|
|
|
if self.dns4 is not None:
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
cmd.append('ipv4.dns')
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
cmd.append(self.dns4)
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
if self.ip6 is not None:
|
|
|
|
}
|
|
|
|
cmd.append('ipv6.address')
|
|
|
|
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
for key, value in options.items():
|
|
|
|
if self.gw6 is not None:
|
|
|
|
if value is not None:
|
|
|
|
cmd.append('ipv6.gateway')
|
|
|
|
cmd.extend([key, value])
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
|
|
|
|
if self.dns6 is not None:
|
|
|
|
|
|
|
|
cmd.append('ipv6.dns')
|
|
|
|
|
|
|
|
cmd.append(self.dns6)
|
|
|
|
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
|
|
|
|
# Can't use MTU with team
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def create_connection_team_slave(self):
|
|
|
|
def create_connection_team_slave(self):
|
|
|
@ -767,9 +778,6 @@ class Nmcli(object):
|
|
|
|
cmd.append('master')
|
|
|
|
cmd.append('master')
|
|
|
|
if self.conn_name is not None:
|
|
|
|
if self.conn_name is not None:
|
|
|
|
cmd.append(self.master)
|
|
|
|
cmd.append(self.master)
|
|
|
|
# if self.mtu is not None:
|
|
|
|
|
|
|
|
# cmd.append('802-3-ethernet.mtu')
|
|
|
|
|
|
|
|
# cmd.append(self.mtu)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def modify_connection_team_slave(self):
|
|
|
|
def modify_connection_team_slave(self):
|
|
|
@ -792,68 +800,53 @@ class Nmcli(object):
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
if self.mode is not None:
|
|
|
|
options = {
|
|
|
|
cmd.append('mode')
|
|
|
|
'mode': self.mode,
|
|
|
|
cmd.append(self.mode)
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
if self.ip4 is not None:
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
cmd.append('ip4')
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
cmd.append('gw4')
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
if self.ip6 is not None:
|
|
|
|
'miimon': self.miimon,
|
|
|
|
cmd.append('ip6')
|
|
|
|
'downdelay': self.downdelay,
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
'updelay': self.updelay,
|
|
|
|
if self.gw6 is not None:
|
|
|
|
'arp-interval': self.arp_interval,
|
|
|
|
cmd.append('gw6')
|
|
|
|
'arp-ip-target': self.arp_ip_target,
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
'primary': self.primary,
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
}
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
for key, value in options.items():
|
|
|
|
if self.miimon is not None:
|
|
|
|
if value is not None:
|
|
|
|
cmd.append('miimon')
|
|
|
|
cmd.extend([key, value])
|
|
|
|
cmd.append(self.miimon)
|
|
|
|
|
|
|
|
if self.downdelay is not None:
|
|
|
|
|
|
|
|
cmd.append('downdelay')
|
|
|
|
|
|
|
|
cmd.append(self.downdelay)
|
|
|
|
|
|
|
|
if self.downdelay is not None:
|
|
|
|
|
|
|
|
cmd.append('updelay')
|
|
|
|
|
|
|
|
cmd.append(self.updelay)
|
|
|
|
|
|
|
|
if self.downdelay is not None:
|
|
|
|
|
|
|
|
cmd.append('arp-interval')
|
|
|
|
|
|
|
|
cmd.append(self.arp_interval)
|
|
|
|
|
|
|
|
if self.downdelay is not None:
|
|
|
|
|
|
|
|
cmd.append('arp-ip-target')
|
|
|
|
|
|
|
|
cmd.append(self.arp_ip_target)
|
|
|
|
|
|
|
|
if self.primary is not None:
|
|
|
|
|
|
|
|
cmd.append('primary')
|
|
|
|
|
|
|
|
cmd.append(self.primary)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def modify_connection_bond(self):
|
|
|
|
def modify_connection_bond(self):
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'mod', self.conn_name]
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'mod', self.conn_name]
|
|
|
|
# format for modifying bond interface
|
|
|
|
# format for modifying bond interface
|
|
|
|
if self.ip4 is not None:
|
|
|
|
options = {
|
|
|
|
cmd.append('ipv4.address')
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'ipv4.dns': self.dns4,
|
|
|
|
cmd.append('ipv4.gateway')
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
if self.dns4 is not None:
|
|
|
|
'ipv6.dns': self.dns6,
|
|
|
|
cmd.append('ipv4.dns')
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
cmd.append(self.dns4)
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
if self.ip6 is not None:
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
cmd.append('ipv6.address')
|
|
|
|
'miimon': self.miimon,
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
'downdelay': self.downdelay,
|
|
|
|
if self.gw6 is not None:
|
|
|
|
'updelay': self.updelay,
|
|
|
|
cmd.append('ipv6.gateway')
|
|
|
|
'arp-interval': self.arp_interval,
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
'arp-ip-target': self.arp_ip_target,
|
|
|
|
if self.dns6 is not None:
|
|
|
|
}
|
|
|
|
cmd.append('ipv6.dns')
|
|
|
|
|
|
|
|
cmd.append(self.dns6)
|
|
|
|
for key, value in options.items():
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
if value is not None:
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
cmd.extend([key, value])
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def create_connection_bond_slave(self):
|
|
|
|
def create_connection_bond_slave(self):
|
|
|
@ -898,21 +891,20 @@ class Nmcli(object):
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
cmd.append(self.ifname)
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
elif self.conn_name is not None:
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
cmd.append(self.conn_name)
|
|
|
|
if self.ip4 is not None:
|
|
|
|
options = {
|
|
|
|
cmd.append('ip4')
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append('gw4')
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
if self.ip6 is not None:
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
cmd.append('ip6')
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
}
|
|
|
|
if self.gw6 is not None:
|
|
|
|
|
|
|
|
cmd.append('gw6')
|
|
|
|
for key, value in options.items():
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
if value is not None:
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
cmd.extend([key, value])
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def modify_connection_ethernet(self, conn_type='ethernet'):
|
|
|
|
def modify_connection_ethernet(self, conn_type='ethernet'):
|
|
|
@ -921,30 +913,25 @@ class Nmcli(object):
|
|
|
|
# To modify an Ethernet connection with static IP configuration, issue a command as follows
|
|
|
|
# To modify an Ethernet connection with static IP configuration, issue a command as follows
|
|
|
|
# - nmcli: conn_name=my-eth1 ifname=eth1 type=ethernet ip4=192.0.2.100/24 gw4=192.0.2.1 state=present
|
|
|
|
# - nmcli: conn_name=my-eth1 ifname=eth1 type=ethernet ip4=192.0.2.100/24 gw4=192.0.2.1 state=present
|
|
|
|
# nmcli con mod con-name my-eth1 ifname eth1 type ethernet ip4 192.0.2.100/24 gw4 192.0.2.1
|
|
|
|
# nmcli con mod con-name my-eth1 ifname eth1 type ethernet ip4 192.0.2.100/24 gw4 192.0.2.1
|
|
|
|
if self.ip4 is not None:
|
|
|
|
options = {
|
|
|
|
cmd.append('ipv4.address')
|
|
|
|
'ipv4.address': self.ip4,
|
|
|
|
cmd.append(self.ip4)
|
|
|
|
'ipv4.gateway': self.gw4,
|
|
|
|
if self.gw4 is not None:
|
|
|
|
'ipv4.dns': self.dns4,
|
|
|
|
cmd.append('ipv4.gateway')
|
|
|
|
'ipv6.address': self.ip6,
|
|
|
|
cmd.append(self.gw4)
|
|
|
|
'ipv6.gateway': self.gw6,
|
|
|
|
if self.dns4 is not None:
|
|
|
|
'ipv6.dns': self.dns6,
|
|
|
|
cmd.append('ipv4.dns')
|
|
|
|
'autoconnect': self.bool_to_string(self.autoconnect),
|
|
|
|
cmd.append(self.dns4)
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
|
|
|
if self.ip6 is not None:
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
|
|
|
cmd.append('ipv6.address')
|
|
|
|
'802-3-ethernet.mtu': self.mtu,
|
|
|
|
cmd.append(self.ip6)
|
|
|
|
}
|
|
|
|
if self.gw6 is not None:
|
|
|
|
|
|
|
|
cmd.append('ipv6.gateway')
|
|
|
|
for key, value in options.items():
|
|
|
|
cmd.append(self.gw6)
|
|
|
|
if value is not None:
|
|
|
|
if self.dns6 is not None:
|
|
|
|
if key == '802-3-ethernet.mtu' and conn_type != 'ethernet':
|
|
|
|
cmd.append('ipv6.dns')
|
|
|
|
continue
|
|
|
|
cmd.append(self.dns6)
|
|
|
|
cmd.extend([key, value])
|
|
|
|
if self.mtu is not None and conn_type == 'ethernet':
|
|
|
|
|
|
|
|
cmd.append('802-3-ethernet.mtu')
|
|
|
|
|
|
|
|
cmd.append(self.mtu)
|
|
|
|
|
|
|
|
if self.autoconnect is not None:
|
|
|
|
|
|
|
|
cmd.append('autoconnect')
|
|
|
|
|
|
|
|
cmd.append(self.bool_to_string(self.autoconnect))
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
|
|
def create_connection_bridge(self):
|
|
|
|
def create_connection_bridge(self):
|
|
|
@ -970,13 +957,12 @@ class Nmcli(object):
|
|
|
|
def create_connection(self):
|
|
|
|
def create_connection(self):
|
|
|
|
cmd = []
|
|
|
|
cmd = []
|
|
|
|
if self.type == 'team':
|
|
|
|
if self.type == 'team':
|
|
|
|
# cmd=self.create_connection_team()
|
|
|
|
|
|
|
|
if (self.dns4 is not None) or (self.dns6 is not None):
|
|
|
|
if (self.dns4 is not None) or (self.dns6 is not None):
|
|
|
|
cmd = self.create_connection_team()
|
|
|
|
cmd = self.create_connection_team()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.modify_connection_team()
|
|
|
|
cmd = self.modify_connection_team()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.up_connection()
|
|
|
|
return self.up_connection()
|
|
|
|
elif (self.dns4 is None) or (self.dns6 is None):
|
|
|
|
elif (self.dns4 is None) or (self.dns6 is None):
|
|
|
|
cmd = self.create_connection_team()
|
|
|
|
cmd = self.create_connection_team()
|
|
|
|
elif self.type == 'team-slave':
|
|
|
|
elif self.type == 'team-slave':
|
|
|
@ -984,8 +970,7 @@ class Nmcli(object):
|
|
|
|
cmd = self.create_connection_team_slave()
|
|
|
|
cmd = self.create_connection_team_slave()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.modify_connection_team_slave()
|
|
|
|
cmd = self.modify_connection_team_slave()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
# cmd=self.up_connection()
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cmd = self.create_connection_team_slave()
|
|
|
|
cmd = self.create_connection_team_slave()
|
|
|
|
elif self.type == 'bond':
|
|
|
|
elif self.type == 'bond':
|
|
|
@ -994,7 +979,7 @@ class Nmcli(object):
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.modify_connection_bond()
|
|
|
|
cmd = self.modify_connection_bond()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.up_connection()
|
|
|
|
return self.up_connection()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cmd = self.create_connection_bond()
|
|
|
|
cmd = self.create_connection_bond()
|
|
|
|
elif self.type == 'bond-slave':
|
|
|
|
elif self.type == 'bond-slave':
|
|
|
@ -1005,7 +990,7 @@ class Nmcli(object):
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.modify_connection_ethernet()
|
|
|
|
cmd = self.modify_connection_ethernet()
|
|
|
|
self.execute_command(cmd)
|
|
|
|
self.execute_command(cmd)
|
|
|
|
cmd = self.up_connection()
|
|
|
|
return self.up_connection()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cmd = self.create_connection_ethernet()
|
|
|
|
cmd = self.create_connection_ethernet()
|
|
|
|
elif self.type == 'bridge':
|
|
|
|
elif self.type == 'bridge':
|
|
|
@ -1067,9 +1052,11 @@ def main():
|
|
|
|
ip4=dict(required=False, default=None, type='str'),
|
|
|
|
ip4=dict(required=False, default=None, type='str'),
|
|
|
|
gw4=dict(required=False, default=None, type='str'),
|
|
|
|
gw4=dict(required=False, default=None, type='str'),
|
|
|
|
dns4=dict(required=False, default=None, type='list'),
|
|
|
|
dns4=dict(required=False, default=None, type='list'),
|
|
|
|
|
|
|
|
dns4_search=dict(type='list'),
|
|
|
|
ip6=dict(required=False, default=None, type='str'),
|
|
|
|
ip6=dict(required=False, default=None, type='str'),
|
|
|
|
gw6=dict(required=False, default=None, type='str'),
|
|
|
|
gw6=dict(required=False, default=None, type='str'),
|
|
|
|
dns6=dict(required=False, default=None, type='str'),
|
|
|
|
dns6=dict(required=False, default=None, type='str'),
|
|
|
|
|
|
|
|
dns6_search=dict(type='list'),
|
|
|
|
# Bond Specific vars
|
|
|
|
# Bond Specific vars
|
|
|
|
mode=dict(require=False, default="balance-rr", type='str', choices=["balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad",
|
|
|
|
mode=dict(require=False, default="balance-rr", type='str', choices=["balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad",
|
|
|
|
"balance-tlb", "balance-alb"]),
|
|
|
|
"balance-tlb", "balance-alb"]),
|
|
|
|