mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -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
|
@ -144,15 +144,7 @@ from ansible.module_utils.ec2 import (boto3_conn, ec2_argument_spec, get_aws_con
|
|||
import traceback
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.ec2
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
try:
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError, NoCredentialsError, NoRegionError, WaiterError
|
||||
from botocore.exceptions import ClientError, NoCredentialsError, WaiterError
|
||||
HAS_BOTO3 = True
|
||||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
@ -166,8 +158,6 @@ def copy_image(module, ec2):
|
|||
ec2: ec2 connection object
|
||||
"""
|
||||
|
||||
tags = module.params.get('tags')
|
||||
|
||||
params = {'SourceRegion': module.params.get('source_region'),
|
||||
'SourceImageId': module.params.get('source_image_id'),
|
||||
'Name': module.params.get('name'),
|
||||
|
@ -213,20 +203,9 @@ def main():
|
|||
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
||||
if not HAS_BOTO:
|
||||
module.fail_json(msg='boto required for this module')
|
||||
# TODO: Check botocore version
|
||||
region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
|
||||
|
||||
if HAS_BOTO3:
|
||||
|
||||
try:
|
||||
ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url,
|
||||
**aws_connect_params)
|
||||
except NoRegionError:
|
||||
module.fail_json(msg='AWS Region is required')
|
||||
else:
|
||||
module.fail_json(msg='boto3 required for this module')
|
||||
ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url,
|
||||
**aws_connect_params)
|
||||
|
||||
copy_image(module, ec2)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue