From 78e5c865f4bf38c7227731ac39e679f1efed1e5a Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Tue, 28 Feb 2017 14:10:59 +0800 Subject: [PATCH] Fix the incompatible of docker-py 2.0.0 docker-py 2.0.0 is released with renaming docker.Client to docker.APIClient. and with a new python package name "docker" rather than "docker-py". This patch support docker and docker-py packages. Change-Id: Ib4400a4d2ce803191ee6215c5b28f0052970332c Closes-Bug: #1668346 --- ansible/library/kolla_container_facts.py | 9 ++++++++- ansible/library/kolla_docker.py | 9 ++++++++- ansible/library/kolla_toolbox.py | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ansible/library/kolla_container_facts.py b/ansible/library/kolla_container_facts.py index a2c73009d7..dcdd931e94 100644 --- a/ansible/library/kolla_container_facts.py +++ b/ansible/library/kolla_container_facts.py @@ -52,6 +52,13 @@ EXAMPLES = ''' import docker +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + def main(): argument_spec = dict( name=dict(required=False, type='list', default=[]), @@ -61,7 +68,7 @@ def main(): module = AnsibleModule(argument_spec=argument_spec) results = dict(changed=False, _containers=[]) - client = docker.Client(version=module.params.get('api_version')) + client = get_docker_client()(version=module.params.get('api_version')) containers = client.containers() names = module.params.get('name') if names and not isinstance(names, list): diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index e41c9b740c..539242676a 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -197,6 +197,13 @@ import traceback import docker +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + class DockerWorker(object): def __init__(self, module): @@ -211,7 +218,7 @@ class DockerWorker(object): 'version': self.params.get('api_version') } - self.dc = docker.Client(**options) + self.dc = get_docker_client()(**options) def generate_tls(self): tls = {'verify': self.params.get('tls_verify')} diff --git a/ansible/library/kolla_toolbox.py b/ansible/library/kolla_toolbox.py index 458665f35a..8725434008 100644 --- a/ansible/library/kolla_toolbox.py +++ b/ansible/library/kolla_toolbox.py @@ -102,6 +102,13 @@ def gen_commandline(params): return command +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + def main(): specs = dict( module_name=dict(type='str'), @@ -109,7 +116,7 @@ def main(): module_extra_vars=dict(type='json') ) module = AnsibleModule(argument_spec=specs, bypass_checks=True) - client = docker.Client() + client = get_docker_client()() command_line = gen_commandline(module.params) kolla_toolbox = client.containers(filters=dict(name='kolla_toolbox', status='running'))