From ce1afd01e030d9e4e9e07125caebd14c249cb724 Mon Sep 17 00:00:00 2001 From: sebi Date: Thu, 6 Aug 2015 16:46:01 +0300 Subject: [PATCH] mem_limit client version check --- lib/ansible/modules/cloud/docker/docker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index 533ea18ed4..5846ae6466 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -1409,12 +1409,12 @@ class DockerManager(object): mem_limit = _human_to_bytes(self.module.params.get('memory_limit')) except ValueError as e: self.module.fail_json(msg=str(e)) + api_version = self.client.version()['ApiVersion'] params = {'image': self.module.params.get('image'), 'command': self.module.params.get('command'), 'ports': self.exposed_ports, 'volumes': self.volumes, - 'mem_limit': mem_limit, 'environment': self.env, 'hostname': self.module.params.get('hostname'), 'domainname': self.module.params.get('domainname'), @@ -1442,6 +1442,13 @@ class DockerManager(object): if self.ensure_capability('host_config', fail=False): params['host_config'] = self.get_host_config() + #For v1.19 API and above use HostConfig, otherwise use Config + if api_version < 1.19: + params['mem_limit'] = mem_limit + else: + params['host_config']['mem_limit'] = mem_limit + + def do_create(count, params): results = [] for _ in range(count):