mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-03-15 19:58:28 +00:00
docker_container: refactoring preparing better comparisons (#713)
* Always get the container's image as well to allow get_value() to use that one too. * Allow options and engines to overwrite comparison functions. * Do not fail if image (by ID) cannot be found. * Allow to control when container image is needed. * Pass option to compare function. * Allow to pass the host info for retrieving a value. * Add changelog fragment.
This commit is contained in:
parent
b8afdc52b1
commit
d8cef6c71e
@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "docker_container - internal refactorings which allow comparisons to use more information like details of the current image or the Docker host config (https://github.com/ansible-collections/community.docker/pull/713)."
|
||||||
@ -19,6 +19,7 @@ from ansible.module_utils.six import string_types
|
|||||||
|
|
||||||
from ansible_collections.community.docker.plugins.module_utils.util import (
|
from ansible_collections.community.docker.plugins.module_utils.util import (
|
||||||
clean_dict_booleans_for_docker_api,
|
clean_dict_booleans_for_docker_api,
|
||||||
|
compare_generic,
|
||||||
normalize_healthcheck,
|
normalize_healthcheck,
|
||||||
omit_none_from_dict,
|
omit_none_from_dict,
|
||||||
)
|
)
|
||||||
@ -67,6 +68,7 @@ class Option(object):
|
|||||||
not_a_container_option=False,
|
not_a_container_option=False,
|
||||||
not_an_ansible_option=False,
|
not_an_ansible_option=False,
|
||||||
copy_comparison_from=None,
|
copy_comparison_from=None,
|
||||||
|
compare=None,
|
||||||
):
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = type
|
self.type = type
|
||||||
@ -106,6 +108,11 @@ class Option(object):
|
|||||||
self.not_a_container_option = not_a_container_option
|
self.not_a_container_option = not_a_container_option
|
||||||
self.not_an_ansible_option = not_an_ansible_option
|
self.not_an_ansible_option = not_an_ansible_option
|
||||||
self.copy_comparison_from = copy_comparison_from
|
self.copy_comparison_from = copy_comparison_from
|
||||||
|
self.compare = (
|
||||||
|
lambda param_value, container_value: compare(self, param_value, container_value)
|
||||||
|
) if compare else (
|
||||||
|
lambda param_value, container_value: compare_generic(param_value, container_value, self.comparison, self.comparison_type)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OptionGroup(object):
|
class OptionGroup(object):
|
||||||
@ -168,15 +175,18 @@ class Engine(object):
|
|||||||
min_api_version_obj = None # LooseVersion object or None
|
min_api_version_obj = None # LooseVersion object or None
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_value(self, module, container, api_version, options):
|
def get_value(self, module, container, api_version, options, image, host_info):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def compare_value(self, option, param_value, container_value):
|
||||||
|
return option.compare(param_value, container_value)
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def set_value(self, module, data, api_version, options, values):
|
def set_value(self, module, data, api_version, options, values):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_expected_values(self, module, client, api_version, options, image, values):
|
def get_expected_values(self, module, client, api_version, options, image, values, host_info):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@ -199,6 +209,14 @@ class Engine(object):
|
|||||||
def can_update_value(self, api_version):
|
def can_update_value(self, api_version):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def needs_container_image(self, values):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def needs_host_info(self, values):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class EngineDriver(object):
|
class EngineDriver(object):
|
||||||
name = None # string
|
name = None # string
|
||||||
@ -208,6 +226,10 @@ class EngineDriver(object):
|
|||||||
# Return (module, active_options, client)
|
# Return (module, active_options, client)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_host_info(self, client):
|
||||||
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_api_version(self, client):
|
def get_api_version(self, client):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -181,6 +181,9 @@ class DockerAPIEngineDriver(EngineDriver):
|
|||||||
|
|
||||||
return client.module, active_options, client
|
return client.module, active_options, client
|
||||||
|
|
||||||
|
def get_host_info(self, client):
|
||||||
|
return client.info()
|
||||||
|
|
||||||
def get_api_version(self, client):
|
def get_api_version(self, client):
|
||||||
return client.docker_api_version
|
return client.docker_api_version
|
||||||
|
|
||||||
@ -216,7 +219,7 @@ class DockerAPIEngineDriver(EngineDriver):
|
|||||||
return client.get_container_by_id(container_id)
|
return client.get_container_by_id(container_id)
|
||||||
|
|
||||||
def inspect_image_by_id(self, client, image_id):
|
def inspect_image_by_id(self, client, image_id):
|
||||||
return client.find_image_by_id(image_id)
|
return client.find_image_by_id(image_id, accept_missing_image=True)
|
||||||
|
|
||||||
def inspect_image_by_name(self, client, repository, tag):
|
def inspect_image_by_name(self, client, repository, tag):
|
||||||
return client.find_image(repository, tag)
|
return client.find_image(repository, tag)
|
||||||
@ -387,18 +390,25 @@ class DockerAPIEngine(Engine):
|
|||||||
can_set_value=None,
|
can_set_value=None,
|
||||||
can_update_value=None,
|
can_update_value=None,
|
||||||
min_api_version=None,
|
min_api_version=None,
|
||||||
|
compare_value=None,
|
||||||
|
needs_container_image=None,
|
||||||
|
needs_host_info=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)
|
||||||
self.get_value = get_value
|
self.get_value = get_value
|
||||||
self.set_value = set_value
|
self.set_value = set_value
|
||||||
self.get_expected_values = get_expected_values or (lambda module, client, api_version, options, image, values: values)
|
self.get_expected_values = get_expected_values or (lambda module, client, api_version, options, image, values, host_info: values)
|
||||||
self.ignore_mismatching_result = ignore_mismatching_result or \
|
self.ignore_mismatching_result = ignore_mismatching_result or \
|
||||||
(lambda module, client, api_version, option, image, container_value, expected_value: False)
|
(lambda module, client, api_version, option, image, container_value, expected_value: False)
|
||||||
self.preprocess_value = preprocess_value or (lambda module, client, api_version, options, values: values)
|
self.preprocess_value = preprocess_value or (lambda module, client, api_version, options, values: values)
|
||||||
self.update_value = update_value
|
self.update_value = update_value
|
||||||
self.can_set_value = can_set_value or (lambda api_version: set_value is not None)
|
self.can_set_value = can_set_value or (lambda api_version: set_value is not None)
|
||||||
self.can_update_value = can_update_value or (lambda api_version: update_value is not None)
|
self.can_update_value = can_update_value or (lambda api_version: update_value is not None)
|
||||||
|
self.needs_container_image = needs_container_image or (lambda values: False)
|
||||||
|
self.needs_host_info = needs_host_info or (lambda values: False)
|
||||||
|
if compare_value is not None:
|
||||||
|
self.compare_value = compare_value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def config_value(
|
def config_value(
|
||||||
@ -423,7 +433,7 @@ class DockerAPIEngine(Engine):
|
|||||||
values[options[0].name] = value
|
values[options[0].name] = value
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def get_value(module, container, api_version, options):
|
def get_value(module, container, api_version, options, image, host_info):
|
||||||
if len(options) != 1:
|
if len(options) != 1:
|
||||||
raise AssertionError('config_value can only be used for a single option')
|
raise AssertionError('config_value can only be used for a single option')
|
||||||
value = container['Config'].get(config_name, _SENTRY)
|
value = container['Config'].get(config_name, _SENTRY)
|
||||||
@ -435,7 +445,7 @@ class DockerAPIEngine(Engine):
|
|||||||
|
|
||||||
get_expected_values_ = None
|
get_expected_values_ = None
|
||||||
if get_expected_value:
|
if get_expected_value:
|
||||||
def get_expected_values_(module, client, api_version, options, image, values):
|
def get_expected_values_(module, client, api_version, options, image, values, host_info):
|
||||||
if len(options) != 1:
|
if len(options) != 1:
|
||||||
raise AssertionError('host_config_value can only be used for a single option')
|
raise AssertionError('host_config_value can only be used for a single option')
|
||||||
value = values.get(options[0].name, _SENTRY)
|
value = values.get(options[0].name, _SENTRY)
|
||||||
@ -499,7 +509,7 @@ class DockerAPIEngine(Engine):
|
|||||||
values[options[0].name] = value
|
values[options[0].name] = value
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def get_value(module, container, api_version, options):
|
def get_value(module, container, api_version, options, get_value, host_info):
|
||||||
if len(options) != 1:
|
if len(options) != 1:
|
||||||
raise AssertionError('host_config_value can only be used for a single option')
|
raise AssertionError('host_config_value can only be used for a single option')
|
||||||
value = container['HostConfig'].get(host_config_name, _SENTRY)
|
value = container['HostConfig'].get(host_config_name, _SENTRY)
|
||||||
@ -511,7 +521,7 @@ class DockerAPIEngine(Engine):
|
|||||||
|
|
||||||
get_expected_values_ = None
|
get_expected_values_ = None
|
||||||
if get_expected_value:
|
if get_expected_value:
|
||||||
def get_expected_values_(module, client, api_version, options, image, values):
|
def get_expected_values_(module, client, api_version, options, image, values, host_info):
|
||||||
if len(options) != 1:
|
if len(options) != 1:
|
||||||
raise AssertionError('host_config_value can only be used for a single option')
|
raise AssertionError('host_config_value can only be used for a single option')
|
||||||
value = values.get(options[0].name, _SENTRY)
|
value = values.get(options[0].name, _SENTRY)
|
||||||
@ -585,7 +595,7 @@ def _get_default_host_ip(module, client):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
def _get_value_detach_interactive(module, container, api_version, options):
|
def _get_value_detach_interactive(module, container, api_version, options, image, host_info):
|
||||||
attach_stdin = container['Config'].get('OpenStdin')
|
attach_stdin = container['Config'].get('OpenStdin')
|
||||||
attach_stderr = container['Config'].get('AttachStderr')
|
attach_stderr = container['Config'].get('AttachStderr')
|
||||||
attach_stdout = container['Config'].get('AttachStdout')
|
attach_stdout = container['Config'].get('AttachStdout')
|
||||||
@ -836,7 +846,7 @@ def _get_network_id(module, client, network_name):
|
|||||||
client.fail("Error getting network id for %s - %s" % (network_name, to_native(exc)))
|
client.fail("Error getting network id for %s - %s" % (network_name, to_native(exc)))
|
||||||
|
|
||||||
|
|
||||||
def _get_values_network(module, container, api_version, options):
|
def _get_values_network(module, container, api_version, options, image, host_info):
|
||||||
value = container['HostConfig'].get('NetworkMode', _SENTRY)
|
value = container['HostConfig'].get('NetworkMode', _SENTRY)
|
||||||
if value is _SENTRY:
|
if value is _SENTRY:
|
||||||
return {}
|
return {}
|
||||||
@ -852,7 +862,7 @@ def _set_values_network(module, data, api_version, options, values):
|
|||||||
data['HostConfig']['NetworkMode'] = value
|
data['HostConfig']['NetworkMode'] = value
|
||||||
|
|
||||||
|
|
||||||
def _get_values_mounts(module, container, api_version, options):
|
def _get_values_mounts(module, container, api_version, options, image, host_info):
|
||||||
volumes = container['Config'].get('Volumes')
|
volumes = container['Config'].get('Volumes')
|
||||||
binds = container['HostConfig'].get('Binds')
|
binds = container['HostConfig'].get('Binds')
|
||||||
# According to https://github.com/moby/moby/, support for HostConfig.Mounts
|
# According to https://github.com/moby/moby/, support for HostConfig.Mounts
|
||||||
@ -916,7 +926,7 @@ def _get_image_binds(volumes):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def _get_expected_values_mounts(module, client, api_version, options, image, values):
|
def _get_expected_values_mounts(module, client, api_version, options, image, values, host_info):
|
||||||
expected_values = {}
|
expected_values = {}
|
||||||
|
|
||||||
# binds
|
# binds
|
||||||
@ -1017,7 +1027,7 @@ def _set_values_mounts(module, data, api_version, options, values):
|
|||||||
data['HostConfig']['Binds'] = values['volume_binds']
|
data['HostConfig']['Binds'] = values['volume_binds']
|
||||||
|
|
||||||
|
|
||||||
def _get_values_log(module, container, api_version, options):
|
def _get_values_log(module, container, api_version, options, image, host_info):
|
||||||
log_config = container['HostConfig'].get('LogConfig') or {}
|
log_config = container['HostConfig'].get('LogConfig') or {}
|
||||||
return {
|
return {
|
||||||
'log_driver': log_config.get('Type'),
|
'log_driver': log_config.get('Type'),
|
||||||
@ -1037,7 +1047,7 @@ def _set_values_log(module, data, api_version, options, values):
|
|||||||
data['HostConfig']['LogConfig'] = log_config
|
data['HostConfig']['LogConfig'] = log_config
|
||||||
|
|
||||||
|
|
||||||
def _get_values_platform(module, container, api_version, options):
|
def _get_values_platform(module, container, api_version, options, image, host_info):
|
||||||
return {
|
return {
|
||||||
'platform': container.get('Platform'),
|
'platform': container.get('Platform'),
|
||||||
}
|
}
|
||||||
@ -1048,7 +1058,7 @@ def _set_values_platform(module, data, api_version, options, values):
|
|||||||
data['platform'] = values['platform']
|
data['platform'] = values['platform']
|
||||||
|
|
||||||
|
|
||||||
def _get_values_restart(module, container, api_version, options):
|
def _get_values_restart(module, container, api_version, options, image, host_info):
|
||||||
restart_policy = container['HostConfig'].get('RestartPolicy') or {}
|
restart_policy = container['HostConfig'].get('RestartPolicy') or {}
|
||||||
return {
|
return {
|
||||||
'restart_policy': restart_policy.get('Name'),
|
'restart_policy': restart_policy.get('Name'),
|
||||||
@ -1077,7 +1087,7 @@ def _update_value_restart(module, data, api_version, options, values):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_values_ports(module, container, api_version, options):
|
def _get_values_ports(module, container, api_version, options, image, host_info):
|
||||||
host_config = container['HostConfig']
|
host_config = container['HostConfig']
|
||||||
config = container['Config']
|
config = container['Config']
|
||||||
|
|
||||||
@ -1094,7 +1104,7 @@ def _get_values_ports(module, container, api_version, options):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_expected_values_ports(module, client, api_version, options, image, values):
|
def _get_expected_values_ports(module, client, api_version, options, image, values, host_info):
|
||||||
expected_values = {}
|
expected_values = {}
|
||||||
|
|
||||||
if 'published_ports' in values:
|
if 'published_ports' in values:
|
||||||
|
|||||||
@ -268,6 +268,20 @@ class ContainerManager(DockerBaseClass):
|
|||||||
parameters.append((options, values))
|
parameters.append((options, values))
|
||||||
return parameters
|
return parameters
|
||||||
|
|
||||||
|
def _needs_container_image(self):
|
||||||
|
for options, values in self.parameters:
|
||||||
|
engine = options.get_engine(self.engine_driver.name)
|
||||||
|
if engine.needs_container_image(values):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _needs_host_info(self):
|
||||||
|
for options, values in self.parameters:
|
||||||
|
engine = options.get_engine(self.engine_driver.name)
|
||||||
|
if engine.needs_host_info(values):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def present(self, state):
|
def present(self, state):
|
||||||
self.parameters = self._collect_params(self.options)
|
self.parameters = self._collect_params(self.options)
|
||||||
container = self._get_container(self.param_name)
|
container = self._get_container(self.param_name)
|
||||||
@ -280,8 +294,10 @@ class ContainerManager(DockerBaseClass):
|
|||||||
# the container already runs or not; in the former case, in case the
|
# the container already runs or not; in the former case, in case the
|
||||||
# container needs to be restarted, we use the existing container's
|
# container needs to be restarted, we use the existing container's
|
||||||
# image ID.
|
# image ID.
|
||||||
image, comparison_image = self._get_image(container)
|
image, container_image, comparison_image = self._get_image(
|
||||||
|
container, needs_container_image=self._needs_container_image())
|
||||||
self.log(image, pretty_print=True)
|
self.log(image, pretty_print=True)
|
||||||
|
host_info = self.engine_driver.get_host_info(self.client) if self._needs_host_info() else None
|
||||||
if not container.exists or container.removing:
|
if not container.exists or container.removing:
|
||||||
# New container
|
# New container
|
||||||
if container.removing:
|
if container.removing:
|
||||||
@ -301,7 +317,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
container_created = True
|
container_created = True
|
||||||
else:
|
else:
|
||||||
# Existing container
|
# Existing container
|
||||||
different, differences = self.has_different_configuration(container, comparison_image)
|
different, differences = self.has_different_configuration(container, container_image, comparison_image, host_info)
|
||||||
image_different = False
|
image_different = False
|
||||||
if self.all_options['image'].comparison == 'strict':
|
if self.all_options['image'].comparison == 'strict':
|
||||||
image_different = self._image_is_different(image, container)
|
image_different = self._image_is_different(image, container)
|
||||||
@ -333,7 +349,7 @@ class ContainerManager(DockerBaseClass):
|
|||||||
comparison_image = image
|
comparison_image = image
|
||||||
|
|
||||||
if container and container.exists:
|
if container and container.exists:
|
||||||
container = self.update_limits(container, comparison_image)
|
container = self.update_limits(container, container_image, comparison_image, host_info)
|
||||||
container = self.update_networks(container, container_created)
|
container = self.update_networks(container, container_created)
|
||||||
|
|
||||||
if state == 'started' and not container.running:
|
if state == 'started' and not container.running:
|
||||||
@ -398,13 +414,20 @@ class ContainerManager(DockerBaseClass):
|
|||||||
image = self.engine_driver.inspect_image_by_name(self.client, repository, tag)
|
image = self.engine_driver.inspect_image_by_name(self.client, repository, tag)
|
||||||
return image or fallback
|
return image or fallback
|
||||||
|
|
||||||
def _get_image(self, container):
|
def _get_image(self, container, needs_container_image=False):
|
||||||
image_parameter = self.param_image
|
image_parameter = self.param_image
|
||||||
|
get_container_image = needs_container_image or not image_parameter
|
||||||
|
container_image = self._get_container_image(container) if get_container_image else None
|
||||||
|
if container_image:
|
||||||
|
self.log("current image")
|
||||||
|
self.log(container_image, pretty_print=True)
|
||||||
if not image_parameter:
|
if not image_parameter:
|
||||||
self.log('No image specified')
|
self.log('No image specified')
|
||||||
return None, self._get_container_image(container)
|
return None, container_image, container_image
|
||||||
if is_image_name_id(image_parameter):
|
if is_image_name_id(image_parameter):
|
||||||
image = self.engine_driver.inspect_image_by_id(self.client, image_parameter)
|
image = self.engine_driver.inspect_image_by_id(self.client, image_parameter)
|
||||||
|
if image is None:
|
||||||
|
self.client.fail("Cannot find image with ID %s" % (image_parameter, ))
|
||||||
else:
|
else:
|
||||||
repository, tag = parse_repository_tag(image_parameter)
|
repository, tag = parse_repository_tag(image_parameter)
|
||||||
if not tag:
|
if not tag:
|
||||||
@ -431,12 +454,11 @@ class ContainerManager(DockerBaseClass):
|
|||||||
|
|
||||||
comparison_image = image
|
comparison_image = image
|
||||||
if self.param_image_comparison == 'current-image':
|
if self.param_image_comparison == 'current-image':
|
||||||
comparison_image = self._get_container_image(container, image)
|
if not get_container_image:
|
||||||
if comparison_image != image:
|
container_image = self._get_container_image(container)
|
||||||
self.log("current image")
|
comparison_image = container_image
|
||||||
self.log(comparison_image, pretty_print=True)
|
|
||||||
|
|
||||||
return image, comparison_image
|
return image, container_image, comparison_image
|
||||||
|
|
||||||
def _image_is_different(self, image, container):
|
def _image_is_different(self, image, container):
|
||||||
if image and image.get('Id'):
|
if image and image.get('Id'):
|
||||||
@ -455,15 +477,16 @@ class ContainerManager(DockerBaseClass):
|
|||||||
params['Image'] = image
|
params['Image'] = image
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def _record_differences(self, differences, options, param_values, engine, container, image):
|
def _record_differences(self, differences, options, param_values, engine, container, container_image, image, host_info):
|
||||||
container_values = engine.get_value(self.module, container.raw, self.engine_driver.get_api_version(self.client), options.options)
|
container_values = engine.get_value(
|
||||||
|
self.module, container.raw, self.engine_driver.get_api_version(self.client), options.options, container_image, host_info)
|
||||||
expected_values = engine.get_expected_values(
|
expected_values = engine.get_expected_values(
|
||||||
self.module, self.client, self.engine_driver.get_api_version(self.client), options.options, image, param_values.copy())
|
self.module, self.client, self.engine_driver.get_api_version(self.client), options.options, image, param_values.copy(), host_info)
|
||||||
for option in options.options:
|
for option in options.options:
|
||||||
if option.name in expected_values:
|
if option.name in expected_values:
|
||||||
param_value = expected_values[option.name]
|
param_value = expected_values[option.name]
|
||||||
container_value = container_values.get(option.name)
|
container_value = container_values.get(option.name)
|
||||||
match = compare_generic(param_value, container_value, option.comparison, option.comparison_type)
|
match = engine.compare_value(option, param_value, container_value)
|
||||||
|
|
||||||
if not match:
|
if not match:
|
||||||
# No match.
|
# No match.
|
||||||
@ -497,28 +520,28 @@ class ContainerManager(DockerBaseClass):
|
|||||||
c = sorted(c, key=sort_key_fn)
|
c = sorted(c, key=sort_key_fn)
|
||||||
differences.add(option.name, parameter=p, active=c)
|
differences.add(option.name, parameter=p, active=c)
|
||||||
|
|
||||||
def has_different_configuration(self, container, image):
|
def has_different_configuration(self, container, container_image, image, host_info):
|
||||||
differences = DifferenceTracker()
|
differences = DifferenceTracker()
|
||||||
update_differences = DifferenceTracker()
|
update_differences = DifferenceTracker()
|
||||||
for options, param_values in self.parameters:
|
for options, param_values in self.parameters:
|
||||||
engine = options.get_engine(self.engine_driver.name)
|
engine = options.get_engine(self.engine_driver.name)
|
||||||
if engine.can_update_value(self.engine_driver.get_api_version(self.client)):
|
if engine.can_update_value(self.engine_driver.get_api_version(self.client)):
|
||||||
self._record_differences(update_differences, options, param_values, engine, container, image)
|
self._record_differences(update_differences, options, param_values, engine, container, container_image, image, host_info)
|
||||||
else:
|
else:
|
||||||
self._record_differences(differences, options, param_values, engine, container, image)
|
self._record_differences(differences, options, param_values, engine, container, container_image, image, host_info)
|
||||||
has_differences = not differences.empty
|
has_differences = not differences.empty
|
||||||
# Only consider differences of properties that can be updated when there are also other differences
|
# Only consider differences of properties that can be updated when there are also other differences
|
||||||
if has_differences:
|
if has_differences:
|
||||||
differences.merge(update_differences)
|
differences.merge(update_differences)
|
||||||
return has_differences, differences
|
return has_differences, differences
|
||||||
|
|
||||||
def has_different_resource_limits(self, container, image):
|
def has_different_resource_limits(self, container, container_image, image, host_info):
|
||||||
differences = DifferenceTracker()
|
differences = DifferenceTracker()
|
||||||
for options, param_values in self.parameters:
|
for options, param_values in self.parameters:
|
||||||
engine = options.get_engine(self.engine_driver.name)
|
engine = options.get_engine(self.engine_driver.name)
|
||||||
if not engine.can_update_value(self.engine_driver.get_api_version(self.client)):
|
if not engine.can_update_value(self.engine_driver.get_api_version(self.client)):
|
||||||
continue
|
continue
|
||||||
self._record_differences(differences, options, param_values, engine, container, image)
|
self._record_differences(differences, options, param_values, engine, container, container_image, image, host_info)
|
||||||
has_differences = not differences.empty
|
has_differences = not differences.empty
|
||||||
return has_differences, differences
|
return has_differences, differences
|
||||||
|
|
||||||
@ -531,8 +554,8 @@ class ContainerManager(DockerBaseClass):
|
|||||||
engine.update_value(self.module, result, self.engine_driver.get_api_version(self.client), options.options, values)
|
engine.update_value(self.module, result, self.engine_driver.get_api_version(self.client), options.options, values)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update_limits(self, container, image):
|
def update_limits(self, container, container_image, image, host_info):
|
||||||
limits_differ, different_limits = self.has_different_resource_limits(container, image)
|
limits_differ, different_limits = self.has_different_resource_limits(container, container_image, image, host_info)
|
||||||
if limits_differ:
|
if limits_differ:
|
||||||
self.log("limit differences:")
|
self.log("limit differences:")
|
||||||
self.log(different_limits.get_legacy_docker_container_diffs(), pretty_print=True)
|
self.log(different_limits.get_legacy_docker_container_diffs(), pretty_print=True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user