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

Remove wildcard imports from amazon modules (#31451)

* Remove wildcard imports from amazon modules
* Remove files from legacy pep8 that now pass
This commit is contained in:
Toshio Kuratomi 2017-10-09 07:38:41 -07:00 committed by GitHub
parent 1037c211d9
commit 9c81257ce3
16 changed files with 205 additions and 345 deletions

View file

@ -1,19 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# # Copyright: Ansible Project
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -293,15 +284,12 @@ virtualization_type:
sample: "hvm" sample: "hvm"
''' '''
try:
import boto.ec2
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
HAS_BOTO=True
except ImportError:
HAS_BOTO=False
import json import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO, ec2_argument_spec, ec2_connect
def get_block_device_mapping(image): def get_block_device_mapping(image):
""" """
Retrieves block device mapping from AMI Retrieves block device mapping from AMI
@ -451,9 +439,6 @@ def main():
module.exit_json(results=results) module.exit_json(results=results)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -170,10 +162,12 @@ EXAMPLES = '''
''' '''
try: try:
import boto.ec2 import boto.exception
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO, ec2_argument_spec, ec2_connect
class EIPException(Exception): class EIPException(Exception):
@ -432,7 +426,8 @@ def main():
if state == 'present': if state == 'present':
if device_id: if device_id:
result = ensure_present(ec2, module, domain, address, private_ip_address, device_id, result = ensure_present(ec2, module, domain, address, private_ip_address, device_id,
reuse_existing_ip_allowed, allow_reassociation, module.check_mode, isinstance=is_instance) reuse_existing_ip_allowed, allow_reassociation,
module.check_mode, isinstance=is_instance)
else: else:
if address: if address:
changed = False changed = False
@ -459,9 +454,6 @@ def main():
result['warnings'] = warnings result['warnings'] = warnings
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import * # noqa
from ansible.module_utils.ec2 import * # noqa
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,19 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -110,16 +102,13 @@ EXAMPLES = '''
name: example name: example
state: absent state: absent
''' '''
try:
import boto.ec2
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
from ansible.module_utils._text import to_bytes
import random import random
import string import string
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO, ec2_argument_spec, ec2_connect
from ansible.module_utils._text import to_bytes
def main(): def main():
@ -127,10 +116,10 @@ def main():
argument_spec.update(dict( argument_spec.update(dict(
name=dict(required=True), name=dict(required=True),
key_material=dict(required=False), key_material=dict(required=False),
force = dict(required=False, type='bool', default=True), force=dict(required=False, type='bool', default=True),
state = dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
wait = dict(type='bool', default=False), wait=dict(type='bool', default=False),
wait_timeout = dict(default=300), wait_timeout=dict(default=300),
) )
) )
module = AnsibleModule( module = AnsibleModule(
@ -191,7 +180,7 @@ def main():
# find an unused name # find an unused name
test = 'empty' test = 'empty'
while test: while test:
randomchars = [random.choice(string.ascii_letters + string.digits) for x in range(0,10)] randomchars = [random.choice(string.ascii_letters + string.digits) for x in range(0, 10)]
tmpkeyname = "ansible-" + ''.join(randomchars) tmpkeyname = "ansible-" + ''.join(randomchars)
test = ec2.get_key_pair(tmpkeyname) test = ec2.get_key_pair(tmpkeyname)
@ -259,9 +248,6 @@ def main():
else: else:
module.exit_json(changed=changed, key=None) module.exit_json(changed=changed, key=None)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -149,11 +141,14 @@ EXAMPLES = '''
try: try:
import boto.ec2.cloudwatch import boto.ec2.cloudwatch
from boto.ec2.cloudwatch import CloudWatchConnection, MetricAlarm from boto.ec2.cloudwatch import MetricAlarm
from boto.exception import BotoServerError from boto.exception import BotoServerError, NoAuthHandlerFound
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (AnsibleAWSError, HAS_BOTO, connect_to_aws, ec2_argument_spec,
get_aws_connection_info)
def create_metric_alarm(connection, module): def create_metric_alarm(connection, module):
@ -309,7 +304,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.ec2.cloudwatch, region, **aws_connect_params) connection = connect_to_aws(boto.ec2.cloudwatch, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: except (NoAuthHandlerFound, AnsibleAWSError) as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -320,8 +315,5 @@ def main():
delete_metric_alarm(connection, module) delete_metric_alarm(connection, module)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -75,17 +67,17 @@ EXAMPLES = '''
cooldown: 300 cooldown: 300
''' '''
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
try: try:
import boto.ec2.autoscale import boto.ec2.autoscale
import boto.exception
from boto.ec2.autoscale import ScalingPolicy from boto.ec2.autoscale import ScalingPolicy
from boto.exception import BotoServerError from boto.exception import BotoServerError
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (AnsibleAWSError, HAS_BOTO, connect_to_aws, ec2_argument_spec,
get_aws_connection_info)
def create_scaling_policy(connection, module): def create_scaling_policy(connection, module):

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -124,10 +116,12 @@ import time
import datetime import datetime
try: try:
import boto.ec2 import boto.exception
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO, ec2_argument_spec, ec2_connect
# Find the most recent snapshot # Find the most recent snapshot
@ -264,7 +258,7 @@ def create_snapshot_ansible_module():
wait_timeout = dict(type='int', default=0), wait_timeout = dict(type='int', default=0),
last_snapshot_min_age = dict(type='int', default=0), last_snapshot_min_age = dict(type='int', default=0),
snapshot_tags = dict(type='dict', default=dict()), snapshot_tags = dict(type='dict', default=dict()),
state = dict(choices=['absent','present'], default='present'), state = dict(choices=['absent', 'present'], default='present'),
) )
) )
module = AnsibleModule(argument_spec=argument_spec) module = AnsibleModule(argument_spec=argument_spec)
@ -305,9 +299,6 @@ def main():
last_snapshot_min_age=last_snapshot_min_age last_snapshot_min_age=last_snapshot_min_age
) )
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -255,12 +247,17 @@ import time
from distutils.version import LooseVersion from distutils.version import LooseVersion
try: try:
import boto
import boto.ec2 import boto.ec2
import boto.exception
from boto.exception import BotoServerError from boto.exception import BotoServerError
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO, AnsibleAWSError, connect_to_aws, ec2_argument_spec,
get_aws_connection_info)
def get_volume(module, ec2): def get_volume(module, ec2):
@ -635,9 +632,6 @@ def main():
elif state == 'absent': elif state == 'absent':
delete_volume(module, ec2) delete_volume(module, ec2)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -144,13 +136,14 @@ vpc.is_default:
''' '''
try: try:
import boto
import boto.ec2
import boto.vpc import boto.vpc
from boto.exception import BotoServerError from boto.exception import BotoServerError, NoAuthHandlerFound
HAS_BOTO=True
except ImportError: except ImportError:
HAS_BOTO=False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO, AnsibleAWSError, boto_exception, connect_to_aws,
ec2_argument_spec, get_aws_connection_info)
def vpc_exists(module, vpc, name, cidr_block, multi): def vpc_exists(module, vpc, name, cidr_block, multi):
@ -260,7 +253,7 @@ def main():
if region: if region:
try: try:
connection = connect_to_aws(boto.vpc, region, **aws_connect_params) connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: except (NoAuthHandlerFound, AnsibleAWSError) as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
else: else:
module.fail_json(msg="region must be specified") module.fail_json(msg="region must be specified")
@ -336,9 +329,6 @@ def main():
module.exit_json(changed=changed, vpc=get_vpc_values(vpc_obj)) module.exit_json(changed=changed, vpc=get_vpc_values(vpc_obj))
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -126,19 +118,16 @@ repository:
''' '''
import json import json
import time import traceback
import inspect
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
try: try:
import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
HAS_BOTO3 = True
except ImportError: except ImportError:
HAS_BOTO3 = False pass # Taken care of by ec2.HAS_BOTO3
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, boto_exception, ec2_argument_spec,
get_aws_connection_info, sort_json_policy_dict)
def build_kwargs(registry_id): def build_kwargs(registry_id):

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -199,17 +191,21 @@ tags:
''' '''
import sys
from time import sleep from time import sleep
from time import time as timestamp from time import time as timestamp
from collections import defaultdict
try: try:
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
import boto3
HAS_BOTO3 = True
except ImportError as e: except ImportError as e:
HAS_BOTO3 = False pass # Taken care of by ec2.HAS_BOTO3
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict,
ec2_argument_spec, get_aws_connection_info)
def _index_by_key(key, items):
return dict((item[key], item) for item in items)
class EFSConnection(object): class EFSConnection(object):
@ -394,11 +390,8 @@ class EFSConnection(object):
lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)), lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)),
0 0
) )
current_targets = _index_by_key('SubnetId', self.get_mount_targets(FileSystemId=fs_id))
index_by_subnet_id = lambda items: dict((item['SubnetId'], item) for item in items) targets = _index_by_key('SubnetId', targets)
current_targets = index_by_subnet_id(self.get_mount_targets(FileSystemId=fs_id))
targets = index_by_subnet_id(targets)
targets_to_create, intersection, targets_to_delete = dict_diff(current_targets, targets_to_create, intersection, targets_to_delete = dict_diff(current_targets,
targets, True) targets, True)
@ -626,8 +619,6 @@ def main():
result = camel_dict_to_snake_dict(result) result = camel_dict_to_snake_dict(result)
module.exit_json(changed=changed, efs=result) module.exit_json(changed=changed, efs=result)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -162,15 +154,18 @@ task:
''' '''
import json import json
import itertools import traceback
import sys
try: try:
import boto import boto.exception
import boto.iam import boto.iam
import boto.ec2 import boto.iam.connection
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO, boto_exception, connect_to_aws, ec2_argument_spec,
get_aws_connection_info)
def _paginate(func, attr): def _paginate(func, attr):
@ -460,7 +455,6 @@ new_name=None):
if ('The group with name %s cannot be found.' % group) in error_msg: if ('The group with name %s cannot be found.' % group) in error_msg:
module.fail_json(changed=False, msg="Group %s doesn't exist" % group) module.fail_json(changed=False, msg="Group %s doesn't exist" % group)
if len(remove_groups) > 0 or len(new_groups) > 0: if len(remove_groups) > 0 or len(new_groups) > 0:
changed = True changed = True
@ -847,8 +841,6 @@ def main():
module.exit_json(changed=changed, roles=role_list, role_result=role_result, module.exit_json(changed=changed, roles=role_list, role_result=role_result,
instance_profile_result=instance_profile_result) instance_profile_result=instance_profile_result)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,17 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# # Copyright: Ansible Project
# This is a free software: you can redistribute it and/or modify # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or from __future__ import absolute_import, division, print_function
# (at your option) any later version. __metaclass__ = type
#
# This Ansible library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -150,17 +143,18 @@ tags:
} }
''' '''
try:
import botocore
import boto3
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
import re import re
import datetime import datetime
import time import time
from functools import reduce from functools import reduce
try:
import botocore.exceptions
except ImportError:
pass # Taken care of by ec2.HAS_BOTO3
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO3, boto3_conn, ec2_argument_spec, get_aws_connection_info
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
@ -1178,9 +1172,6 @@ def main():
success=success, changed=changed, msg=err_msg, result=results success=success, changed=changed, msg=err_msg, result=results
) )
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,18 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -517,22 +509,25 @@ db_subnet_groups:
sample: "active" sample: "active"
''' '''
import sys
import time import time
from ansible.module_utils.ec2 import AWSRetry
try: try:
import boto.rds import boto.rds
HAS_BOTO = True import boto.exception
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
try: try:
import boto.rds2 import boto.rds2
has_rds2 = True import boto.rds2.exceptions
HAS_RDS2 = True
except ImportError: except ImportError:
has_rds2 = False HAS_RDS2 = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import AWSRetry
from ansible.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info
DEFAULT_PORTS = { DEFAULT_PORTS = {
'aurora': 3306, 'aurora': 3306,
@ -567,13 +562,13 @@ class RDSConnection:
def get_db_instance(self, instancename): def get_db_instance(self, instancename):
try: try:
return RDSDBInstance(self.connection.get_all_dbinstances(instancename)[0]) return RDSDBInstance(self.connection.get_all_dbinstances(instancename)[0])
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError:
return None return None
def get_db_snapshot(self, snapshotid): def get_db_snapshot(self, snapshotid):
try: try:
return RDSSnapshot(self.connection.get_all_dbsnapshots(snapshot_id=snapshotid)[0]) return RDSSnapshot(self.connection.get_all_dbsnapshots(snapshot_id=snapshotid)[0])
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError:
return None return None
def create_db_instance(self, instance_name, size, instance_class, db_engine, def create_db_instance(self, instance_name, size, instance_class, db_engine,
@ -670,7 +665,7 @@ class RDS2Connection:
)['DescribeDBSnapshotsResponse']['DescribeDBSnapshotsResult']['DBSnapshots'] )['DescribeDBSnapshotsResponse']['DescribeDBSnapshotsResult']['DBSnapshots']
result = RDS2Snapshot(snapshots[0]) result = RDS2Snapshot(snapshots[0])
return result return result
except boto.rds2.exceptions.DBSnapshotNotFound as e: except boto.rds2.exceptions.DBSnapshotNotFound:
return None return None
def create_db_instance(self, instance_name, size, instance_class, db_engine, def create_db_instance(self, instance_name, size, instance_class, db_engine,
@ -785,7 +780,7 @@ class RDSDBInstance:
# ReadReplicaSourceDBInstanceIdentifier may or may not exist # ReadReplicaSourceDBInstanceIdentifier may or may not exist
try: try:
d["replication_source"] = self.instance.ReadReplicaSourceDBInstanceIdentifier d["replication_source"] = self.instance.ReadReplicaSourceDBInstanceIdentifier
except Exception as e: except Exception:
d["replication_source"] = None d["replication_source"] = None
return d return d
@ -955,7 +950,6 @@ def await_resource(conn, resource, status, module):
def create_db_instance(module, conn): def create_db_instance(module, conn):
subnet = module.params.get('subnet')
required_vars = ['instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password'] required_vars = ['instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password']
valid_vars = ['backup_retention', 'backup_window', valid_vars = ['backup_retention', 'backup_window',
'character_set_name', 'db_name', 'engine_version', 'character_set_name', 'db_name', 'engine_version',
@ -966,7 +960,7 @@ def create_db_instance(module, conn):
valid_vars.append('vpc_security_groups') valid_vars.append('vpc_security_groups')
else: else:
valid_vars.append('security_groups') valid_vars.append('security_groups')
if has_rds2: if HAS_RDS2:
valid_vars.extend(['publicly_accessible', 'tags']) valid_vars.extend(['publicly_accessible', 'tags'])
params = validate_parameters(required_vars, valid_vars, module) params = validate_parameters(required_vars, valid_vars, module)
instance_name = module.params.get('instance_name') instance_name = module.params.get('instance_name')
@ -994,7 +988,7 @@ def create_db_instance(module, conn):
def replicate_db_instance(module, conn): def replicate_db_instance(module, conn):
required_vars = ['instance_name', 'source_instance'] required_vars = ['instance_name', 'source_instance']
valid_vars = ['instance_type', 'port', 'upgrade', 'zone'] valid_vars = ['instance_type', 'port', 'upgrade', 'zone']
if has_rds2: if HAS_RDS2:
valid_vars.extend(['iops', 'option_group', 'publicly_accessible', 'tags']) valid_vars.extend(['iops', 'option_group', 'publicly_accessible', 'tags'])
params = validate_parameters(required_vars, valid_vars, module) params = validate_parameters(required_vars, valid_vars, module)
instance_name = module.params.get('instance_name') instance_name = module.params.get('instance_name')
@ -1037,7 +1031,7 @@ def delete_db_instance_or_snapshot(module, conn):
if instance_name: if instance_name:
if snapshot: if snapshot:
params["skip_final_snapshot"] = False params["skip_final_snapshot"] = False
if has_rds2: if HAS_RDS2:
params["final_db_snapshot_identifier"] = snapshot params["final_db_snapshot_identifier"] = snapshot
else: else:
params["final_snapshot_id"] = snapshot params["final_snapshot_id"] = snapshot
@ -1054,7 +1048,7 @@ def delete_db_instance_or_snapshot(module, conn):
if not module.params.get('wait'): if not module.params.get('wait'):
module.exit_json(changed=True) module.exit_json(changed=True)
try: try:
resource = await_resource(conn, result, 'deleted', module) await_resource(conn, result, 'deleted', module)
module.exit_json(changed=True) module.exit_json(changed=True)
except RDSException as e: except RDSException as e:
if e.code == 'DBInstanceNotFound': if e.code == 'DBInstanceNotFound':
@ -1066,9 +1060,6 @@ def delete_db_instance_or_snapshot(module, conn):
def facts_db_instance_or_snapshot(module, conn): def facts_db_instance_or_snapshot(module, conn):
required_vars = []
valid_vars = ['instance_name', 'snapshot']
params = validate_parameters(required_vars, valid_vars, module)
instance_name = module.params.get('instance_name') instance_name = module.params.get('instance_name')
snapshot = module.params.get('snapshot') snapshot = module.params.get('snapshot')
@ -1177,7 +1168,7 @@ def reboot_db_instance(module, conn):
required_vars = ['instance_name'] required_vars = ['instance_name']
valid_vars = [] valid_vars = []
if has_rds2: if HAS_RDS2:
valid_vars.append('force_failover') valid_vars.append('force_failover')
params = validate_parameters(required_vars, valid_vars, module) params = validate_parameters(required_vars, valid_vars, module)
@ -1203,7 +1194,7 @@ def restore_db_instance(module, conn):
valid_vars = ['db_name', 'iops', 'license_model', 'multi_zone', valid_vars = ['db_name', 'iops', 'license_model', 'multi_zone',
'option_group', 'port', 'publicly_accessible', 'option_group', 'port', 'publicly_accessible',
'subnet', 'tags', 'upgrade', 'zone'] 'subnet', 'tags', 'upgrade', 'zone']
if has_rds2: if HAS_RDS2:
valid_vars.append('instance_type') valid_vars.append('instance_type')
else: else:
required_vars.append('instance_type') required_vars.append('instance_type')
@ -1272,7 +1263,7 @@ def validate_parameters(required_vars, valid_vars, module):
'new_instance_name': 'new_db_instance_identifier', 'new_instance_name': 'new_db_instance_identifier',
'force_failover': 'force_failover', 'force_failover': 'force_failover',
} }
if has_rds2: if HAS_RDS2:
optional_params.update(optional_params_rds2) optional_params.update(optional_params_rds2)
sec_group = 'db_security_groups' sec_group = 'db_security_groups'
else: else:
@ -1299,7 +1290,7 @@ def validate_parameters(required_vars, valid_vars, module):
vpc_groups = module.params.get('vpc_security_groups') vpc_groups = module.params.get('vpc_security_groups')
if vpc_groups: if vpc_groups:
if has_rds2: if HAS_RDS2:
params['vpc_security_group_ids'] = vpc_groups params['vpc_security_group_ids'] = vpc_groups
else: else:
groups_list = [] groups_list = []
@ -1385,16 +1376,13 @@ def main():
module.params['port'] = DEFAULT_PORTS[engine.lower()] module.params['port'] = DEFAULT_PORTS[engine.lower()]
# connect to the rds endpoint # connect to the rds endpoint
if has_rds2: if HAS_RDS2:
conn = RDS2Connection(module, region, **aws_connect_params) conn = RDS2Connection(module, region, **aws_connect_params)
else: else:
conn = RDSConnection(module, region, **aws_connect_params) conn = RDSConnection(module, region, **aws_connect_params)
invocations[module.params.get('command')](module, conn) invocations[module.params.get('command')](module, conn)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,19 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# Copyright 2014 Jens Carl, Hothead Games Inc. # Copyright 2014 Jens Carl, Hothead Games Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
@ -232,11 +224,13 @@ cluster:
import time import time
try: try:
import boto import boto.exception
from boto import redshift import boto.redshift
HAS_BOTO = True
except ImportError: except ImportError:
HAS_BOTO = False pass # Taken care of by ec2.HAS_BOTO
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info
def _collect_facts(resource): def _collect_facts(resource):
@ -507,9 +501,6 @@ def main():
module.exit_json(changed=changed, cluster=cluster) module.exit_json(changed=changed, cluster=cluster)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -18,7 +18,6 @@ wildcard_imports=$(find . -path ./test/runner/.tox -prune \
-o -path ./lib/ansible/compat/tests/mock.py -prune \ -o -path ./lib/ansible/compat/tests/mock.py -prune \
-o -path ./lib/ansible/compat/tests/unittest.py \ -o -path ./lib/ansible/compat/tests/unittest.py \
-o -path ./test/units/modules/network/cumulus/test_nclu.py -prune \ -o -path ./test/units/modules/network/cumulus/test_nclu.py -prune \
-o -path ./lib/ansible/modules/cloud/amazon -prune \
-o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \
-o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \
-o -path ./lib/ansible/modules/network/f5 -prune \ -o -path ./lib/ansible/modules/network/f5 -prune \

View file

@ -17,9 +17,7 @@ lib/ansible/modules/cloud/amazon/cloudfront_facts.py
lib/ansible/modules/cloud/amazon/dynamodb_table.py lib/ansible/modules/cloud/amazon/dynamodb_table.py
lib/ansible/modules/cloud/amazon/ec2_ami_copy.py lib/ansible/modules/cloud/amazon/ec2_ami_copy.py
lib/ansible/modules/cloud/amazon/ec2_ami_find.py lib/ansible/modules/cloud/amazon/ec2_ami_find.py
lib/ansible/modules/cloud/amazon/ec2_eip.py
lib/ansible/modules/cloud/amazon/ec2_eni_facts.py lib/ansible/modules/cloud/amazon/ec2_eni_facts.py
lib/ansible/modules/cloud/amazon/ec2_key.py
lib/ansible/modules/cloud/amazon/ec2_lc_facts.py lib/ansible/modules/cloud/amazon/ec2_lc_facts.py
lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py
lib/ansible/modules/cloud/amazon/ec2_scaling_policy.py lib/ansible/modules/cloud/amazon/ec2_scaling_policy.py
@ -41,7 +39,6 @@ lib/ansible/modules/cloud/amazon/ecs_service.py
lib/ansible/modules/cloud/amazon/ecs_service_facts.py lib/ansible/modules/cloud/amazon/ecs_service_facts.py
lib/ansible/modules/cloud/amazon/ecs_task.py lib/ansible/modules/cloud/amazon/ecs_task.py
lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
lib/ansible/modules/cloud/amazon/efs.py
lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py
lib/ansible/modules/cloud/amazon/elb_instance.py lib/ansible/modules/cloud/amazon/elb_instance.py
lib/ansible/modules/cloud/amazon/elb_classic_lb.py lib/ansible/modules/cloud/amazon/elb_classic_lb.py