Merge "Fix the incompatible of docker-py 2.0.0"

This commit is contained in:
Jenkins 2017-03-09 17:34:43 +00:00 committed by Gerrit Code Review
commit 60379615f3
3 changed files with 24 additions and 3 deletions

View File

@ -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):

View File

@ -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')}

View File

@ -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'))