[cloud] Remove repeated error handling and region checking, both now in boto3_conn (#32774)

* Remove boto usage from boto3 modules

* Remove region checking

boto3_conn now takes care of region checking and handles NoRegionError
exceptions with a standard message

boto3_conn also takes care of other connection exceptions too.

* Document boto3 as a requirement for ec2_eni_facts
This commit is contained in:
Will Thames 2017-12-15 07:16:59 +10:00 committed by Ryan Brown
parent c52964a6f4
commit ddc3465408
8 changed files with 37 additions and 173 deletions

View file

@ -27,7 +27,7 @@ description:
- Registers or deregisters task definitions in the Amazon Web Services (AWS) EC2 Container Service (ECS)
version_added: "2.0"
author: Mark Chance(@Java1Guy)
requirements: [ json, boto, botocore, boto3 ]
requirements: [ json, botocore, boto3 ]
options:
state:
description:
@ -114,15 +114,9 @@ taskdefinition:
type: dict
returned: always
'''
try:
import boto
import botocore
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
try:
import boto3
import botocore
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
@ -138,13 +132,8 @@ class EcsTaskManager:
def __init__(self, module):
self.module = module
try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
if not region:
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg="Can't authorize connection - " % str(e))
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
def describe_task(self, task_name):
try:
@ -233,9 +222,6 @@ def main():
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
if not HAS_BOTO:
module.fail_json(msg='boto is required.')
if not HAS_BOTO3:
module.fail_json(msg='boto3 is required.')