mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
[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:
parent
c52964a6f4
commit
ddc3465408
8 changed files with 37 additions and 173 deletions
|
@ -36,7 +36,7 @@ author:
|
|||
- "Stephane Maarek (@simplesteph)"
|
||||
- "Zac Blazic (@zacblazic)"
|
||||
|
||||
requirements: [ json, boto, botocore, boto3 ]
|
||||
requirements: [ json, botocore, boto3 ]
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
|
@ -267,14 +267,7 @@ DEPLOYMENT_CONFIGURATION_TYPE_MAP = {
|
|||
|
||||
|
||||
try:
|
||||
import boto
|
||||
import botocore
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
try:
|
||||
import boto3
|
||||
HAS_BOTO3 = True
|
||||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
@ -289,13 +282,8 @@ class EcsServiceManager:
|
|||
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:
|
||||
self.module.fail_json(msg="Can't authorize connection - %s" % 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 find_in_array(self, array_of_services, service_name, field_name='serviceArn'):
|
||||
for c in array_of_services:
|
||||
|
@ -403,9 +391,6 @@ def main():
|
|||
required_together=[['load_balancers', 'role']]
|
||||
)
|
||||
|
||||
if not HAS_BOTO:
|
||||
module.fail_json(msg='boto is required.')
|
||||
|
||||
if not HAS_BOTO3:
|
||||
module.fail_json(msg='boto3 is required.')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue