diff --git a/library/network_connections.py b/library/network_connections.py index 2bd952e..123251c 100755 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -591,6 +591,10 @@ class ArgValidator_DictIP(ArgValidatorDict): nested = ArgValidatorIP('dns[?]'), default_value = list, ), + ArgValidatorList('dns_search', + nested = ArgValidatorStr('dns_search[?]', allow_empty = False), + default_value = list, + ), ], default_value = lambda: { 'ip_is_present': False, @@ -603,6 +607,7 @@ class ArgValidator_DictIP(ArgValidatorDict): 'route_metric6': None, 'address': [], 'dns': [], + 'dns_search': [], }, all_missing_during_validate = False, ) @@ -956,6 +961,8 @@ class IfcfgUtil: for idx, dns in enumerate(ip['dns']): ifcfg['DNS' + str(idx+1)] = dns['address'] + if ip['dns_search']: + ifcfg['DOMAIN'] = ' '.join(ip['dns_search']) if ip['auto6']: ifcfg['IPV6INIT'] = 'yes' @@ -1232,6 +1239,8 @@ class NMUtil: for d in ip['dns']: if d['is_v4']: s_ip4.add_dns(d['address']) + for s in ip['dns_search']: + s_ip4.add_dns_search(s) if ip['auto6']: s_ip6.set_property(NM.SETTING_IP_CONFIG_METHOD, 'auto') diff --git a/library/test_network_connections.py b/library/test_network_connections.py index b8fa7d8..5a8029c 100755 --- a/library/test_network_connections.py +++ b/library/test_network_connections.py @@ -127,6 +127,7 @@ class TestValidator(unittest.TestCase): 'ip_is_present': False, 'dhcp4_send_hostname': None, 'dns': [], + 'dns_search': [], }, 'mac': None, 'master': None, @@ -166,6 +167,7 @@ class TestValidator(unittest.TestCase): 'dhcp4': True, 'address': [], 'dns': [], + 'dns_search': [], 'route_metric6': None, 'ip_is_present': False, 'dhcp4_send_hostname': None, @@ -228,6 +230,7 @@ class TestValidator(unittest.TestCase): 'route_metric4': None, 'route_metric6': None, 'dns': [], + 'dns_search': [], }, 'mac': 'aa:bb:cc', 'master': None, @@ -250,6 +253,49 @@ class TestValidator(unittest.TestCase): ]), ) + self.assertEqual( + [ + { + 'name': '5', + 'state': 'up', + 'type': 'ethernet', + 'autoconnect': True, + 'parent': None, + 'ip': { + 'gateway6': None, + 'gateway4': None, + 'route_metric4': None, + 'auto6': False, + 'dhcp4': True, + 'address': [], + 'dns': [], + 'dns_search': [ 'aa', 'bb' ], + 'route_metric6': None, + 'ip_is_present': True, + 'dhcp4_send_hostname': False, + }, + 'mac': None, + 'master': None, + 'vlan_id': None, + 'ignore_errors': None, + 'interface_name': None, + 'check_iface_exists': True, + 'slave_type': None, + 'wait': 90, + }, + ], + n.AnsibleUtil.ARGS_CONNECTIONS.validate([ + { 'name': '5', + 'state': 'up', + 'type': 'ethernet', + 'ip': { + 'dns_search': [ 'aa', 'bb' ], + }, + }, + ]), + ) + + with self.assertRaises(n.ValidationError): n.AnsibleUtil.ARGS_CONNECTIONS.validate([ { 'name': 'b', 'type': 'ethernet', 'mac': 'aa:b' } ])