-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker_* modules: unify docker module version checks #47046
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,8 @@ def log(self, msg, pretty_print=False): | |
class AnsibleDockerClient(Client): | ||
|
||
def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclusive=None, | ||
required_together=None, required_if=None): | ||
required_together=None, required_if=None, min_docker_version=MIN_DOCKER_VERSION, | ||
min_docker_api_version=None): | ||
|
||
merged_arg_spec = dict() | ||
merged_arg_spec.update(DOCKER_COMMON_ARGS) | ||
|
@@ -182,18 +183,33 @@ def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclu | |
required_together=required_together_params, | ||
required_if=required_if) | ||
|
||
NEEDS_DOCKER_PY2 = (LooseVersion(min_docker_version) < LooseVersion('2.0')) | ||
|
||
if HAS_DOCKER_MODELS and HAS_DOCKER_SSLADAPTER: | ||
self.fail("Cannot have both the docker-py and docker python modules installed together as they use the same namespace and " | ||
"cause a corrupt installation. Please uninstall both packages, and re-install only the docker-py or docker python " | ||
"module. It is recommended to install the docker module if no support for Python 2.6 is required. " | ||
"Please note that simply uninstalling one of the modules can leave the other module in a broken state.") | ||
|
||
if not HAS_DOCKER_PY: | ||
self.fail("Failed to import docker or docker-py - %s. Try `pip install docker` or `pip install docker-py` (Python 2.6)" % HAS_DOCKER_ERROR) | ||
|
||
if LooseVersion(docker_version) < LooseVersion(MIN_DOCKER_VERSION): | ||
self.fail("Error: docker / docker-py version is %s. Minimum version required is %s." % (docker_version, | ||
MIN_DOCKER_VERSION)) | ||
if NEEDS_DOCKER_PY2: | ||
msg = "Failed to import docker - %s. Try `pip install docker`" | ||
else: | ||
msg = "Failed to import docker or docker-py - %s. Try `pip install docker` or `pip install docker-py` (Python 2.6)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently the module would suggest installing |
||
self.fail(msg % HAS_DOCKER_ERROR) | ||
|
||
if LooseVersion(docker_version) < LooseVersion(min_docker_version): | ||
if NEEDS_DOCKER_PY2: | ||
if docker_version < LooseVersion('2.0'): | ||
msg = "Error: docker-py version is %s, while this module requires docker %s. Try `pip uninstall docker-py` and then `pip install docker`" | ||
else: | ||
msg = "Error: docker version is %s. Minimum version required is %s. Use `pip install --upgrade docker` to upgrade." | ||
else: | ||
# The minimal required version is < 2.0 (and the current version as well). | ||
# Advertise docker (instead of docker-py) for non-Python-2.6 users. | ||
msg = ("Error: docker / docker-py version is %s. Minimum version required is %s. " | ||
"Hint: if you do not need Python 2.6 support, try `pip uninstall docker-py` followed by `pip install docker`") | ||
self.fail(msg % (docker_version, min_docker_version)) | ||
|
||
self.debug = self.module.params.get('debug') | ||
self.check_mode = self.module.check_mode | ||
|
@@ -206,6 +222,11 @@ def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclu | |
except Exception as exc: | ||
self.fail("Error connecting: %s" % exc) | ||
|
||
if min_docker_api_version is not None: | ||
docker_api_version = self.version()['ApiVersion'] | ||
if LooseVersion(docker_api_version) < LooseVersion(min_docker_api_version): | ||
self.fail('docker API version is %s. Minimum version required is %s.' % (docker_api_version, min_docker_api_version)) | ||
|
||
def log(self, msg, pretty_print=False): | ||
pass | ||
# if self.debug: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
NEEDS_DOCKER_PY2
beTrue
if the required version is>=2.0
instead than<2.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right! Thanks for spotting this. I'll create a new PR for fixing this (since this was already merged).