1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adapt exception syntax to work under python3 in s3_bucket.py

Signed-off-by: Javier M. Mellid <jmunhoz@igalia.com>
This commit is contained in:
Javier M. Mellid 2016-06-18 00:06:13 +02:00 committed by Matt Clay
parent 3c36c2b3db
commit 04e6a207bd

View file

@ -155,11 +155,11 @@ def _create_bucket(connection, module, location):
try: try:
bucket = connection.get_bucket(name) bucket = connection.get_bucket(name)
except S3ResponseError, e: except S3ResponseError as e:
try: try:
bucket = connection.create_bucket(name, location=location) bucket = connection.create_bucket(name, location=location)
changed = True changed = True
except S3CreateError, e: except S3CreateError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
# Versioning # Versioning
@ -169,7 +169,7 @@ def _create_bucket(connection, module, location):
bucket.configure_versioning(versioning) bucket.configure_versioning(versioning)
changed = True changed = True
versioning_status = bucket.get_versioning_status() versioning_status = bucket.get_versioning_status()
except S3ResponseError, e: except S3ResponseError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
elif not versioning_status and not versioning: elif not versioning_status and not versioning:
# do nothing # do nothing
@ -199,7 +199,7 @@ def _create_bucket(connection, module, location):
# Policy # Policy
try: try:
current_policy = bucket.get_policy() current_policy = bucket.get_policy()
except S3ResponseError, e: except S3ResponseError as e:
if e.error_code == "NoSuchBucketPolicy": if e.error_code == "NoSuchBucketPolicy":
current_policy = None current_policy = None
else: else:
@ -214,7 +214,7 @@ def _create_bucket(connection, module, location):
bucket.set_policy(policy) bucket.set_policy(policy)
changed = True changed = True
current_policy = bucket.get_policy() current_policy = bucket.get_policy()
except S3ResponseError, e: except S3ResponseError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
elif current_policy is None and policy is not None: elif current_policy is None and policy is not None:
@ -224,7 +224,7 @@ def _create_bucket(connection, module, location):
bucket.set_policy(policy) bucket.set_policy(policy)
changed = True changed = True
current_policy = bucket.get_policy() current_policy = bucket.get_policy()
except S3ResponseError, e: except S3ResponseError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
elif current_policy is not None and policy is None: elif current_policy is not None and policy is None:
@ -232,7 +232,7 @@ def _create_bucket(connection, module, location):
bucket.delete_policy() bucket.delete_policy()
changed = True changed = True
current_policy = bucket.get_policy() current_policy = bucket.get_policy()
except S3ResponseError, e: except S3ResponseError as e:
if e.error_code == "NoSuchBucketPolicy": if e.error_code == "NoSuchBucketPolicy":
current_policy = None current_policy = None
else: else:
@ -246,7 +246,7 @@ def _create_bucket(connection, module, location):
try: try:
current_tags = bucket.get_tags() current_tags = bucket.get_tags()
tag_set = TagSet() tag_set = TagSet()
except S3ResponseError, e: except S3ResponseError as e:
if e.error_code == "NoSuchTagSet": if e.error_code == "NoSuchTagSet":
current_tags = None current_tags = None
else: else:
@ -267,7 +267,7 @@ def _create_bucket(connection, module, location):
bucket.delete_tags() bucket.delete_tags()
current_tags_dict = tags current_tags_dict = tags
changed = True changed = True
except S3ResponseError, e: except S3ResponseError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
module.exit_json(changed=changed, name=bucket.name, versioning=versioning_status, requester_pays=requester_pays_status, policy=current_policy, tags=current_tags_dict) module.exit_json(changed=changed, name=bucket.name, versioning=versioning_status, requester_pays=requester_pays_status, policy=current_policy, tags=current_tags_dict)
@ -280,7 +280,7 @@ def _destroy_bucket(connection, module):
try: try:
bucket = connection.get_bucket(name) bucket = connection.get_bucket(name)
except S3ResponseError, e: except S3ResponseError as e:
if e.error_code != "NoSuchBucket": if e.error_code != "NoSuchBucket":
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
@ -293,13 +293,13 @@ def _destroy_bucket(connection, module):
for key in bucket.list(): for key in bucket.list():
key.delete() key.delete()
except BotoServerError, e: except BotoServerError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
try: try:
bucket = connection.delete_bucket(name) bucket = connection.delete_bucket(name)
changed = True changed = True
except S3ResponseError, e: except S3ResponseError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
module.exit_json(changed=changed) module.exit_json(changed=changed)
@ -312,11 +312,11 @@ def _create_bucket_ceph(connection, module, location):
try: try:
bucket = connection.get_bucket(name) bucket = connection.get_bucket(name)
except S3ResponseError, e: except S3ResponseError as e:
try: try:
bucket = connection.create_bucket(name, location=location) bucket = connection.create_bucket(name, location=location)
changed = True changed = True
except S3CreateError, e: except S3CreateError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
module.exit_json(changed=changed) module.exit_json(changed=changed)
@ -430,9 +430,9 @@ def main():
if connection is None: if connection is None:
connection = boto.connect_s3(**aws_connect_params) connection = boto.connect_s3(**aws_connect_params)
except boto.exception.NoAuthHandlerFound, e: except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg='No Authentication Handler found: %s ' % str(e)) module.fail_json(msg='No Authentication Handler found: %s ' % str(e))
except Exception, e: except Exception as e:
module.fail_json(msg='Failed to connect to S3: %s' % str(e)) module.fail_json(msg='Failed to connect to S3: %s' % str(e))
if connection is None: # this should never happen if connection is None: # this should never happen