Switch StrictVersion for LooseVersion since some distros ship beta versions and StrictVersion would fail on that.
Also clean up some minor style things
This commit is contained in:
parent
c048990419
commit
d6db0f3981
1 changed files with 13 additions and 11 deletions
|
@ -102,24 +102,25 @@ import os.path
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import docker.client
|
import docker.client
|
||||||
from docker.errors import APIError as DockerAPIError
|
from docker.errors import APIError as DockerAPIError
|
||||||
has_lib_docker = True
|
has_lib_docker = True
|
||||||
if StrictVersion(docker.__version__) >= StrictVersion("1.1.0"):
|
if LooseVersion(docker.__version__) >= LooseVersion("1.1.0"):
|
||||||
has_correct_lib_docker_version = True
|
has_correct_lib_docker_version = True
|
||||||
else:
|
else:
|
||||||
has_correct_lib_docker_version = False
|
has_correct_lib_docker_version = False
|
||||||
except ImportError, e:
|
except ImportError:
|
||||||
has_lib_docker = False
|
has_lib_docker = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from requests.exceptions import *
|
import requests
|
||||||
has_lib_requests_execeptions = True
|
has_lib_requests = True
|
||||||
except ImportError, e:
|
except ImportError:
|
||||||
has_lib_requests_execeptions = False
|
has_lib_requests = False
|
||||||
|
|
||||||
|
|
||||||
class DockerLoginManager:
|
class DockerLoginManager:
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ class DockerLoginManager:
|
||||||
self.module.fail_json(msg="failed to login to the remote registry", error=repr(e))
|
self.module.fail_json(msg="failed to login to the remote registry", error=repr(e))
|
||||||
|
|
||||||
# Get status from registry response.
|
# Get status from registry response.
|
||||||
if self.response.has_key("Status"):
|
if "Status" in self.response:
|
||||||
self.log.append(self.response["Status"])
|
self.log.append(self.response["Status"])
|
||||||
|
|
||||||
# Update the dockercfg if not in check mode.
|
# Update the dockercfg if not in check mode.
|
||||||
|
@ -186,9 +187,9 @@ class DockerLoginManager:
|
||||||
docker_config = json.load(open(self.dockercfg_path, "r"))
|
docker_config = json.load(open(self.dockercfg_path, "r"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
docker_config = dict()
|
docker_config = dict()
|
||||||
if not docker_config.has_key("auths"):
|
if "auths" not in docker_config:
|
||||||
docker_config["auths"] = dict()
|
docker_config["auths"] = dict()
|
||||||
if not docker_config["auths"].has_key(self.registry):
|
if self.registry not in docker_config["auths"]:
|
||||||
docker_config["auths"][self.registry] = dict()
|
docker_config["auths"][self.registry] = dict()
|
||||||
|
|
||||||
# Calculate docker credentials based on current parameters.
|
# Calculate docker credentials based on current parameters.
|
||||||
|
@ -219,6 +220,7 @@ class DockerLoginManager:
|
||||||
def has_changed(self):
|
def has_changed(self):
|
||||||
return self.changed
|
return self.changed
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -241,7 +243,7 @@ def main():
|
||||||
if not has_correct_lib_docker_version:
|
if not has_correct_lib_docker_version:
|
||||||
module.fail_json(msg="your version of docker-py is outdated: pip install docker-py>=1.1.0")
|
module.fail_json(msg="your version of docker-py is outdated: pip install docker-py>=1.1.0")
|
||||||
|
|
||||||
if not has_lib_requests_execeptions:
|
if not has_lib_requests:
|
||||||
module.fail_json(msg="python library requests required: pip install requests")
|
module.fail_json(msg="python library requests required: pip install requests")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue