From b0b1566b8934988c5ba725f34a8744c2092c765a Mon Sep 17 00:00:00 2001 From: Micheal Waltz Date: Tue, 21 Jul 2015 12:58:58 -0700 Subject: [PATCH 1/3] Use proper HostConfig element which contians the proper Memory value - fixes #1766 --- cloud/docker/docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index e77951abf49..f8532659ecf 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -1008,7 +1008,7 @@ class DockerManager(object): except ValueError as e: self.module.fail_json(msg=str(e)) - actual_mem = container['Config']['Memory'] + actual_mem = container['HostConfig']['Memory'] if expected_mem and actual_mem != expected_mem: self.reload_reasons.append('memory ({0} => {1})'.format(actual_mem, expected_mem)) From 77d1c896fea212f0421c7cae6f2e56e9f7befc82 Mon Sep 17 00:00:00 2001 From: Micheal Waltz Date: Thu, 23 Jul 2015 11:34:33 -0700 Subject: [PATCH 2/3] Set the API version when checking differences in containers and use this to determine the location of the Memory value depending on the version used. In v1.18 and earlier it was ['Config']['Memory'], but in v1.19 it changed to ['HostConfig']['Memory']. --- cloud/docker/docker.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index f8532659ecf..8055fbf23c9 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -942,6 +942,9 @@ class DockerManager(object): running = self.get_running_containers() current = self.get_inspect_containers(running) + #Get API version + api_version = self.client.version()['ApiVersion'] + image = self.get_inspect_image() if image is None: # The image isn't present. Assume that we're about to pull a new @@ -1010,6 +1013,10 @@ class DockerManager(object): actual_mem = container['HostConfig']['Memory'] + #Use v1.18 API and earlier Memory element location + if docker_api_version <= 1.18: + actual_mem = container['Config']['Memory'] + if expected_mem and actual_mem != expected_mem: self.reload_reasons.append('memory ({0} => {1})'.format(actual_mem, expected_mem)) differing.append(container) From 613fe54908eb406ca942e15aa340259fdd6f0837 Mon Sep 17 00:00:00 2001 From: Micheal Waltz Date: Thu, 23 Jul 2015 12:17:26 -0700 Subject: [PATCH 3/3] Use a if/else instead to avoid loading possibly invalid values for Memory --- cloud/docker/docker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py index 8055fbf23c9..df7eb141aec 100644 --- a/cloud/docker/docker.py +++ b/cloud/docker/docker.py @@ -1011,10 +1011,10 @@ class DockerManager(object): except ValueError as e: self.module.fail_json(msg=str(e)) - actual_mem = container['HostConfig']['Memory'] - - #Use v1.18 API and earlier Memory element location - if docker_api_version <= 1.18: + #For v1.19 API and above use HostConfig, otherwise use Config + if docker_api_version >= 1.19: + actual_mem = container['HostConfig']['Memory'] + else: actual_mem = container['Config']['Memory'] if expected_mem and actual_mem != expected_mem: