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
This commit is contained in:
parent
ef34e2a1c5
commit
78e5c865f4
@ -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):
|
||||
|
@ -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')}
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user