[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

@ -22,7 +22,7 @@ version_added: "2.1"
author:
- "Mark Chance (@java1guy)"
- "Darek Kaczynski (@kaczynskid)"
requirements: [ json, boto, botocore, boto3 ]
requirements: [ json, botocore, boto3 ]
options:
details:
description:
@ -124,14 +124,7 @@ services:
''' # NOQA
try:
import boto
import botocore
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
try:
import boto3
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
@ -146,14 +139,9 @@ class EcsServiceManager:
def __init__(self, module):
self.module = module
try:
# self.ecs = boto3.client('ecs')
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:
self.module.fail_json(msg="Can't authorize connection - %s" % str(e))
# self.ecs = boto3.client('ecs')
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 list_clusters(self):
# return self.client.list_clusters()
@ -211,9 +199,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.')