mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 11:58:43 +00:00
Add networks[].mac_address option. (#763)
This commit is contained in:
parent
37d0a44c0b
commit
fcf608b334
@ -0,0 +1,4 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "docker_container - add ``networks[].mac_address`` option for Docker API 1.44+.
|
||||||
|
Note that Docker API 1.44 no longer uses the global ``mac_address`` option, this new option is the only way to set the MAC address for a container
|
||||||
|
(https://github.com/ansible-collections/community.docker/pull/763)."
|
||||||
@ -177,6 +177,7 @@ class OptionGroup(object):
|
|||||||
class Engine(object):
|
class Engine(object):
|
||||||
min_api_version = None # string or None
|
min_api_version = None # string or None
|
||||||
min_api_version_obj = None # LooseVersion object or None
|
min_api_version_obj = None # LooseVersion object or None
|
||||||
|
extra_option_minimal_versions = None # dict[str, dict[str, Any]] or None
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_value(self, module, container, api_version, options, image, host_info):
|
def get_value(self, module, container, api_version, options, image, host_info):
|
||||||
@ -509,6 +510,8 @@ def _preprocess_networks(module, values):
|
|||||||
parsed_link = (link, link)
|
parsed_link = (link, link)
|
||||||
parsed_links.append(tuple(parsed_link))
|
parsed_links.append(tuple(parsed_link))
|
||||||
network['links'] = parsed_links
|
network['links'] = parsed_links
|
||||||
|
if network['mac_address']:
|
||||||
|
network['mac_address'] = network['mac_address'].replace('-', ':')
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@ -945,7 +948,7 @@ OPTION_HOSTNAME = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
OPTION_IMAGE = (
|
OPTION_IMAGE = (
|
||||||
OptionGroup(preprocess=_preprocess_networks)
|
OptionGroup()
|
||||||
.add_option('image', type='str')
|
.add_option('image', type='str')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1019,6 +1022,7 @@ OPTION_NETWORK = (
|
|||||||
ipv6_address=dict(type='str'),
|
ipv6_address=dict(type='str'),
|
||||||
aliases=dict(type='list', elements='str'),
|
aliases=dict(type='list', elements='str'),
|
||||||
links=dict(type='list', elements='str'),
|
links=dict(type='list', elements='str'),
|
||||||
|
mac_address=dict(type='str'),
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -170,6 +170,8 @@ class DockerAPIEngineDriver(EngineDriver):
|
|||||||
for option in options.options:
|
for option in options.options:
|
||||||
if not option.not_an_ansible_option:
|
if not option.not_an_ansible_option:
|
||||||
option_minimal_versions[option.name] = {'docker_api_version': engine.min_api_version}
|
option_minimal_versions[option.name] = {'docker_api_version': engine.min_api_version}
|
||||||
|
if engine.extra_option_minimal_versions:
|
||||||
|
option_minimal_versions.update(engine.extra_option_minimal_versions)
|
||||||
|
|
||||||
active_options.append(options)
|
active_options.append(options)
|
||||||
|
|
||||||
@ -244,7 +246,13 @@ class DockerAPIEngineDriver(EngineDriver):
|
|||||||
def connect_container_to_network(self, client, container_id, network_id, parameters=None):
|
def connect_container_to_network(self, client, container_id, network_id, parameters=None):
|
||||||
parameters = (parameters or {}).copy()
|
parameters = (parameters or {}).copy()
|
||||||
params = {}
|
params = {}
|
||||||
for para, dest_para in {'ipv4_address': 'IPv4Address', 'ipv6_address': 'IPv6Address', 'links': 'Links', 'aliases': 'Aliases'}.items():
|
for para, dest_para in {
|
||||||
|
'ipv4_address': 'IPv4Address',
|
||||||
|
'ipv6_address': 'IPv6Address',
|
||||||
|
'links': 'Links',
|
||||||
|
'aliases': 'Aliases',
|
||||||
|
'mac_address': 'MacAddress',
|
||||||
|
}.items():
|
||||||
value = parameters.pop(para, None)
|
value = parameters.pop(para, None)
|
||||||
if value:
|
if value:
|
||||||
if para == 'links':
|
if para == 'links':
|
||||||
@ -398,6 +406,7 @@ class DockerAPIEngine(Engine):
|
|||||||
compare_value=None,
|
compare_value=None,
|
||||||
needs_container_image=None,
|
needs_container_image=None,
|
||||||
needs_host_info=None,
|
needs_host_info=None,
|
||||||
|
extra_option_minimal_versions=None,
|
||||||
):
|
):
|
||||||
self.min_api_version = min_api_version
|
self.min_api_version = min_api_version
|
||||||
self.min_api_version_obj = None if min_api_version is None else LooseVersion(min_api_version)
|
self.min_api_version_obj = None if min_api_version is None else LooseVersion(min_api_version)
|
||||||
@ -414,6 +423,7 @@ class DockerAPIEngine(Engine):
|
|||||||
self.needs_host_info = needs_host_info or (lambda values: False)
|
self.needs_host_info = needs_host_info or (lambda values: False)
|
||||||
if compare_value is not None:
|
if compare_value is not None:
|
||||||
self.compare_value = compare_value
|
self.compare_value = compare_value
|
||||||
|
self.extra_option_minimal_versions = extra_option_minimal_versions
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def config_value(
|
def config_value(
|
||||||
@ -1330,6 +1340,12 @@ OPTION_NETWORK.add_engine('docker_api', DockerAPIEngine(
|
|||||||
get_value=_get_values_network,
|
get_value=_get_values_network,
|
||||||
set_value=_set_values_network,
|
set_value=_set_values_network,
|
||||||
ignore_mismatching_result=_ignore_mismatching_network_result,
|
ignore_mismatching_result=_ignore_mismatching_network_result,
|
||||||
|
extra_option_minimal_versions={
|
||||||
|
'networks.mac_address': {
|
||||||
|
'docker_api_version': '1.44',
|
||||||
|
'detect_usage': lambda c: any(net_info.get('mac_address') is not None for net_info in (c.module.params['networks'] or [])),
|
||||||
|
},
|
||||||
|
},
|
||||||
))
|
))
|
||||||
|
|
||||||
OPTION_OOM_KILLER.add_engine('docker_api', DockerAPIEngine.host_config_value('OomKillDisable'))
|
OPTION_OOM_KILLER.add_engine('docker_api', DockerAPIEngine.host_config_value('OomKillDisable'))
|
||||||
|
|||||||
@ -614,6 +614,8 @@ class ContainerManager(DockerBaseClass):
|
|||||||
expected_links.append("%s:%s" % (link, alias))
|
expected_links.append("%s:%s" % (link, alias))
|
||||||
if not compare_generic(expected_links, network_info.get('Links'), 'allow_more_present', 'set'):
|
if not compare_generic(expected_links, network_info.get('Links'), 'allow_more_present', 'set'):
|
||||||
diff = True
|
diff = True
|
||||||
|
if network.get('mac_address') and network['mac_address'] != network_info.get('MacAddress'):
|
||||||
|
diff = True
|
||||||
if diff:
|
if diff:
|
||||||
different = True
|
different = True
|
||||||
differences.append(dict(
|
differences.append(dict(
|
||||||
@ -623,7 +625,8 @@ class ContainerManager(DockerBaseClass):
|
|||||||
ipv4_address=network_info_ipam.get('IPv4Address'),
|
ipv4_address=network_info_ipam.get('IPv4Address'),
|
||||||
ipv6_address=network_info_ipam.get('IPv6Address'),
|
ipv6_address=network_info_ipam.get('IPv6Address'),
|
||||||
aliases=network_info.get('Aliases'),
|
aliases=network_info.get('Aliases'),
|
||||||
links=network_info.get('Links')
|
links=network_info.get('Links'),
|
||||||
|
mac_address=network_info.get('MacAddress'),
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
return different, differences
|
return different, differences
|
||||||
|
|||||||
@ -525,6 +525,7 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Container MAC address (for example, V(92:d0:c6:0a:29:33)).
|
- Container MAC address (for example, V(92:d0:c6:0a:29:33)).
|
||||||
- Note that the global container-wide MAC address is deprecated and no longer used since Docker API version 1.44.
|
- Note that the global container-wide MAC address is deprecated and no longer used since Docker API version 1.44.
|
||||||
|
- Use O(networks[].mac_address) instead.
|
||||||
type: str
|
type: str
|
||||||
memory:
|
memory:
|
||||||
description:
|
description:
|
||||||
@ -690,6 +691,12 @@ options:
|
|||||||
can be used in the network to reach this container.
|
can be used in the network to reach this container.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
mac_address:
|
||||||
|
description:
|
||||||
|
- Endpoint MAC address (for example, V(92:d0:c6:0a:29:33)).
|
||||||
|
- This is only available for Docker API version 1.44 and later.
|
||||||
|
type: str
|
||||||
|
version_added: 3.6.0
|
||||||
networks_cli_compatible:
|
networks_cli_compatible:
|
||||||
description:
|
description:
|
||||||
- "If O(networks_cli_compatible=true) (default), this module will behave as
|
- "If O(networks_cli_compatible=true) (default), this module will behave as
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user