From 671e1b06f29400a0a86ec7954176997ebb908e88 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 16 Dec 2020 21:06:15 +0100 Subject: [PATCH] Use botocore_at_least rather than LooseVersion/StrictVersion directly (#280) * Use botocore_at_least rather than LooseVersion/StrictVersion directly * changelog --- dynamodb_ttl.py | 5 ++--- ec2_vpc_peer.py | 3 +-- ecs_task.py | 9 +++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/dynamodb_ttl.py b/dynamodb_ttl.py index b23c0ab076e..e04dedfafbb 100644 --- a/dynamodb_ttl.py +++ b/dynamodb_ttl.py @@ -65,7 +65,6 @@ - { "AttributeName": "deploy_timestamp", "Enabled": true } ''' -import distutils.version import traceback try: @@ -126,8 +125,8 @@ def main(): argument_spec=argument_spec, ) - if distutils.version.StrictVersion(botocore.__version__) < distutils.version.StrictVersion('1.5.24'): - # TTL was added in this version. + if not module.botocore_at_least('1.5.24'): + # TTL was added in 1.5.24 module.fail_json(msg='Found botocore in version {0}, but >= {1} is required for TTL support'.format(botocore.__version__, '1.5.24')) try: diff --git a/ec2_vpc_peer.py b/ec2_vpc_peer.py index 31f6ea203a7..c7efeff3829 100644 --- a/ec2_vpc_peer.py +++ b/ec2_vpc_peer.py @@ -221,7 +221,6 @@ except ImportError: pass # Handled by AnsibleAWSModule -import distutils.version import traceback from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule @@ -279,7 +278,7 @@ def create_peer_connection(client, module): params['VpcId'] = module.params.get('vpc_id') params['PeerVpcId'] = module.params.get('peer_vpc_id') if module.params.get('peer_region'): - if distutils.version.StrictVersion(botocore.__version__) < distutils.version.StrictVersion('1.8.6'): + if not module.botocore_at_least('1.8.6'): module.fail_json(msg="specifying peer_region parameter requires botocore >= 1.8.6") params['PeerRegion'] = module.params.get('peer_region') if module.params.get('peer_owner_id'): diff --git a/ecs_task.py b/ecs_task.py index f43cd700d27..e8eeb9c57ea 100644 --- a/ecs_task.py +++ b/ecs_task.py @@ -307,29 +307,26 @@ def stop_task(self, cluster, task): return response['task'] def ecs_api_handles_launch_type(self): - from distutils.version import LooseVersion # There doesn't seem to be a nice way to inspect botocore to look # for attributes (and networkConfiguration is not an explicit argument # to e.g. ecs.run_task, it's just passed as a keyword argument) - return LooseVersion(botocore.__version__) >= LooseVersion('1.8.4') + return self.module.botocore_at_least('1.8.4') def ecs_task_long_format_enabled(self): account_support = self.ecs.list_account_settings(name='taskLongArnFormat', effectiveSettings=True) return account_support['settings'][0]['value'] == 'enabled' def ecs_api_handles_tags(self): - from distutils.version import LooseVersion # There doesn't seem to be a nice way to inspect botocore to look # for attributes (and networkConfiguration is not an explicit argument # to e.g. ecs.run_task, it's just passed as a keyword argument) - return LooseVersion(botocore.__version__) >= LooseVersion('1.12.46') + return self.module.botocore_at_least('1.12.46') def ecs_api_handles_network_configuration(self): - from distutils.version import LooseVersion # There doesn't seem to be a nice way to inspect botocore to look # for attributes (and networkConfiguration is not an explicit argument # to e.g. ecs.run_task, it's just passed as a keyword argument) - return LooseVersion(botocore.__version__) >= LooseVersion('1.7.44') + return self.module.botocore_at_least('1.7.44') def main():