summaryrefslogtreecommitdiff
path: root/cloud/amazon/ec2_ami_copy.py
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-10-23 13:41:03 -0700
committerToshio Kuratomi <a.badger@gmail.com>2016-10-23 16:40:52 -0700
commit79c7997952ec790f38caf027078bbcc294f928d1 (patch)
treed722683f45d40a93f5b1614d1ec4887b0a9d76ca /cloud/amazon/ec2_ami_copy.py
parent7ce17ab49ef232af2064d2a680dc6ca78c2211f5 (diff)
downloadansible-modules-extras-79c7997952ec790f38caf027078bbcc294f928d1.tar.gz
Fix amazon extras modules to compile under python3
Diffstat (limited to 'cloud/amazon/ec2_ami_copy.py')
-rw-r--r--cloud/amazon/ec2_ami_copy.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/cloud/amazon/ec2_ami_copy.py b/cloud/amazon/ec2_ami_copy.py
index 88eba110..c053eb31 100644
--- a/cloud/amazon/ec2_ami_copy.py
+++ b/cloud/amazon/ec2_ami_copy.py
@@ -124,6 +124,8 @@ EXAMPLES = '''
kms_key_id: arn:aws:kms:us-east-1:XXXXXXXXXXXX:key/746de6ea-50a4-4bcb-8fbc-e3b29f2d367b
'''
+import time
+
try:
import boto
import boto.ec2
@@ -131,6 +133,9 @@ try:
except ImportError:
HAS_BOTO = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.ec2 import ec2_argument_spec, ec2_connect, get_aws_connection_info
+
def copy_image(module, ec2):
"""
@@ -160,7 +165,7 @@ def copy_image(module, ec2):
}
image_id = ec2.copy_image(**params).image_id
- except boto.exception.BotoServerError, e:
+ except boto.exception.BotoServerError as e:
module.fail_json(msg="%s: %s" % (e.error_code, e.error_message))
img = wait_until_image_is_recognized(module, ec2, wait_timeout, image_id, wait)
@@ -198,7 +203,7 @@ def wait_until_image_is_recognized(module, ec2, wait_timeout, image_id, wait):
for i in range(wait_timeout):
try:
return ec2.get_image(image_id)
- except boto.exception.EC2ResponseError, e:
+ except boto.exception.EC2ResponseError as e:
# This exception we expect initially right after registering the copy with EC2 API
if 'InvalidAMIID.NotFound' in e.error_code and wait:
time.sleep(1)
@@ -231,12 +236,12 @@ def main():
try:
ec2 = ec2_connect(module)
- except boto.exception.NoAuthHandlerFound, e:
+ except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg=str(e))
try:
region, ec2_url, boto_params = get_aws_connection_info(module)
- except boto.exception.NoAuthHandlerFound, e:
+ except boto.exception.NoAuthHandlerFound as e:
module.fail_json(msg=str(e))
if not region:
@@ -245,9 +250,6 @@ def main():
copy_image(module, ec2)
-# import module snippets
-from ansible.module_utils.basic import *
-from ansible.module_utils.ec2 import *
-
-main()
+if __name__ == '__main__':
+ main()