diff --git a/lib/ansible/modules/cloud/centurylink/clc_aa_policy.py b/lib/ansible/modules/cloud/centurylink/clc_aa_policy.py index ce4f456c3d..ca4bcc47e9 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_aa_policy.py +++ b/lib/ansible/modules/cloud/centurylink/clc_aa_policy.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -150,7 +138,7 @@ else: REQUESTS_FOUND = True # -# Requires the clc-python-sdk. +# Requires the clc-python-sdk: # sudo pip install clc-sdk # try: @@ -357,5 +345,6 @@ def main(): clc_aa_policy = ClcAntiAffinityPolicy(module) clc_aa_policy.process_request() + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_alert_policy.py b/lib/ansible/modules/cloud/centurylink/clc_alert_policy.py index b65b4c2227..b6c31087f5 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_alert_policy.py +++ b/lib/ansible/modules/cloud/centurylink/clc_alert_policy.py @@ -2,22 +2,11 @@ # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -179,6 +168,8 @@ policy: __version__ = '${version}' +import json +import os from distutils.version import LooseVersion try: @@ -201,6 +192,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcAlertPolicy: @@ -537,6 +530,6 @@ def main(): clc_alert_policy = ClcAlertPolicy(module) clc_alert_policy.process_request() -from ansible.module_utils.basic import * # pylint: disable=W0614 + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_blueprint_package.py b/lib/ansible/modules/cloud/centurylink/clc_blueprint_package.py index 058c59899d..7cef698f4e 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_blueprint_package.py +++ b/lib/ansible/modules/cloud/centurylink/clc_blueprint_package.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -99,6 +87,7 @@ server_ids: __version__ = '${version}' +import os from distutils.version import LooseVersion try: @@ -121,6 +110,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcBlueprintPackage: @@ -302,6 +293,6 @@ def main(): clc_blueprint_package = ClcBlueprintPackage(module) clc_blueprint_package.process_request() -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py b/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py index 680d3de905..de80b7f00d 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py +++ b/lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -177,6 +165,7 @@ firewall_policy: __version__ = '${version}' +import os import urlparse from time import sleep from distutils.version import LooseVersion @@ -190,7 +179,6 @@ else: try: import clc as clc_sdk - from clc import CLCException from clc import APIFailedResponse except ImportError: CLC_FOUND = False @@ -198,6 +186,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcFirewallPolicy: @@ -597,6 +587,6 @@ def main(): clc_firewall = ClcFirewallPolicy(module) clc_firewall.process_request() -from ansible.module_utils.basic import * # pylint: disable=W0614 + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_group.py b/lib/ansible/modules/cloud/centurylink/clc_group.py index 4b5238d2ea..219f20edb1 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_group.py +++ b/lib/ansible/modules/cloud/centurylink/clc_group.py @@ -2,22 +2,11 @@ # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py b/lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py index 25eb184855..91ef5b1723 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py +++ b/lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py @@ -1,23 +1,12 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink # -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -222,6 +211,8 @@ loadbalancer: __version__ = '${version}' +import json +import os from time import sleep from distutils.version import LooseVersion @@ -245,6 +236,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcLoadBalancer: @@ -941,6 +934,6 @@ def main(): clc_loadbalancer = ClcLoadBalancer(module) clc_loadbalancer.process_request() -from ansible.module_utils.basic import * # pylint: disable=W0614 + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_modify_server.py b/lib/ansible/modules/cloud/centurylink/clc_modify_server.py index 7b2d5888e2..e76f3c0573 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_modify_server.py +++ b/lib/ansible/modules/cloud/centurylink/clc_modify_server.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -330,6 +318,8 @@ servers: __version__ = '${version}' +import json +import os from distutils.version import LooseVersion try: @@ -353,6 +343,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcModifyServer: clc = clc_sdk @@ -977,6 +969,6 @@ def main(): clc_modify_server = ClcModifyServer(module) clc_modify_server.process_request() -from ansible.module_utils.basic import * # pylint: disable=W0614 + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_publicip.py b/lib/ansible/modules/cloud/centurylink/clc_publicip.py index aebe63ad5a..1eb2412080 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_publicip.py +++ b/lib/ansible/modules/cloud/centurylink/clc_publicip.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/centurylink/clc_server.py b/lib/ansible/modules/cloud/centurylink/clc_server.py index 0aa79a9c81..78c1515421 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_server.py +++ b/lib/ansible/modules/cloud/centurylink/clc_server.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -464,7 +452,9 @@ servers: __version__ = '${version}' -from time import sleep +import json +import os +import time from distutils.version import LooseVersion try: @@ -488,6 +478,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcServer: clc = clc_sdk @@ -732,10 +724,8 @@ class ClcServer: location = account.data.get('primaryDataCenter') data_center = clc.v2.Datacenter(location) return data_center - except CLCException as ex: - module.fail_json( - msg=str( - "Unable to find location: {0}".format(location))) + except CLCException: + module.fail_json(msg="Unable to find location: {0}".format(location)) @staticmethod def _find_alias(clc, module): @@ -1565,7 +1555,7 @@ class ClcServer: if retries == 0: return module.fail_json( msg='Unable to reach the CLC API after 5 attempts') - sleep(back_out) + time.sleep(back_out) back_out *= 2 @staticmethod @@ -1588,6 +1578,6 @@ def main(): clc_server = ClcServer(module) clc_server.process_request() -from ansible.module_utils.basic import * # pylint: disable=W0614 + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/centurylink/clc_server_snapshot.py b/lib/ansible/modules/cloud/centurylink/clc_server_snapshot.py index 6484b40dd5..771ab8e1f4 100644 --- a/lib/ansible/modules/cloud/centurylink/clc_server_snapshot.py +++ b/lib/ansible/modules/cloud/centurylink/clc_server_snapshot.py @@ -1,23 +1,11 @@ #!/usr/bin/python - # # Copyright (c) 2015 CenturyLink -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -112,6 +100,7 @@ server_ids: __version__ = '${version}' +import os from distutils.version import LooseVersion try: @@ -134,6 +123,8 @@ except ImportError: else: CLC_FOUND = True +from ansible.module_utils.basic import AnsibleModule + class ClcSnapshot: @@ -413,6 +404,6 @@ def main(): clc_snapshot = ClcSnapshot(module) clc_snapshot.process_request() -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gc_storage.py b/lib/ansible/modules/cloud/google/gc_storage.py index ee9cf19d43..eff76d0078 100644 --- a/lib/ansible/modules/cloud/google/gc_storage.py +++ b/lib/ansible/modules/cloud/google/gc_storage.py @@ -1,18 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible # -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -146,8 +139,6 @@ EXAMPLES = ''' ''' import os -import urlparse -import hashlib try: import boto @@ -155,6 +146,9 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule + + def grant_check(module, gs, obj): try: acp = obj.get_acl() @@ -461,7 +455,5 @@ def main(): module.fail_json(msg="Bucket and Object parameters must be set", failed=True) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcdns_record.py b/lib/ansible/modules/cloud/google/gcdns_record.py index d0c2d980a2..b8be8df6c1 100644 --- a/lib/ansible/modules/cloud/google/gcdns_record.py +++ b/lib/ansible/modules/cloud/google/gcdns_record.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2015 CallFire Inc. -# -# This file is part of Ansible. -# -# 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 -# the Free Software Foundation, either version 3 of the License, or -# (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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ################################################################################ @@ -333,6 +322,9 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gcdns import gcdns_connect + ################################################################################ # Constants @@ -788,8 +780,5 @@ def main(): module.exit_json(changed=changed, diff=diff, **json_output) -from ansible.module_utils.basic import * -from ansible.module_utils.gcdns import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcdns_zone.py b/lib/ansible/modules/cloud/google/gcdns_zone.py index c642812159..dc3de3f641 100644 --- a/lib/ansible/modules/cloud/google/gcdns_zone.py +++ b/lib/ansible/modules/cloud/google/gcdns_zone.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2015 CallFire Inc. -# -# This file is part of Ansible. -# -# 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 -# the Free Software Foundation, either version 3 of the License, or -# (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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ################################################################################ @@ -139,6 +128,9 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gcdns import gcdns_connect + ################################################################################ # Constants @@ -379,8 +371,5 @@ def main(): module.exit_json(changed=changed, diff=diff, **json_output) -from ansible.module_utils.basic import * -from ansible.module_utils.gcdns import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce.py b/lib/ansible/modules/cloud/google/gce.py index 0480e478ac..cf5ff9dbeb 100644 --- a/lib/ansible/modules/cloud/google/gce.py +++ b/lib/ansible/modules/cloud/google/gce.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2013 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -302,6 +292,12 @@ EXAMPLES = ''' import socket +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False + try: import libcloud from libcloud.compute.types import Provider @@ -314,11 +310,10 @@ try: except ImportError: HAS_LIBCLOUD = False -try: - from ast import literal_eval - HAS_PYTHON26 = True -except ImportError: - HAS_PYTHON26 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect, unexpected_error_msg +from ansible.module_utils.gcp import get_valid_location +from ansible.module_utils.six.moves import reduce def get_instance_info(inst): @@ -390,7 +385,6 @@ def create_instances(module, gce, instance_names, number, lc_zone): subnetwork = module.params.get('subnetwork') persistent_boot_disk = module.params.get('persistent_boot_disk') disks = module.params.get('disks') - state = module.params.get('state') tags = module.params.get('tags') ip_forward = module.params.get('ip_forward') external_ip = module.params.get('external_ip') @@ -398,7 +392,6 @@ def create_instances(module, gce, instance_names, number, lc_zone): preemptible = module.params.get('preemptible') disk_size = module.params.get('disk_size') service_account_permissions = module.params.get('service_account_permissions') - service_account_email = module.params.get('service_account_email') if external_ip == "none": instance_external_ip = None @@ -657,19 +650,12 @@ def main(): gce = gce_connect(module) - image = module.params.get('image') instance_names = module.params.get('instance_names') - machine_type = module.params.get('machine_type') - metadata = module.params.get('metadata') name = module.params.get('name') number = module.params.get('num_instances') - network = module.params.get('network') subnetwork = module.params.get('subnetwork') - persistent_boot_disk = module.params.get('persistent_boot_disk') state = module.params.get('state') - tags = module.params.get('tags') zone = module.params.get('zone') - ip_forward = module.params.get('ip_forward') preemptible = module.params.get('preemptible') changed = False @@ -745,9 +731,5 @@ class LazyDiskImage: return self.image -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gce import * -from ansible.module_utils.gcp import get_valid_location if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_eip.py b/lib/ansible/modules/cloud/google/gce_eip.py index f6b4753a28..fe3ee319e9 100644 --- a/lib/ansible/modules/cloud/google/gce_eip.py +++ b/lib/ansible/modules/cloud/google/gce_eip.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -91,6 +81,12 @@ region: USER_AGENT_VERSION = 'v1' USER_AGENT_PRODUCT = 'Ansible-gce_eip' +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False + try: import libcloud from libcloud.compute.types import Provider @@ -103,11 +99,9 @@ try: except ImportError: HAS_LIBCLOUD = False -try: - from ast import literal_eval - HAS_PYTHON26 = True -except ImportError: - HAS_PYTHON26 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gcp import gcp_connect + def get_address(gce, name, region): """ @@ -226,8 +220,6 @@ def main(): json_output.update(params) module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gcp import gcp_connect + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_img.py b/lib/ansible/modules/cloud/google/gce_img.py index bfbf0cf970..5a4a69823a 100644 --- a/lib/ansible/modules/cloud/google/gce_img.py +++ b/lib/ansible/modules/cloud/google/gce_img.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2015 Google Inc. All Rights Reserved. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + """An Ansible module to utilize GCE image resources.""" @@ -230,5 +220,6 @@ def main(): module.exit_json(changed=changed, name=name) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_instance_template.py b/lib/ansible/modules/cloud/google/gce_instance_template.py index 95d0755875..edd30fd9e9 100644 --- a/lib/ansible/modules/cloud/google/gce_instance_template.py +++ b/lib/ansible/modules/cloud/google/gce_instance_template.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -243,8 +235,12 @@ EXAMPLES = ''' RETURN = ''' ''' -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.gce import gce_connect +import traceback +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False try: import libcloud @@ -258,11 +254,9 @@ try: except ImportError: HAS_LIBCLOUD = False -try: - from ast import literal_eval - HAS_PYTHON26 = True -except ImportError: - HAS_PYTHON26 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect +from ansible.module_utils._text import to_native def get_info(inst): @@ -294,7 +288,6 @@ def create_instance_template(module, gce): subnetwork_region = module.params.get('subnetwork_region') can_ip_forward = module.params.get('can_ip_forward') external_ip = module.params.get('external_ip') - service_account_email = module.params.get('service_account_email') service_account_permissions = module.params.get( 'service_account_permissions') on_host_maintenance = module.params.get('on_host_maintenance') @@ -303,7 +296,6 @@ def create_instance_template(module, gce): tags = module.params.get('tags') metadata = module.params.get('metadata') description = module.params.get('description') - disks = module.params.get('disks') disks_gce_struct = module.params.get('disks_gce_struct') changed = False @@ -467,8 +459,9 @@ def delete_instance_template(module, gce): try: instance = gce.ex_get_instancetemplate(name) current_state = "present" - except GoogleBaseError as err: - json_data = dict(msg='instance template not exists') + except GoogleBaseError as e: + json_data = dict(msg='instance template not exists: %s' % to_native(e), + exception=traceback.format_exc()) if current_state == "present": rc = instance.destroy() @@ -519,26 +512,26 @@ def check_if_system_state_would_be_changed(module, gce): state = module.params.get("state") name = module.params.get("name") - instance = None try: - instance = gce.ex_get_instancetemplate(name) + gce.ex_get_instancetemplate(name) current_state = "present" - except GoogleBaseError as err: - module.fail_json(msg='GCE get instancetemplate problem') + except GoogleBaseError as e: + module.fail_json(msg='GCE get instancetemplate problem: %s' % to_native(e), + exception=traceback.format_exc()) if current_state != state: changed = True if current_state == "absent": if changed: - output = 'instance template {} will be created'.format(name) + output = 'instance template {0} will be created'.format(name) else: - output = 'nothing to do for instance template {} '.format(name) + output = 'nothing to do for instance template {0} '.format(name) if current_state == "present": if changed: - output = 'instance template {} will be destroyed'.format(name) + output = 'instance template {0} will be destroyed'.format(name) else: - output = 'nothing to do for instance template {} '.format(name) + output = 'nothing to do for instance template {0} '.format(name) return (changed, output) @@ -587,8 +580,8 @@ def main(): try: gce = gce_connect(module) - except GoogleBaseError as err: - module.fail_json(msg='GCE Connexion failed') + except GoogleBaseError as e: + module.fail_json(msg='GCE Connexion failed %s' % to_native(e), exception=traceback.format_exc()) if module.check_mode: (changed, output) = check_if_system_state_would_be_changed(module, gce) diff --git a/lib/ansible/modules/cloud/google/gce_labels.py b/lib/ansible/modules/cloud/google/gce_labels.py index 77e84c2f5f..e75ec8c70d 100644 --- a/lib/ansible/modules/cloud/google/gce_labels.py +++ b/lib/ansible/modules/cloud/google/gce_labels.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -146,10 +136,10 @@ try: except ImportError: HAS_PYTHON26 = False -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import check_params, get_google_api_client, GCPUtils + UA_PRODUCT = 'ansible-gce_labels' UA_VERSION = '0.0.1' GCE_API_VERSION = 'v1' @@ -329,5 +319,6 @@ def main(): module.exit_json(**json_output) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_lb.py b/lib/ansible/modules/cloud/google/gce_lb.py index 82c35fea03..ef7c4347a9 100644 --- a/lib/ansible/modules/cloud/google/gce_lb.py +++ b/lib/ansible/modules/cloud/google/gce_lb.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2013 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -174,6 +164,9 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import USER_AGENT_PRODUCT, USER_AGENT_VERSION, gce_connect, unexpected_error_msg + def main(): module = AnsibleModule( @@ -342,9 +335,6 @@ def main(): json_output['changed'] = changed module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gce import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_mig.py b/lib/ansible/modules/cloud/google/gce_mig.py index 683d5a42cb..3ee2dc3ae8 100644 --- a/lib/ansible/modules/cloud/google/gce_mig.py +++ b/lib/ansible/modules/cloud/google/gce_mig.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2016 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -272,7 +262,11 @@ updated_named_ports: sample: true ''' -import socket +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False try: import libcloud @@ -286,11 +280,8 @@ try: except ImportError: HAS_LIBCLOUD = False -try: - from ast import literal_eval - HAS_PYTHON26 = True -except ImportError: - HAS_PYTHON26 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect def _check_params(params, field_list): @@ -902,8 +893,6 @@ def main(): json_output.update(params) module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gce import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_net.py b/lib/ansible/modules/cloud/google/gce_net.py index d98c6d2171..ca6066791c 100644 --- a/lib/ansible/modules/cloud/google/gce_net.py +++ b/lib/ansible/modules/cloud/google/gce_net.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2013 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -281,6 +271,10 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect, unexpected_error_msg + + def format_allowed_section(allowed): """Format each section of the allowed list""" if allowed.count(":") == 0: @@ -552,9 +546,6 @@ def main(): json_output['changed'] = changed module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gce import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_pd.py b/lib/ansible/modules/cloud/google/gce_pd.py index a7a8d9901e..f4176a05a1 100644 --- a/lib/ansible/modules/cloud/google/gce_pd.py +++ b/lib/ansible/modules/cloud/google/gce_pd.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2013 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -161,6 +151,9 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect, unexpected_error_msg + def main(): module = AnsibleModule( @@ -318,9 +311,6 @@ def main(): json_output['changed'] = changed module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gce import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gce_snapshot.py b/lib/ansible/modules/cloud/google/gce_snapshot.py index 2de14023ca..4663a17ac7 100644 --- a/lib/ansible/modules/cloud/google/gce_snapshot.py +++ b/lib/ansible/modules/cloud/google/gce_snapshot.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -131,9 +123,6 @@ snapshots_absent: sample: "[disk0-example-snapshot, disk1-example-snapshot]" ''' -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.gce import gce_connect - try: from libcloud.compute.types import Provider _ = Provider.GCE @@ -141,6 +130,9 @@ try: except ImportError: HAS_LIBCLOUD = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gce import gce_connect + def find_snapshot(volume, name): ''' diff --git a/lib/ansible/modules/cloud/google/gce_tag.py b/lib/ansible/modules/cloud/google/gce_tag.py index a65dbe8147..39fbe558b9 100644 --- a/lib/ansible/modules/cloud/google/gce_tag.py +++ b/lib/ansible/modules/cloud/google/gce_tag.py @@ -1,18 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible # -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -130,6 +123,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gce import gce_connect + def _union_items(baselist, comparelist): """Combine two lists, removing duplicates.""" return list(set(baselist) | set(comparelist)) @@ -145,7 +139,6 @@ def _get_changed_items(baselist, comparelist): def modify_tags(gce, module, node, tags, state='present'): """Modify tags on an instance.""" - zone = node.extra['zone'].name existing_tags = node.extra['tags'] tags = [x.lower() for x in tags] tags_changed = [] @@ -236,5 +229,6 @@ def main(): else: module.exit_json(changed=changed, instance_name=instance_name, tags=tags_changed, zone=zone) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcp_backend_service.py b/lib/ansible/modules/cloud/google/gcp_backend_service.py index 504d49ec36..7d71ca83e1 100644 --- a/lib/ansible/modules/cloud/google/gcp_backend_service.py +++ b/lib/ansible/modules/cloud/google/gcp_backend_service.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -180,6 +170,11 @@ timeout: sample: "myhttpport" ''' +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False try: import libcloud @@ -193,13 +188,6 @@ try: except ImportError: HAS_LIBCLOUD = False -try: - from ast import literal_eval - HAS_PYTHON26 = True -except ImportError: - HAS_PYTHON26 = False - -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gce import gce_connect from ansible.module_utils.gcp import check_params @@ -416,5 +404,6 @@ def main(): json_output.update(params) module.exit_json(**json_output) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcp_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_forwarding_rule.py index d00611d58d..55f0787bb3 100644 --- a/lib/ansible/modules/cloud/google/gcp_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_forwarding_rule.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -130,11 +120,10 @@ state: sample: present ''' - -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import get_google_api_client, GCPUtils + USER_AGENT_PRODUCT = 'ansible-forwarding_rule' USER_AGENT_VERSION = '0.0.1' @@ -270,7 +259,7 @@ def update_global_forwarding_rule(client, forwarding_rule, params, name, project """ gcp_dict = _build_global_forwarding_rule_dict(params, project_id) - ans = GCPUtils.are_params_equal(forwarding_rule, gcp_dict) + GCPUtils.are_params_equal(forwarding_rule, gcp_dict) if forwarding_rule['target'] == gcp_dict['target']: return (False, 'no update necessary') diff --git a/lib/ansible/modules/cloud/google/gcp_healthcheck.py b/lib/ansible/modules/cloud/google/gcp_healthcheck.py index 0b3ae9355d..7e53a3020a 100644 --- a/lib/ansible/modules/cloud/google/gcp_healthcheck.py +++ b/lib/ansible/modules/cloud/google/gcp_healthcheck.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -197,10 +187,9 @@ healthcheck: sample: { "name": "my-hc", "port": 443, "requestPath": "/foo" } ''' - -# import module snippets from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.gcp import check_params, get_google_api_client, GCPUtils +from ansible.module_utils.gcp import get_google_api_client, GCPUtils + USER_AGENT_PRODUCT = 'ansible-healthcheck' USER_AGENT_VERSION = '0.0.1' diff --git a/lib/ansible/modules/cloud/google/gcp_target_proxy.py b/lib/ansible/modules/cloud/google/gcp_target_proxy.py index a508f2baf8..0c73c7eaca 100644 --- a/lib/ansible/modules/cloud/google/gcp_target_proxy.py +++ b/lib/ansible/modules/cloud/google/gcp_target_proxy.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -96,11 +86,10 @@ target_proxy: sample: { "name": "my-target-proxy", "urlMap": "..." } ''' - -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import get_google_api_client, GCPUtils + USER_AGENT_PRODUCT = 'ansible-target_proxy' USER_AGENT_VERSION = '0.0.1' @@ -227,7 +216,7 @@ def update_target_http_proxy(client, target_proxy, params, name, project_id): """ gcp_dict = _build_target_proxy_dict(params, project_id) - ans = GCPUtils.are_params_equal(target_proxy, gcp_dict) + GCPUtils.are_params_equal(target_proxy, gcp_dict) if target_proxy['urlMap'] == gcp_dict['urlMap']: return (False, 'no update necessary') diff --git a/lib/ansible/modules/cloud/google/gcp_url_map.py b/lib/ansible/modules/cloud/google/gcp_url_map.py index eb4620b67b..549aa4103f 100644 --- a/lib/ansible/modules/cloud/google/gcp_url_map.py +++ b/lib/ansible/modules/cloud/google/gcp_url_map.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -146,8 +136,11 @@ url_map: sample: { "name": "my-url-map", "hostRules": [...], "pathMatchers": [...] } ''' - -from ast import literal_eval +try: + from ast import literal_eval + HAS_PYTHON26 = True +except ImportError: + HAS_PYTHON26 = False from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import check_params, get_google_api_client, GCPUtils diff --git a/lib/ansible/modules/cloud/google/gcpubsub.py b/lib/ansible/modules/cloud/google/gcpubsub.py index 4c46300346..19773a103f 100644 --- a/lib/ansible/modules/cloud/google/gcpubsub.py +++ b/lib/ansible/modules/cloud/google/gcpubsub.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2016 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -186,9 +176,6 @@ topic: type: str sample: "mytopic" ''' -CLOUD_CLIENT = 'google-cloud-pubsub' -CLOUD_CLIENT_MINIMUM_VERSION = '0.22.0' -CLOUD_CLIENT_USER_AGENT = 'ansible-pubsub-0.1' try: from ast import literal_eval @@ -202,6 +189,14 @@ try: except ImportError as e: HAS_GOOGLE_CLOUD_PUBSUB = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gcp import check_min_pkg_version, get_google_cloud_credentials + + +CLOUD_CLIENT = 'google-cloud-pubsub' +CLOUD_CLIENT_MINIMUM_VERSION = '0.22.0' +CLOUD_CLIENT_USER_AGENT = 'ansible-pubsub-0.1' + def publish_messages(message_list, topic): with topic.batch() as batch: @@ -336,8 +331,6 @@ def main(): json_output.update(mod_params) module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gcp import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcpubsub_facts.py b/lib/ansible/modules/cloud/google/gcpubsub_facts.py index f0404f593d..43effe5376 100644 --- a/lib/ansible/modules/cloud/google/gcpubsub_facts.py +++ b/lib/ansible/modules/cloud/google/gcpubsub_facts.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2016 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -100,6 +90,11 @@ try: HAS_GOOGLE_CLOUD_PUBSUB = True except ImportError as e: HAS_GOOGLE_CLOUD_PUBSUB = False + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.gcp import check_min_pkg_version, get_google_cloud_credentials + + def list_func(data, member='name'): """Used for state=list.""" return [getattr(x, member) for x in data] @@ -148,8 +143,6 @@ def main(): json_output.update(mod_params) module.exit_json(**json_output) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.gcp import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcspanner.py b/lib/ansible/modules/cloud/google/gcspanner.py index eae2843525..fbfd5f37dc 100644 --- a/lib/ansible/modules/cloud/google/gcspanner.py +++ b/lib/ansible/modules/cloud/google/gcspanner.py @@ -1,20 +1,10 @@ #!/usr/bin/python # Copyright 2017 Google Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -141,6 +131,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import check_min_pkg_version, get_google_cloud_credentials from ansible.module_utils.six import string_types + CLOUD_CLIENT = 'google-cloud-spanner' CLOUD_CLIENT_MINIMUM_VERSION = '0.23.0' CLOUD_CLIENT_USER_AGENT = 'ansible-spanner-0.1' @@ -178,7 +169,7 @@ def instance_update(instance): try: instance.update() - except ValueError as e: + except ValueError: # The ValueError here is the one we 'expect'. pass @@ -285,5 +276,6 @@ def main(): json_output.update(mod_params) module.exit_json(**json_output) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax.py b/lib/ansible/modules/cloud/rackspace/rax.py index 201bca5695..82a825e885 100644 --- a/lib/ansible/modules/cloud/rackspace/rax.py +++ b/lib/ansible/modules/cloud/rackspace/rax.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -240,8 +230,8 @@ EXAMPLES = ''' register: rax ''' -import os import json +import os import re import time diff --git a/lib/ansible/modules/cloud/rackspace/rax_cbs.py b/lib/ansible/modules/cloud/rackspace/rax_cbs.py index ae66651d31..9ddbb78fdf 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_cbs.py +++ b/lib/ansible/modules/cloud/rackspace/rax_cbs.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -120,6 +110,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (VOLUME_STATUS, rax_argument_spec, rax_find_image, rax_find_volume, + rax_required_together, rax_to_dict, setup_rax_module) + def cloud_block_storage(module, state, name, description, meta, size, snapshot_id, volume_type, wait, wait_timeout, @@ -160,7 +154,7 @@ def cloud_block_storage(module, state, name, description, meta, size, module.fail_json(msg='%s' % e.message) else: if wait: - attempts = wait_timeout / 5 + attempts = wait_timeout // 5 pyrax.utils.wait_for_build(volume, interval=5, attempts=attempts) @@ -233,11 +227,6 @@ def main(): snapshot_id, volume_type, wait, wait_timeout, image) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_cbs_attachments.py b/lib/ansible/modules/cloud/rackspace/rax_cbs_attachments.py index 9193ae0acc..78fdb50263 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_cbs_attachments.py +++ b/lib/ansible/modules/cloud/rackspace/rax_cbs_attachments.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -95,6 +85,16 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (NON_CALLABLES, + rax_argument_spec, + rax_find_server, + rax_find_volume, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def cloud_block_storage_attachments(module, state, volume, server, device, wait, wait_timeout): @@ -141,7 +141,7 @@ def cloud_block_storage_attachments(module, state, volume, server, device, if volume.status == 'error': result['msg'] = '%s failed to build' % volume.id elif wait: - attempts = wait_timeout / 5 + attempts = wait_timeout // 5 pyrax.utils.wait_until(volume, 'status', 'in-use', interval=5, attempts=attempts) @@ -219,11 +219,6 @@ def main(): cloud_block_storage_attachments(module, state, volume, server, device, wait, wait_timeout) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_cdb.py b/lib/ansible/modules/cloud/rackspace/rax_cdb.py index 15b48c7a69..b0330cd004 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_cdb.py +++ b/lib/ansible/modules/cloud/rackspace/rax_cdb.py @@ -1,21 +1,11 @@ #!/usr/bin/python -tt -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -98,6 +88,9 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, rax_to_dict, setup_rax_module + def find_instance(name): @@ -258,11 +251,5 @@ def main(): rax_cdb(module, state, name, flavor, volume, cdb_type, cdb_version, wait, wait_timeout) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_cdb_database.py b/lib/ansible/modules/cloud/rackspace/rax_cdb_database.py index c0206ea9b5..8d72c64c65 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_cdb_database.py +++ b/lib/ansible/modules/cloud/rackspace/rax_cdb_database.py @@ -1,21 +1,11 @@ #!/usr/bin/python -tt -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -73,6 +63,9 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, rax_to_dict, setup_rax_module + def find_database(instance, name): try: @@ -172,11 +165,5 @@ def main(): rax_cdb_database(module, state, cdb_id, name, character_set, collate) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_cdb_user.py b/lib/ansible/modules/cloud/rackspace/rax_cdb_user.py index 955ffe6a60..90aeafe4d0 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_cdb_user.py +++ b/lib/ansible/modules/cloud/rackspace/rax_cdb_user.py @@ -1,21 +1,11 @@ #!/usr/bin/python -tt -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -82,6 +72,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, rax_to_dict, setup_rax_module + def find_user(instance, name): try: @@ -210,18 +204,12 @@ def main(): name = module.params.get('db_username') password = module.params.get('db_password') databases = module.params.get('databases') - host = unicode(module.params.get('host')) + host = to_text(module.params.get('host'), errors='surrogate_or_strict') state = module.params.get('state') setup_rax_module(module, pyrax) rax_cdb_user(module, state, cdb_id, name, password, databases, host) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_clb.py b/lib/ansible/modules/cloud/rackspace/rax_clb.py index 00e043dd0e..577e6ffe43 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_clb.py +++ b/lib/ansible/modules/cloud/rackspace/rax_clb.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -144,6 +134,15 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (CLB_ALGORITHMS, + CLB_PROTOCOLS, + rax_argument_spec, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol, vip_type, timeout, wait, wait_timeout, vip_id): @@ -221,7 +220,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol, 'be changed') if wait: - attempts = wait_timeout / 5 + attempts = wait_timeout // 5 pyrax.utils.wait_for_build(balancer, interval=5, attempts=attempts) balancer.get() @@ -251,7 +250,7 @@ def cloud_load_balancer(module, state, name, meta, algorithm, port, protocol, instance = rax_to_dict(balancer, 'clb') if wait: - attempts = wait_timeout / 5 + attempts = wait_timeout // 5 pyrax.utils.wait_until(balancer, 'status', ('DELETED'), interval=5, attempts=attempts) else: @@ -305,11 +304,5 @@ def main(): vip_type, timeout, wait, wait_timeout, vip_id) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_clb_nodes.py b/lib/ansible/modules/cloud/rackspace/rax_clb_nodes.py index b395b2b346..ba0fff89de 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_clb_nodes.py +++ b/lib/ansible/modules/cloud/rackspace/rax_clb_nodes.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -121,12 +111,17 @@ EXAMPLES = ''' credentials: /path/to/credentials ''' +import os + try: import pyrax HAS_PYRAX = True except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_clb_node_to_dict, rax_required_together, setup_rax_module + def _activate_virtualenv(path): path = os.path.expanduser(path) @@ -276,11 +271,5 @@ def main(): module.exit_json(changed=True, state=state, **kwargs) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_clb_ssl.py b/lib/ansible/modules/cloud/rackspace/rax_clb_ssl.py index a2e774293c..395dace6b1 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_clb_ssl.py +++ b/lib/ansible/modules/cloud/rackspace/rax_clb_ssl.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -104,6 +94,14 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, + rax_find_loadbalancer, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def cloud_load_balancer_ssl(module, loadbalancer, state, enabled, private_key, certificate, intermediate_certificate, secure_port, secure_traffic_only, https_redirect, @@ -121,7 +119,7 @@ def cloud_load_balancer_ssl(module, loadbalancer, state, enabled, private_key, else: certificate = certificate.strip() - attempts = wait_timeout / 5 + attempts = wait_timeout // 5 # Locate the load balancer. @@ -268,8 +266,6 @@ def main(): https_redirect, wait, wait_timeout ) -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_dns.py b/lib/ansible/modules/cloud/rackspace/rax_dns.py index 9130252c2c..5d1096fca0 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_dns.py +++ b/lib/ansible/modules/cloud/rackspace/rax_dns.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -77,6 +67,13 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def rax_dns(module, comment, email, name, state, ttl): changed = False @@ -170,11 +167,5 @@ def main(): rax_dns(module, comment, email, name, state, ttl) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_dns_record.py b/lib/ansible/modules/cloud/rackspace/rax_dns_record.py index a3d4639cae..14710b5c99 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_dns_record.py +++ b/lib/ansible/modules/cloud/rackspace/rax_dns_record.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -131,6 +121,15 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, + rax_find_loadbalancer, + rax_find_server, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def rax_dns_record_ptr(module, data=None, comment=None, loadbalancer=None, name=None, server=None, state='present', ttl=7200): @@ -345,11 +344,5 @@ def main(): record_type=record_type, state=state, ttl=ttl) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_facts.py b/lib/ansible/modules/cloud/rackspace/rax_facts.py index 0a3cae8626..762e088d35 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_facts.py +++ b/lib/ansible/modules/cloud/rackspace/rax_facts.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -66,6 +56,13 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def rax_facts(module, address, name, server_id): changed = False @@ -143,11 +140,5 @@ def main(): rax_facts(module, address, name, server_id) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_files.py b/lib/ansible/modules/cloud/rackspace/rax_files.py index c7b3865bff..4b698c7d2f 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_files.py +++ b/lib/ansible/modules/cloud/rackspace/rax_files.py @@ -1,24 +1,12 @@ #!/usr/bin/python # (c) 2013, Paul Durivage -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -163,6 +151,10 @@ try: except ImportError as e: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + EXIT_DICT = dict(success=True) META_PREFIX = 'x-container-meta-' @@ -391,9 +383,5 @@ def main(): private, web_index, web_error) -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_files_objects.py b/lib/ansible/modules/cloud/rackspace/rax_files_objects.py index f708c7fb5d..55b482d926 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_files_objects.py +++ b/lib/ansible/modules/cloud/rackspace/rax_files_objects.py @@ -1,24 +1,12 @@ #!/usr/bin/python # (c) 2013, Paul Durivage -# -# This file is part of Ansible. -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -232,12 +220,18 @@ EXAMPLES = ''' type: meta ''' +import os + try: import pyrax HAS_PYRAX = True except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + EXIT_DICT = dict(success=False) META_PREFIX = 'x-object-meta-' @@ -619,9 +613,5 @@ def main(): cloudfiles(module, container, src, dest, method, typ, meta, clear_meta, structure, expires) -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_identity.py b/lib/ansible/modules/cloud/rackspace/rax_identity.py index 71976e6dbd..654caf7c47 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_identity.py +++ b/lib/ansible/modules/cloud/rackspace/rax_identity.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -61,6 +51,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, rax_required_together, rax_to_dict, + setup_rax_module) + def cloud_identity(module, state, identity): instance = dict( @@ -106,11 +100,6 @@ def main(): cloud_identity(module, state, pyrax.identity) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_keypair.py b/lib/ansible/modules/cloud/rackspace/rax_keypair.py index 31ca75f38e..cc38f35fc4 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_keypair.py +++ b/lib/ansible/modules/cloud/rackspace/rax_keypair.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -88,6 +78,7 @@ EXAMPLES = ''' region: DFW register: keypair ''' +import os try: import pyrax @@ -95,6 +86,13 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (rax_argument_spec, + rax_required_together, + rax_to_dict, + setup_rax_module, + ) + def rax_keypair(module, name, public_key, state): changed = False @@ -171,11 +169,5 @@ def main(): rax_keypair(module, name, public_key, state) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_meta.py b/lib/ansible/modules/cloud/rackspace/rax_meta.py index 7257e6341e..dca1c1ea50 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_meta.py +++ b/lib/ansible/modules/cloud/rackspace/rax_meta.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} diff --git a/lib/ansible/modules/cloud/rackspace/rax_mon_alarm.py b/lib/ansible/modules/cloud/rackspace/rax_mon_alarm.py index f1e8bcb2fb..cdd0f5a60e 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_mon_alarm.py +++ b/lib/ansible/modules/cloud/rackspace/rax_mon_alarm.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -107,6 +97,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + def alarm(module, state, label, entity_id, check_id, notification_plan_id, criteria, disabled, metadata): @@ -224,10 +218,5 @@ def main(): criteria, disabled, metadata) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# Invoke the module. if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_mon_check.py b/lib/ansible/modules/cloud/rackspace/rax_mon_check.py index dcd78e0a73..79e91f9829 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_mon_check.py +++ b/lib/ansible/modules/cloud/rackspace/rax_mon_check.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -142,6 +132,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + def cloud_check(module, state, entity_id, label, check_type, monitoring_zones_poll, target_hostname, target_alias, details, disabled, metadata, period, timeout): @@ -310,10 +304,5 @@ def main(): disabled, metadata, period, timeout) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# Invoke the module. if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_mon_entity.py b/lib/ansible/modules/cloud/rackspace/rax_mon_entity.py index e067957450..c0867f1869 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_mon_entity.py +++ b/lib/ansible/modules/cloud/rackspace/rax_mon_entity.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -86,6 +76,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + def cloud_monitoring(module, state, label, agent_id, named_ip_addresses, metadata): @@ -189,10 +183,6 @@ def main(): cloud_monitoring(module, state, label, agent_id, named_ip_addresses, metadata) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * -# Invoke the module. if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_mon_notification.py b/lib/ansible/modules/cloud/rackspace/rax_mon_notification.py index c54ba5b324..07e184876d 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_mon_notification.py +++ b/lib/ansible/modules/cloud/rackspace/rax_mon_notification.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -79,6 +69,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + def notification(module, state, label, notification_type, details): if len(label) < 1 or len(label) > 255: @@ -173,10 +167,6 @@ def main(): notification(module, state, label, notification_type, details) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * -# Invoke the module. if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py b/lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py index 7d3f9e4fd5..f7cc8bb40a 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py +++ b/lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -83,6 +73,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + + def notification_plan(module, state, label, critical_state, warning_state, ok_state): if len(label) < 1 or len(label) > 255: @@ -178,10 +172,6 @@ def main(): notification_plan(module, state, label, critical_state, warning_state, ok_state) -# Import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * -# Invoke the module. if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_network.py b/lib/ansible/modules/cloud/rackspace/rax_network.py index 47b7c7ddab..13dd94756e 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_network.py +++ b/lib/ansible/modules/cloud/rackspace/rax_network.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -70,6 +60,9 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + def cloud_network(module, state, label, cidr): changed = False @@ -143,11 +136,5 @@ def main(): cloud_network(module, state, label, cidr) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_queue.py b/lib/ansible/modules/cloud/rackspace/rax_queue.py index 074ac8c6fc..2d44488e2d 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_queue.py +++ b/lib/ansible/modules/cloud/rackspace/rax_queue.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -68,6 +58,9 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module + def cloud_queue(module, state, name): for arg in (state, name): @@ -144,11 +137,5 @@ def main(): cloud_queue(module, state, name) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -### invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/rackspace/rax_scaling_group.py b/lib/ansible/modules/cloud/rackspace/rax_scaling_group.py index 6975ed4a5c..0e3b03ebcf 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_scaling_group.py +++ b/lib/ansible/modules/cloud/rackspace/rax_scaling_group.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} diff --git a/lib/ansible/modules/cloud/rackspace/rax_scaling_policy.py b/lib/ansible/modules/cloud/rackspace/rax_scaling_policy.py index 121e86ce31..5a7b7c0713 100644 --- a/lib/ansible/modules/cloud/rackspace/rax_scaling_policy.py +++ b/lib/ansible/modules/cloud/rackspace/rax_scaling_policy.py @@ -1,21 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + -# This is a DOCUMENTATION stub specific to this module, it extends -# a documentation fragment located in ansible.utils.module_docs_fragments ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -129,6 +119,10 @@ try: except ImportError: HAS_PYRAX = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.rax import (UUID, rax_argument_spec, rax_required_together, rax_to_dict, + setup_rax_module) + def rax_asp(module, at=None, change=0, cron=None, cooldown=300, desired_capacity=0, is_percent=False, name=None, @@ -280,11 +274,5 @@ def main(): state=state) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.rax import * - -# invoke the module - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vca_fw.py b/lib/ansible/modules/cloud/vmware/vca_fw.py index 6d56634b25..c981823027 100644 --- a/lib/ansible/modules/cloud/vmware/vca_fw.py +++ b/lib/ansible/modules/cloud/vmware/vca_fw.py @@ -1,21 +1,10 @@ #!/usr/bin/python # Copyright (c) 2015 VMware, Inc. All Rights Reserved. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -76,11 +65,16 @@ except ImportError: # protects against generating an exception at runtime pass +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vca import VcaError, vca_argument_spec, vca_login + + VALID_PROTO = ['Tcp', 'Udp', 'Icmp', 'Other', 'Any'] VALID_RULE_KEYS = ['policy', 'is_enable', 'enable_logging', 'description', 'dest_ip', 'dest_port', 'source_ip', 'source_port', 'protocol'] + def protocol_to_tuple(protocol): return (protocol.get_Tcp(), protocol.get_Udp(), @@ -237,14 +231,12 @@ def main(): if task: vca.block_until_completed(task) - result['rules_updated'] = count=len(updates) - result['rules_added'] = count=len(additions) - result['rules_deleted'] = count=len(deletions) + result['rules_updated'] = len(updates) + result['rules_added'] = len(additions) + result['rules_deleted'] = len(deletions) return module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.vca import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vca_nat.py b/lib/ansible/modules/cloud/vmware/vca_nat.py index c0407a846b..e50ff1a7bc 100644 --- a/lib/ansible/modules/cloud/vmware/vca_nat.py +++ b/lib/ansible/modules/cloud/vmware/vca_nat.py @@ -1,21 +1,10 @@ #!/usr/bin/python # Copyright (c) 2015 VMware, Inc. All Rights Reserved. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -78,8 +67,9 @@ EXAMPLES = ''' ''' -import time -import xmltodict +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vca import VcaError, vca_argument_spec, vca_login + VALID_RULE_KEYS = ['rule_type', 'original_ip', 'original_port', 'translated_ip', 'translated_port', 'protocol'] @@ -142,7 +132,6 @@ def main(): module = AnsibleModule(argument_spec, supports_check_mode=True) vdc_name = module.params.get('vdc_name') - state = module.params['state'] nat_rules = module.params['nat_rules'] gateway_name = module.params['gateway_name'] purge_rules = module.params['purge_rules'] @@ -212,9 +201,5 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.vca import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vca_vapp.py b/lib/ansible/modules/cloud/vmware/vca_vapp.py index 32a43e149e..9f0243a4f4 100644 --- a/lib/ansible/modules/cloud/vmware/vca_vapp.py +++ b/lib/ansible/modules/cloud/vmware/vca_vapp.py @@ -1,21 +1,10 @@ #!/usr/bin/python # Copyright (c) 2015 Ansible, Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -147,6 +136,9 @@ EXAMPLES = ''' ''' +from ansible.module_utils.vca import VcaAnsibleModule, VcaError + + DEFAULT_VAPP_OPERATION = 'noop' VAPP_STATUS = { @@ -283,8 +275,6 @@ def main(): return module.exit(**result) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.vca import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_cluster.py b/lib/ansible/modules/cloud/vmware/vmware_cluster.py index b21e135f06..9f95277f0e 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_cluster.py +++ b/lib/ansible/modules/cloud/vmware/vmware_cluster.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -83,6 +73,16 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, + TaskError, + connect_to_api, + find_cluster_by_name_datacenter, + find_datacenter_by_name, + vmware_argument_spec, + wait_for_task + ) + class VMwareCluster(object): def __init__(self, module): @@ -251,8 +251,6 @@ def main(): vmware_cluster = VMwareCluster(module) vmware_cluster.process_state() -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_datacenter.py b/lib/ansible/modules/cloud/vmware/vmware_datacenter.py index ca7459ce43..9fcbcd6faa 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_datacenter.py +++ b/lib/ansible/modules/cloud/vmware/vmware_datacenter.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -81,6 +71,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, find_datacenter_by_name, + vmware_argument_spec, wait_for_task) + def get_datacenter(context, module): try: @@ -161,8 +155,6 @@ def main(): if state == 'absent': destroy_datacenter(context, module) -from ansible.module_utils.basic import * -from ansible.module_utils.vmware import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_dns_config.py b/lib/ansible/modules/cloud/vmware/vmware_dns_config.py index b2b0eca882..9b28d318b1 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_dns_config.py +++ b/lib/ansible/modules/cloud/vmware/vmware_dns_config.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -72,6 +62,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec + def configure_dns(host_system, hostname, domainname, dns_servers): @@ -128,8 +121,5 @@ def main(): module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_dvs_host.py b/lib/ansible/modules/cloud/vmware/vmware_dvs_host.py index 0a66bb6c9c..f8751d40f6 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_dvs_host.py +++ b/lib/ansible/modules/cloud/vmware/vmware_dvs_host.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -34,7 +24,7 @@ author: "Joseph Callen (@jcpowermac)" notes: - Tested on vSphere 5.5 requirements: - - "python >= 2.6" + - "python >= 2.7" - PyVmomi options: esxi_hostname: @@ -74,12 +64,21 @@ EXAMPLES = ''' ''' try: - import collections + from collections import Counter + HAS_COLLECTIONS_COUNTER = True +except ImportError: + HAS_COLLECTIONS_COUNTER = False + +try: from pyVmomi import vim, vmodl HAS_PYVMOMI = True except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, find_dvs_by_name, + find_hostsystem_by_name, vmware_argument_spec, wait_for_task) + class VMwareDvsHost(object): def __init__(self, module): @@ -201,7 +200,7 @@ class VMwareDvsHost(object): for pnicSpec in dvs_host_member.config.backing.pnicSpec: pnic_device.append(pnicSpec.pnicDevice) - return collections.Counter(pnic_device) == collections.Counter(self.vmnics) + return Counter(pnic_device) == Counter(self.vmnics) def check_dvs_host_state(self): self.dv_switch = find_dvs_by_name(self.content, self.switch_name) @@ -244,11 +243,12 @@ def main(): if not HAS_PYVMOMI: module.fail_json(msg='pyvmomi is required for this module') + if not HAS_COLLECTIONS_COUNTER: + module.fail_json(msg='collections.Counter from Python-2.7 is required for this module') + vmware_dvs_host = VMwareDvsHost(module) vmware_dvs_host.process_state() -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup.py b/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup.py index 09cecef1d4..ba8e3c606b 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup.py +++ b/lib/ansible/modules/cloud/vmware/vmware_dvs_portgroup.py @@ -2,21 +2,12 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -85,6 +76,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, find_dvs_by_name, find_dvspg_by_name, + vmware_argument_spec, wait_for_task) + class VMwareDvsPortgroup(object): def __init__(self, module): @@ -196,8 +191,6 @@ def main(): vmware_dvs_portgroup = VMwareDvsPortgroup(module) vmware_dvs_portgroup.process_state() -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_dvswitch.py b/lib/ansible/modules/cloud/vmware/vmware_dvswitch.py index b57dcde9ba..3662b4af12 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_dvswitch.py +++ b/lib/ansible/modules/cloud/vmware/vmware_dvswitch.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -100,6 +90,16 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, + connect_to_api, + find_datacenter_by_name, + find_dvs_by_name, + vmware_argument_spec, + wait_for_task + ) + + class VMwareDVSwitch(object): def __init__(self, module): self.module = module @@ -206,8 +206,6 @@ def main(): vmware_dvswitch = VMwareDVSwitch(module) vmware_dvswitch.process_state() -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 2758b3aa0a..9f8c70b24c 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # # This module is also sponsored by E.T.A.I. (www.etai.fr) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -311,18 +301,7 @@ instance: sample: None ''' - import time -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.vmware import connect_to_api, find_obj, gather_vm_facts, get_all_objs, compile_folder_path_for_object -from ansible.module_utils.vmware import serialize_spec, find_vm_by_id, vmware_argument_spec - - -try: - import json -except ImportError: - import simplejson as json HAS_PYVMOMI = False try: @@ -333,6 +312,12 @@ try: except ImportError: pass +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text +from ansible.module_utils.vmware import (connect_to_api, find_obj, gather_vm_facts, get_all_objs, + compile_folder_path_for_object, serialize_spec, find_vm_by_id, + vmware_argument_spec) + class PyVmomiDeviceHelper(object): """ This class is a helper to create easily VMWare Objects for PyVmomiHelper """ @@ -1033,7 +1018,6 @@ class PyVmomiHelper(object): def autoselect_datastore(self): datastore = None - datastore_name = None datastores = self.cache.get_all_objs(self.content, [vim.Datastore]) if datastores is None or len(datastores) == 0: @@ -1043,7 +1027,6 @@ class PyVmomiHelper(object): for ds in datastores: if ds.summary.freeSpace > datastore_freespace: datastore = ds - datastore_name = datastore.name datastore_freespace = ds.summary.freeSpace return datastore @@ -1512,5 +1495,6 @@ def main(): else: module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py b/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py index ec6daf6139..e1aa9c78b1 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # # This module is also sponsored by E.T.A.I. (www.etai.fr) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -96,16 +86,6 @@ instance: sample: None """ -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils._text import to_text -from ansible.module_utils.vmware import connect_to_api, find_vm_by_id, gather_vm_facts, vmware_argument_spec - -try: - import json -except ImportError: - import simplejson as json - - try: import pyVmomi from pyVmomi import vim @@ -114,6 +94,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text +from ansible.module_utils.vmware import connect_to_api, find_vm_by_id, gather_vm_facts, vmware_argument_spec + class PyVmomiHelper(object): def __init__(self, module): @@ -175,5 +159,6 @@ def main(): msg += "%(uuid)s" % module.params module.fail_json(msg=msg) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_find.py b/lib/ansible/modules/cloud/vmware/vmware_guest_find.py index 4c1df6dadd..973aa9f39e 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest_find.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest_find.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -76,10 +67,6 @@ RETURN = """ """ import os -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils._text import to_native -from ansible.module_utils.vmware import connect_to_api, gather_vm_facts, get_all_objs, compile_folder_path_for_object, vmware_argument_spec - HAS_PYVMOMI = False try: @@ -90,6 +77,11 @@ try: except ImportError: pass +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native +from ansible.module_utils.vmware import (connect_to_api, gather_vm_facts, get_all_objs, + compile_folder_path_for_object, vmware_argument_spec) + class PyVmomiHelper(object): def __init__(self, module): @@ -258,5 +250,6 @@ def main(): msg += "%(uuid)s" % module.params module.fail_json(msg=msg) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py b/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py index 49163b2881..0afd90b0b0 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # # This module is also sponsored by E.T.A.I. (www.etai.fr) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -188,14 +178,6 @@ instance: """ import time -from ansible.module_utils._text import to_native -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.vmware import connect_to_api, vmware_argument_spec, find_vm_by_id - -try: - import json -except ImportError: - import simplejson as json HAS_PYVMOMI = False try: @@ -206,6 +188,10 @@ try: except ImportError: pass +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native +from ansible.module_utils.vmware import connect_to_api, vmware_argument_spec, find_vm_by_id + class PyVmomiHelper(object): def __init__(self, module): @@ -358,5 +344,6 @@ def main(): else: module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_host.py b/lib/ansible/modules/cloud/vmware/vmware_host.py index 8cd4d174da..3517e50b8b 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_host.py +++ b/lib/ansible/modules/cloud/vmware/vmware_host.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -240,5 +230,6 @@ def main(): vmware_host = VMwareHost(module) vmware_host.process_state() + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py b/lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py index 3f05c147a6..3c1d72dc97 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py +++ b/lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py @@ -3,21 +3,12 @@ # Copyright IBM Corp. 2016 # Author(s): Andreas Nafpliotis +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -113,6 +102,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, TaskError, connect_to_api, find_hostsystem_by_name, + vmware_argument_spec, wait_for_task) + def EnterMaintenanceMode(module, host): @@ -209,9 +202,5 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * -from ansible.module_utils.vmware import * - - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py b/lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py index c42f2a2a22..91546a6b50 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py +++ b/lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -85,8 +75,10 @@ try: HAS_PYVMOMI = True except ImportError: HAS_PYVMOMI = False -from ansible.module_utils.vmware import vmware_argument_spec, find_dvs_by_name, find_hostsystem_by_name, connect_to_api, find_dvspg_by_name + from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (vmware_argument_spec, find_dvs_by_name, find_hostsystem_by_name, + connect_to_api, find_dvspg_by_name) class VMwareMigrateVmk(object): diff --git a/lib/ansible/modules/cloud/vmware/vmware_portgroup.py b/lib/ansible/modules/cloud/vmware/vmware_portgroup.py index 3a6d82a740..c8aa694e02 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_portgroup.py +++ b/lib/ansible/modules/cloud/vmware/vmware_portgroup.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -91,6 +81,14 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, + connect_to_api, + find_host_portgroup_by_name, + get_all_objs, + vmware_argument_spec, + ) + def create_network_policy(promiscuous_mode, forged_transmits, mac_changes): @@ -116,7 +114,7 @@ def create_port_group(host_system, portgroup_name, vlan_id, vswitch_name, networ config.portgroup[0].spec.vswitchName = vswitch_name config.portgroup[0].spec.policy = network_policy - host_network_config_result = host_system.configManager.networkSystem.UpdateNetworkConfig(config, "modify") + host_system.configManager.networkSystem.UpdateNetworkConfig(config, "modify") return True @@ -161,8 +159,6 @@ def main(): except Exception as e: module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_resource_pool.py b/lib/ansible/modules/cloud/vmware/vmware_resource_pool.py index 0404354b51..4b7733bafd 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_resource_pool.py +++ b/lib/ansible/modules/cloud/vmware/vmware_resource_pool.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Davis Phillips davis.phillips@gmail.com -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'status': ['preview'], 'supported_by': 'community', @@ -147,9 +137,9 @@ try: except ImportError: HAS_PYVMOMI = False -from ansible.module_utils.vmware import get_all_objs, connect_to_api, vmware_argument_spec, find_datacenter_by_name, \ - find_cluster_by_name_datacenter, wait_for_task from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (get_all_objs, connect_to_api, vmware_argument_spec, + find_datacenter_by_name, find_cluster_by_name_datacenter, wait_for_task) class VMwareResourcePool(object): @@ -265,8 +255,6 @@ class VMwareResourcePool(object): def state_add_rp(self): changed = True - result = None - root_resource_pool = None rp_spec = vim.ResourceConfigSpec() cpu_alloc = vim.ResourceAllocationInfo() @@ -290,7 +278,7 @@ class VMwareResourcePool(object): self.cluster_obj = find_cluster_by_name_datacenter( self.dc_obj, self.cluster) rootResourcePool = self.cluster_obj.resourcePool - task = rootResourcePool.CreateResourcePool(self.resource_pool, rp_spec) + rootResourcePool.CreateResourcePool(self.resource_pool, rp_spec) self.module.exit_json(changed=changed) @@ -337,5 +325,6 @@ def main(): vmware_rp = VMwareResourcePool(module) vmware_rp.process_state() + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_target_canonical_facts.py b/lib/ansible/modules/cloud/vmware/vmware_target_canonical_facts.py index 9b6d4933ee..fed958a09c 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_target_canonical_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_target_canonical_facts.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -60,6 +50,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec + def find_hostsystem(content): host_system = get_all_objs(content, [vim.HostSystem]) @@ -94,9 +87,6 @@ def main(): module.exit_json(changed=False, canonical=scsilun_canonical[target_lun_uuid[module.params['target_id']]]) -from ansible.module_utils.basic import * -from ansible.module_utils.vmware import * if __name__ == '__main__': main() - diff --git a/lib/ansible/modules/cloud/vmware/vmware_vm_facts.py b/lib/ansible/modules/cloud/vmware/vmware_vm_facts.py index 8f359e90a7..caad5c2bcc 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vm_facts.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vm_facts.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -55,6 +45,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec + # https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/getallvms.py def get_all_virtual_machines(content): @@ -106,8 +99,6 @@ def main(): except Exception as e: module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vm_shell.py b/lib/ansible/modules/cloud/vmware/vmware_vm_shell.py index aae3004414..d32c7a41f1 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vm_shell.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vm_shell.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, 2016 Ritesh Khadgaray -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -140,8 +130,10 @@ try: HAS_PYVMOMI = True except ImportError: HAS_PYVMOMI = False -from ansible.module_utils.vmware import connect_to_api, find_cluster_by_name, find_datacenter_by_name, find_vm_by_id, vmware_argument_spec + from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (connect_to_api, find_cluster_by_name, find_datacenter_by_name, + find_vm_by_id, vmware_argument_spec) # https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/execute_program_in_vm.py @@ -214,5 +206,6 @@ def main(): except Exception as e: module.fail_json(changed=False, msg=str(e)) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vm_vss_dvs_migrate.py b/lib/ansible/modules/cloud/vmware/vmware_vm_vss_dvs_migrate.py index 0651e7ddce..d55012d3d5 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vm_vss_dvs_migrate.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vm_vss_dvs_migrate.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -65,6 +55,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, get_all_objs, + vmware_argument_spec, wait_for_task) + class VMwareVmVssDvsMigrate(object): def __init__(self, module): @@ -156,8 +150,6 @@ def main(): vmware_vmnic_migrate = VMwareVmVssDvsMigrate(module) vmware_vmnic_migrate.process_state() -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py b/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py index df2e95014b..9782b04910 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vmkernel.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -103,6 +93,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec + def create_vmkernel_adapter(host_system, port_group_name, vlan_id, vswitch_name, @@ -144,7 +137,7 @@ def create_vmkernel_adapter(host_system, port_group_name, vsan_config.networkInfo.port = [vim.vsan.host.ConfigInfo.NetworkInfo.PortConfig()] vsan_config.networkInfo.port[0].device = vnic_device - host_vsan_config_result = vsan_system.UpdateVsan_Task(vsan_config) + vsan_system.UpdateVsan_Task(vsan_config) if enable_vmotion: host_virtual_vic_manager.SelectVnicForNicType("vmotion", vnic_device) @@ -206,8 +199,5 @@ def main(): module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vmkernel_ip_config.py b/lib/ansible/modules/cloud/vmware/vmware_vmkernel_ip_config.py index 09bac54551..74009009f0 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vmkernel_ip_config.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vmkernel_ip_config.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -72,6 +62,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec + def configure_vmkernel_ip_address(host_system, vmk_name, ip_address, subnet_mask): @@ -121,8 +114,6 @@ def main(): except Exception as e: module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vmotion.py b/lib/ansible/modules/cloud/vmware/vmware_vmotion.py index 7af3af74f0..6cd69ff873 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vmotion.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vmotion.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Bede Carroll -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -79,6 +69,9 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (connect_to_api, find_hostsystem_by_name, find_vm_by_name, + vmware_argument_spec, wait_for_task) def migrate_vm(vm_object, host_object): """ @@ -146,8 +139,6 @@ def main(): result['changed'] = True module.exit_json(**result) -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.vmware import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vsan_cluster.py b/lib/ansible/modules/cloud/vmware/vmware_vsan_cluster.py index f17afaad34..c4942f7964 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vsan_cluster.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vsan_cluster.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Russell Teague -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -76,6 +66,10 @@ try: except ImportError: HAS_PYVMOMI = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, get_all_objs, vmware_argument_spec, + wait_for_task) + def create_vsan_cluster(host_system, new_cluster_uuid): host_config_manager = host_system.configManager @@ -128,8 +122,6 @@ def main(): except Exception as e: module.fail_json(msg=str(e)) -from ansible.module_utils.vmware import * -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vmware_vswitch.py b/lib/ansible/modules/cloud/vmware/vmware_vswitch.py index c5590bdf7b..77fb35dad5 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vswitch.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vswitch.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Joseph Callen -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -91,8 +81,9 @@ try: HAS_PYVMOMI = True except ImportError: HAS_PYVMOMI = False -from ansible.module_utils.vmware import vmware_argument_spec, get_all_objs, connect_to_api + from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vmware import vmware_argument_spec, get_all_objs, connect_to_api def find_vswitch_by_name(host, vswitch_name): @@ -206,5 +197,6 @@ def main(): host_virtual_switch = VMwareHostVirtualSwitch(module) host_virtual_switch.process_state() + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vsphere_copy.py b/lib/ansible/modules/cloud/vmware/vsphere_copy.py index 0d62024d0a..e542100df0 100644 --- a/lib/ansible/modules/cloud/vmware/vsphere_copy.py +++ b/lib/ansible/modules/cloud/vmware/vsphere_copy.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2015 Dag Wieers -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -96,15 +86,17 @@ EXAMPLES = ''' ''' import atexit -import mmap import errno +import mmap import socket +import traceback from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils._text import to_native from ansible.module_utils.urls import open_url + def vmware_path(datastore, datacenter, path): ''' Constructs a URL path that VSphere accepts reliably ''' path = "/folder/%s" % path.lstrip("/") @@ -119,6 +111,7 @@ def vmware_path(datastore, datacenter, path): params = urlencode(params) return "%s?%s" % (path, params) + def main(): module = AnsibleModule( @@ -163,22 +156,22 @@ def main(): r = open_url(url, data=data, headers=headers, method='PUT', url_username=login, url_password=password, validate_certs=validate_certs, force_basic_auth=True) - except socket.error: - e = get_exception() + except socket.error as e: if isinstance(e.args, tuple) and e[0] == errno.ECONNRESET: # VSphere resets connection if the file is in use and cannot be replaced - module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=str(e), url=url) + module.fail_json(msg='Failed to upload, image probably in use', status=None, errno=e[0], reason=to_native(e), url=url) else: - module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e), url=url) - except Exception: - e = get_exception() + module.fail_json(msg=str(e), status=None, errno=e[0], reason=str(e), + url=url, exception=traceback.format_exc()) + except Exception as e: error_code = -1 try: if isinstance(e[0], int): error_code = e[0] except KeyError: pass - module.fail_json(msg=str(e), status=None, errno=error_code, reason=str(e), url=url) + module.fail_json(msg=to_native(e), status=None, errno=error_code, + reason=to_native(e), url=url, exception=traceback.format_exc()) status = r.getcode() if 200 <= status < 300: @@ -192,5 +185,6 @@ def main(): module.fail_json(msg='Failed to upload', errno=None, status=status, reason=r.msg, length=length, headers=dict(r.headers), chunked=chunked, url=url) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/vmware/vsphere_guest.py b/lib/ansible/modules/cloud/vmware/vsphere_guest.py index 2939e4df44..51a72be62b 100644 --- a/lib/ansible/modules/cloud/vmware/vsphere_guest.py +++ b/lib/ansible/modules/cloud/vmware/vsphere_guest.py @@ -1,22 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# TODO: -# Ability to set CPU/Memory reservations ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -307,7 +296,6 @@ EXAMPLES = ''' force: yes ''' -import json import os import re import ssl @@ -318,7 +306,7 @@ try: from pysphere import VIServer, VIProperty, MORTypes from pysphere.resources import VimService_services as VI from pysphere.vi_task import VITask - from pysphere import VIException, VIApiException, FaultTypes + from pysphere import VIApiException HAS_PYSPHERE = True except ImportError: pass @@ -328,6 +316,9 @@ from ansible.module_utils.six import string_types from ansible.module_utils._text import to_native +# TODO: +# Ability to set CPU/Memory reservations + def add_scsi_controller(module, s, config, devices, type="paravirtual", bus_num=0, disk_ctrl_key=1): # add a scsi controller scsi_ctrl_spec = config.new_deviceChange() @@ -801,7 +792,7 @@ def update_disks(vsphere_client, vm, module, vm_disk, changes): found = True continue if not found: - it = VI.ReconfigVM_TaskRequestMsg() + VI.ReconfigVM_TaskRequestMsg() _this = request.new__this(vm._mor) _this.set_attribute_type(vm._mor.get_attribute_type()) request.set_element__this(_this) @@ -1811,7 +1802,7 @@ def main(): except ssl.SSLError as sslerr: if '[SSL: CERTIFICATE_VERIFY_FAILED]' in sslerr.strerror: if not validate_certs: - default_context = ssl._create_default_https_context + ssl._create_default_https_context ssl._create_default_https_context = ssl._create_unverified_context viserver.connect(vcenter_hostname, username, password) else: diff --git a/lib/ansible/modules/notification/campfire.py b/lib/ansible/modules/notification/campfire.py index bb8bd84497..0620d3a274 100644 --- a/lib/ansible/modules/notification/campfire.py +++ b/lib/ansible/modules/notification/campfire.py @@ -1,20 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -81,6 +74,10 @@ EXAMPLES = ''' import cgi +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url + + def main(): module = AnsibleModule( @@ -144,8 +141,6 @@ def main(): module.exit_json(changed=True, room=room, msg=msg, notify=notify) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/catapult.py b/lib/ansible/modules/notification/catapult.py index ebfc803c2a..1f6c1971c5 100644 --- a/lib/ansible/modules/notification/catapult.py +++ b/lib/ansible/modules/notification/catapult.py @@ -2,21 +2,13 @@ # -*- coding: utf-8 -*- # (c) 2016, Jonathan Mainguy +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# basis of code taken from the ansible twillio and nexmo modules + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -106,9 +98,9 @@ changed: import json + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url -# Stole most of this code from the ansible twillio and nexmo modules def send(module, src, dest, msg, media, user_id, api_token, api_secret): @@ -161,5 +153,6 @@ def main(): changed = True module.exit_json(changed=changed) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/cisco_spark.py b/lib/ansible/modules/notification/cisco_spark.py index 189c94a62b..08fa062423 100644 --- a/lib/ansible/modules/notification/cisco_spark.py +++ b/lib/ansible/modules/notification/cisco_spark.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -122,6 +113,8 @@ message: type: string sample: OK (585 bytes) """ +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url def spark_message(module): @@ -195,7 +188,5 @@ def main(): module.exit_json(**results) -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import fetch_url if __name__ == "__main__": main() diff --git a/lib/ansible/modules/notification/flowdock.py b/lib/ansible/modules/notification/flowdock.py index 8dd95badac..67717f5706 100644 --- a/lib/ansible/modules/notification/flowdock.py +++ b/lib/ansible/modules/notification/flowdock.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2013 Matt Coddington -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -110,7 +100,10 @@ EXAMPLES = ''' tags: tag1,tag2,tag3 ''' +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.urls import fetch_url + # =========================================== # Module execution. @@ -192,9 +185,6 @@ def main(): module.exit_json(changed=True, msg=module.params["msg"]) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/grove.py b/lib/ansible/modules/notification/grove.py index 810a14685d..90c6f519a8 100644 --- a/lib/ansible/modules/notification/grove.py +++ b/lib/ansible/modules/notification/grove.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -69,7 +61,10 @@ EXAMPLES = ''' message=deployed {{ target }} ''' +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.urls import fetch_url + BASE_URL = 'https://grove.io/api/notice/%s/' @@ -116,9 +111,6 @@ def main(): # Mission complete module.exit_json(msg="OK") -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/hall.py b/lib/ansible/modules/notification/hall.py index 65b5811071..bf6f51e090 100644 --- a/lib/ansible/modules/notification/hall.py +++ b/lib/ansible/modules/notification/hall.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # (c) 2015, Billy Kimble -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -69,9 +58,13 @@ EXAMPLES = """ when: ec2.instances|length > 0 with_items: '{{ ec2.instances }}' """ +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url + HALL_API_ENDPOINT = 'https://hall.com/api/1/services/generic/%s' + def send_request_to_hall(module, room_token, payload): headers = {'Content-Type': 'application/json'} payload=module.jsonify(payload) @@ -81,6 +74,7 @@ def send_request_to_hall(module, room_token, payload): secure_url = HALL_API_ENDPOINT % ('[redacted]') module.fail_json(msg=" failed to send %s to %s: %s" % (payload, secure_url, info['msg'])) + def main(): module = AnsibleModule( argument_spec=dict( @@ -100,8 +94,6 @@ def main(): send_request_to_hall(module, room_token, payload) module.exit_json(msg="OK") -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/hipchat.py b/lib/ansible/modules/notification/hipchat.py index dc368b5862..9491adcc33 100644 --- a/lib/ansible/modules/notification/hipchat.py +++ b/lib/ansible/modules/notification/hipchat.py @@ -1,20 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], 'supported_by': 'community'} @@ -103,19 +96,16 @@ EXAMPLES = ''' # HipChat module specific support methods. # -try: - import json -except ImportError: - import simplejson as json +import json +import traceback - -# import module snippets from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.request import pathname2url +from ansible.module_utils._text import to_native from ansible.module_utils.urls import fetch_url + DEFAULT_URI = "https://api.hipchat.com/v1" MSG_URI_V1 = "/rooms/message" @@ -217,12 +207,12 @@ def main(): send_msg_v2(module, token, room, msg_from, msg, msg_format, color, notify, api) else: send_msg_v1(module, token, room, msg_from, msg, msg_format, color, notify, api) - except Exception: - e = get_exception() - module.fail_json(msg="unable to send msg: %s" % e) + except Exception as e: + module.fail_json(msg="unable to send msg: %s" % to_native(e), exception=traceback.format_exc()) changed = True module.exit_json(changed=changed, room=room, msg_from=msg_from, msg=msg) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/irc.py b/lib/ansible/modules/notification/irc.py index 2082f70977..c8c44f288c 100644 --- a/lib/ansible/modules/notification/irc.py +++ b/lib/ansible/modules/notification/irc.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Jan-Piet Mens -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -152,8 +141,11 @@ EXAMPLES = ''' import re import socket import ssl +import time +import traceback -from time import sleep +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key=None, topic=None, @@ -219,7 +211,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key break elif time.time() - start > timeout: raise Exception('Timeout waiting for IRC server welcome response') - sleep(0.5) + time.sleep(0.5) if key: irc.send('JOIN %s %s\r\n' % (channel, key)) @@ -234,22 +226,22 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key break elif time.time() - start > timeout: raise Exception('Timeout waiting for IRC JOIN response') - sleep(0.5) + time.sleep(0.5) if topic is not None: irc.send('TOPIC %s :%s\r\n' % (channel, topic)) - sleep(1) + time.sleep(1) if nick_to: for nick in nick_to: irc.send('PRIVMSG %s :%s\r\n' % (nick, message)) if channel: irc.send('PRIVMSG %s :%s\r\n' % (channel, message)) - sleep(1) + time.sleep(1) if part: irc.send('PART %s\r\n' % channel) irc.send('QUIT\r\n') - sleep(1) + time.sleep(1) irc.close() # =========================================== @@ -303,16 +295,12 @@ def main(): try: send_msg(msg, server, port, channel, nick_to, key, topic, nick, color, passwd, timeout, use_ssl, part, style) - except Exception: - e = get_exception() - module.fail_json(msg="unable to send to IRC: %s" % e) + except Exception as e: + module.fail_json(msg="unable to send to IRC: %s" % to_native(e), exception=traceback.format_exc()) module.exit_json(changed=False, channel=channel, nick=nick, msg=msg) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/jabber.py b/lib/ansible/modules/notification/jabber.py index 4986d28a6d..dcd6dd67dc 100644 --- a/lib/ansible/modules/notification/jabber.py +++ b/lib/ansible/modules/notification/jabber.py @@ -2,21 +2,10 @@ # -*- coding: utf-8 -*- # # (c) 2015, Brian Coca -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -94,9 +83,8 @@ EXAMPLES = ''' msg: Ansible task finished ''' -import os -import re import time +import traceback HAS_XMPP = True try: @@ -104,6 +92,10 @@ try: except ImportError: HAS_XMPP = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + + def main(): module = AnsibleModule( @@ -163,15 +155,11 @@ def main(): conn.send(msg) time.sleep(1) conn.disconnect() - except Exception: - e = get_exception() - module.fail_json(msg="unable to send msg: %s" % e) + except Exception as e: + module.fail_json(msg="unable to send msg: %s" % to_native(e), exception=traceback.format_exc()) module.exit_json(changed=False, to=to, user=user, msg=msg.getBody()) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/mail.py b/lib/ansible/modules/notification/mail.py index 862e61ccef..7be2f3d6d7 100644 --- a/lib/ansible/modules/notification/mail.py +++ b/lib/ansible/modules/notification/mail.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # Copyright 2012 Dag Wieers -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -203,24 +193,15 @@ EXAMPLES = ''' import os import smtplib import ssl - -try: - # Python 2.6+ - from email import encoders - from email.utils import parseaddr, formataddr - from email.mime.base import MIMEBase - from email.mime.multipart import MIMEMultipart - from email.mime.text import MIMEText -except ImportError: - # Python 2.4 & 2.5 - from email import Encoders as encoders - from email.Utils import parseaddr, formataddr - from email.MIMEBase import MIMEBase - from email.MIMEMultipart import MIMEMultipart - from email.MIMEText import MIMEText +import traceback +from email import encoders +from email.utils import parseaddr, formataddr +from email.mime.base import MIMEBase +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native def main(): @@ -275,18 +256,18 @@ def main(): if secure in ('never', 'try', 'starttls'): try: code, smtpmessage = smtp.connect(host, port=port) - except smtplib.SMTPException: - e = get_exception() + except smtplib.SMTPException as e: if secure == 'try': try: smtp = smtplib.SMTP_SSL(timeout=timeout) code, smtpmessage = smtp.connect(host, port=port) secure_state = True - except ssl.SSLError: - e = get_exception() - module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % (host, port, e)) + except ssl.SSLError as e: + module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % + (host, port, to_native(e)), exception=traceback.format_exc()) else: - module.fail_json(rc=1, msg='Unable to Connect to %s:%s: %s' % (host, port, e)) + module.fail_json(rc=1, msg='Unable to Connect to %s:%s: %s' % + (host, port, to_native(e)), exception=traceback.format_exc()) if (secure == 'always'): @@ -294,16 +275,16 @@ def main(): smtp = smtplib.SMTP_SSL(timeout=timeout) code, smtpmessage = smtp.connect(host, port=port) secure_state = True - except ssl.SSLError: - e = get_exception() - module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % (host, port, e)) + except ssl.SSLError as e: + module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % + (host, port, to_native(e)), exception=traceback.format_exc()) if int(code) > 0: try: smtp.ehlo() - except smtplib.SMTPException: - e = get_exception() - module.fail_json(rc=1, msg='Helo failed for host %s:%s: %s' % (host, port, e)) + except smtplib.SMTPException as e: + module.fail_json(rc=1, msg='Helo failed for host %s:%s: %s' % + (host, port, to_native(e)), exception=traceback.format_exc()) auth_flag = smtp.has_extn('AUTH') @@ -314,9 +295,9 @@ def main(): smtp.ehlo() auth_flag = smtp.has_extn('AUTH') secure_state = True - except smtplib.SMTPException: - e = get_exception() - module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % (host, port, e)) + except smtplib.SMTPException as e: + module.fail_json(rc=1, msg='Unable to start an encrypted session to %s:%s: %s' % + (host, port, to_native(e)), exception=traceback.format_exc()) else: if secure == 'starttls': module.fail_json(rc=1, msg='StartTLS is not offered on server %s:%s' % (host, port)) @@ -385,17 +366,17 @@ def main(): part.add_header('Content-disposition', 'attachment', filename=os.path.basename(file)) msg.attach(part) - except Exception: - e = get_exception() - module.fail_json(rc=1, msg="Failed to send mail: can't attach file %s: %s" % (file, e)) + except Exception as e: + module.fail_json(rc=1, msg="Failed to send mail: can't attach file %s: %s" % + (file, to_native(e)), exception=traceback.format_exc()) composed = msg.as_string() try: smtp.sendmail(sender_addr, set(addr_list), composed) - except Exception: - e = get_exception() - module.fail_json(rc=1, msg='Failed to send mail to %s: %s' % (", ".join(addr_list), e)) + except Exception as e: + module.fail_json(rc=1, msg='Failed to send mail to %s: %s' % + (", ".join(addr_list), to_native(e)), exception=traceback.format_exc()) smtp.quit() diff --git a/lib/ansible/modules/notification/mattermost.py b/lib/ansible/modules/notification/mattermost.py index a3c0b70610..899aed9a09 100644 --- a/lib/ansible/modules/notification/mattermost.py +++ b/lib/ansible/modules/notification/mattermost.py @@ -7,21 +7,12 @@ # # (c) 2016, René Moser # # (c) 2015, Stefan Berggren # # (c) 2014, Ramon de la Fuente ) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -103,6 +94,7 @@ webhook_url: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url + def main(): module = AnsibleModule( supports_check_mode=True, diff --git a/lib/ansible/modules/notification/mqtt.py b/lib/ansible/modules/notification/mqtt.py index aefa714478..4e00400285 100644 --- a/lib/ansible/modules/notification/mqtt.py +++ b/lib/ansible/modules/notification/mqtt.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, 2014, Jan-Piet Mens -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -133,6 +122,9 @@ EXAMPLES = ''' # MQTT module support methods. # +import os +import traceback + HAS_PAHOMQTT = True try: import socket @@ -140,6 +132,10 @@ try: except ImportError: HAS_PAHOMQTT = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + + # =========================================== # Main # @@ -196,7 +192,7 @@ def main(): 'keyfile': keyfile} try: - rc = mqtt.single(topic, payload, + mqtt.single(topic, payload, qos=qos, retain=retain, client_id=client_id, @@ -204,15 +200,12 @@ def main(): port=port, auth=auth, tls=tls) - except Exception: - e = get_exception() - module.fail_json(msg="unable to publish to MQTT broker %s" % (e)) + except Exception as e: + module.fail_json(msg="unable to publish to MQTT broker %s" % to_native(e), + exception=traceback.format_exc()) module.exit_json(changed=False, topic=topic) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/nexmo.py b/lib/ansible/modules/notification/nexmo.py index 4a88d6c1f0..02777f5056 100644 --- a/lib/ansible/modules/notification/nexmo.py +++ b/lib/ansible/modules/notification/nexmo.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Matt Martz -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -75,8 +65,12 @@ EXAMPLES = """ msg: '{{ inventory_hostname }} completed' delegate_to: localhost """ +import json from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url, url_argument_spec + NEXMO_API = 'https://rest.nexmo.com/sms/json' @@ -139,9 +133,5 @@ def main(): send_msg(module) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/osx_say.py b/lib/ansible/modules/notification/osx_say.py index d1eb71ae25..c841d61b9d 100644 --- a/lib/ansible/modules/notification/osx_say.py +++ b/lib/ansible/modules/notification/osx_say.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -53,12 +43,18 @@ EXAMPLES = ''' voice: Zarvox delegate_to: localhost ''' +import os + +from ansible.module_utils.basic import AnsibleModule + DEFAULT_VOICE='Alex' + def say(module, msg, voice): module.run_command(["/usr/bin/say", msg, "--voice=%s" % (voice)], check_rc=True) + def main(): module = AnsibleModule( @@ -79,8 +75,6 @@ def main(): module.exit_json(msg=msg, changed=False) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/pushbullet.py b/lib/ansible/modules/notification/pushbullet.py index 216eab72d2..8dbfa2d6c4 100644 --- a/lib/ansible/modules/notification/pushbullet.py +++ b/lib/ansible/modules/notification/pushbullet.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -106,6 +98,9 @@ except ImportError: else: pushbullet_found = True +from ansible.module_utils.basic import AnsibleModule + + # =========================================== # Main # @@ -187,8 +182,6 @@ def main(): module.fail_json(msg="An unknown error has occurred") -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/pushover.py b/lib/ansible/modules/notification/pushover.py index a77f5679ac..049a9dec0e 100644 --- a/lib/ansible/modules/notification/pushover.py +++ b/lib/ansible/modules/notification/pushover.py @@ -1,24 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2012, Jim Richardson -# All rights reserved. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -### ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -65,7 +52,9 @@ EXAMPLES = ''' delegate_to: localhost ''' +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.urls import fetch_url class Pushover(object): @@ -116,8 +105,6 @@ def main(): module.exit_json(msg='message sent successfully: %s' % response, changed=False) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/rocketchat.py b/lib/ansible/modules/notification/rocketchat.py index 78a46e787d..c7eeeb95aa 100644 --- a/lib/ansible/modules/notification/rocketchat.py +++ b/lib/ansible/modules/notification/rocketchat.py @@ -5,20 +5,11 @@ # (c) 2015, Stefan Berggren # (c) 2014, Ramon de la Fuente # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -168,8 +159,13 @@ changed: sample: false """ +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url + + ROCKETCHAT_INCOMING_WEBHOOK = '%s://%s/hooks/%s' + def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments): payload = {} if color == "normal" and text is not None: @@ -249,9 +245,6 @@ def main(): module.exit_json(msg="OK") -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/sendgrid.py b/lib/ansible/modules/notification/sendgrid.py index e6dcbf5fdb..9dcf27d471 100644 --- a/lib/ansible/modules/notification/sendgrid.py +++ b/lib/ansible/modules/notification/sendgrid.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Matt Makai -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -140,7 +130,7 @@ EXAMPLES = ''' # ======================================= # sendgrid module support methods # -from ansible.module_utils.six.moves.urllib.parse import urlencode +import os try: import sendgrid @@ -148,6 +138,12 @@ try: except ImportError: HAS_SENDGRID = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils._text import to_bytes +from ansible.module_utils.urls import fetch_url + + def post_sendgrid_api(module, username, password, from_address, to_addresses, subject, body, api_key=None, cc=None, bcc=None, attachments=None, html_body=False, from_name=None, headers=None): @@ -160,8 +156,7 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses, encoded_data = urlencode(data) to_addresses_api = '' for recipient in to_addresses: - if isinstance(recipient, unicode): - recipient = recipient.encode('utf-8') + recipient = to_bytes(recipient, errors='surrogate_or_strict') to_addresses_api += '&to[]=%s' % recipient encoded_data += to_addresses_api @@ -270,8 +265,6 @@ def main(): module.exit_json(msg=subject, changed=False) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/slack.py b/lib/ansible/modules/notification/slack.py index 6077a20057..974e453a79 100644 --- a/lib/ansible/modules/notification/slack.py +++ b/lib/ansible/modules/notification/slack.py @@ -6,20 +6,11 @@ # (c) 2015, Stefan Berggren # (c) 2014, Ramon de la Fuente # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -180,6 +171,10 @@ EXAMPLES = """ msg: This message has <brackets> & ampersands in plain text. """ +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url + + OLD_SLACK_INCOMING_WEBHOOK = 'https://%s/services/hooks/incoming-webhook?token=%s' SLACK_INCOMING_WEBHOOK = 'https://hooks.slack.com/services/%s' @@ -190,10 +185,12 @@ escape_table = { "'": "\'", } + def escape_quotes(text): '''Backslash any quotes within text.''' return "".join(escape_table.get(c,c) for c in text) + def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoji, link_names, parse, color, attachments): payload = {} if color == "normal" and text is not None: @@ -296,9 +293,6 @@ def main(): module.exit_json(msg="OK") -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/telegram.py b/lib/ansible/modules/notification/telegram.py index f058acf4f0..8e3018f31e 100644 --- a/lib/ansible/modules/notification/telegram.py +++ b/lib/ansible/modules/notification/telegram.py @@ -2,22 +2,10 @@ # -*- coding: utf-8 -*- # (c) 2016, Artem Feofanov -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -85,7 +73,10 @@ telegram_error: """ import json + +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import quote +from ansible.module_utils.urls import fetch_url def main(): @@ -122,8 +113,5 @@ def main(): telegram_error=body['description']) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/twilio.py b/lib/ansible/modules/notification/twilio.py index 7c2f9b2dee..061c837d34 100644 --- a/lib/ansible/modules/notification/twilio.py +++ b/lib/ansible/modules/notification/twilio.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Matt Makai -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -109,7 +99,11 @@ EXAMPLES = ''' # ======================================= # twilio module support methods # +import json + +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils.urls import fetch_url def post_twilio_api(module, account_sid, auth_token, msg, from_number, @@ -175,8 +169,6 @@ def main(): module.exit_json(msg=msg, changed=False) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/notification/typetalk.py b/lib/ansible/modules/notification/typetalk.py index 2507d5aaf1..a9314c64d6 100644 --- a/lib/ansible/modules/notification/typetalk.py +++ b/lib/ansible/modules/notification/typetalk.py @@ -1,20 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} @@ -56,17 +49,9 @@ EXAMPLES = ''' msg: install completed ''' -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - json = None +import json -# import module snippets from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.urls import fetch_url, ConnectionError @@ -109,8 +94,7 @@ def send_message(module, client_id, client_secret, topic, msg): } do_request(module, url, {'message': msg}, headers) return True, {'access_token': access_token} - except ConnectionError: - e = get_exception() + except ConnectionError as e: return False, e diff --git a/lib/ansible/modules/packaging/language/bower.py b/lib/ansible/modules/packaging/language/bower.py index cc6ffe1c06..52bd51400d 100644 --- a/lib/ansible/modules/packaging/language/bower.py +++ b/lib/ansible/modules/packaging/language/bower.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Michael Warkentin -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -104,6 +94,10 @@ EXAMPLES = ''' path: /app/location relative_execpath: node_modules/.bin ''' +import json +import os + +from ansible.module_utils.basic import AnsibleModule class Bower(object): @@ -239,7 +233,6 @@ def main(): module.exit_json(changed=changed) -# Import module snippets -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/bundler.py b/lib/ansible/modules/packaging/language/bundler.py index ff9662c6b9..d73aac1b4a 100644 --- a/lib/ansible/modules/packaging/language/bundler.py +++ b/lib/ansible/modules/packaging/language/bundler.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Tim Hoiberg -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -142,6 +131,8 @@ EXAMPLES=''' chdir: ~/rails_project ''' +from ansible.module_utils.basic import AnsibleModule + def get_bundler_executable(module): if module.params.get('executable'): @@ -169,7 +160,6 @@ def main(): supports_check_mode=True ) - executable = module.params.get('executable') state = module.params.get('state') chdir = module.params.get('chdir') exclude_groups = module.params.get('exclude_groups') @@ -221,6 +211,5 @@ def main(): module.exit_json(changed='Installing' in out, state=state, stdout=out, stderr=err) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/composer.py b/lib/ansible/modules/packaging/language/composer.py index ddee95fde2..36e6cec4ee 100644 --- a/lib/ansible/modules/packaging/language/composer.py +++ b/lib/ansible/modules/packaging/language/composer.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Dimitrios Tydeas Mengidis +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -159,6 +148,7 @@ EXAMPLES = ''' ''' import re + from ansible.module_utils.basic import AnsibleModule diff --git a/lib/ansible/modules/packaging/language/cpanm.py b/lib/ansible/modules/packaging/language/cpanm.py index 8f9129ec8c..f3fc7fd448 100644 --- a/lib/ansible/modules/packaging/language/cpanm.py +++ b/lib/ansible/modules/packaging/language/cpanm.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2012, Franck Cuny -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -135,6 +124,11 @@ EXAMPLES = ''' version: '1.0' ''' +import os + +from ansible.module_utils.basic import AnsibleModule + + def _is_package_installed(module, name, locallib, cpanm, version): cmd = "" if locallib: @@ -233,8 +227,6 @@ def main(): module.exit_json(changed=changed, binary=cpanm, name=name) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/easy_install.py b/lib/ansible/modules/packaging/language/easy_install.py index fb0178afa6..ba261a5aa0 100644 --- a/lib/ansible/modules/packaging/language/easy_install.py +++ b/lib/ansible/modules/packaging/language/easy_install.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2012, Matt Wright -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -102,8 +91,12 @@ EXAMPLES = ''' virtualenv: /webapps/myapp/venv ''' -import tempfile +import os import os.path +import tempfile + +from ansible.module_utils.basic import AnsibleModule + def _is_package_installed(module, name, easy_install, executable_arguments): executable_arguments = executable_arguments + ['--dry-run'] @@ -208,8 +201,6 @@ def main(): module.exit_json(changed=changed, binary=easy_install, name=name, virtualenv=env) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/gem.py b/lib/ansible/modules/packaging/language/gem.py index 0ae4fd5dcf..d2e2280670 100644 --- a/lib/ansible/modules/packaging/language/gem.py +++ b/lib/ansible/modules/packaging/language/gem.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Johan Wiren -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -121,6 +110,9 @@ EXAMPLES = ''' import re +from ansible.module_utils.basic import AnsibleModule + + def get_rubygems_path(module): if module.params['executable']: return module.params['executable'].split(' ') @@ -276,8 +268,6 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index 9dd52ce443..92ded95419 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -6,18 +6,11 @@ # Built using https://github.com/hamnis/useful-scripts/blob/master/python/download-maven-artifact # as a reference and starting point. # -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This software 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 software. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -138,20 +131,23 @@ EXAMPLES = ''' dest: /var/lib/tomcat7/webapps/web-app.war ''' -from lxml import etree -import os import hashlib -import sys +import os import posixpath -import urlparse -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * +import sys + +from lxml import etree + try: import boto3 HAS_BOTO = True except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six.moves.urllib import parse as urlparse +from ansible.module_utils.urls import fetch_url + class Artifact(object): def __init__(self, group_id, artifact_id, version, classifier=None, extension='jar'): @@ -387,8 +383,6 @@ def main(): version = module.params["version"] classifier = module.params["classifier"] extension = module.params["extension"] - repository_username = module.params["username"] - repository_password = module.params["password"] state = module.params["state"] dest = module.params["dest"] @@ -423,6 +417,5 @@ def main(): module.fail_json(msg=e.args[0]) - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/npm.py b/lib/ansible/modules/packaging/language/npm.py index 1deb60c6fa..56670a206a 100644 --- a/lib/ansible/modules/packaging/language/npm.py +++ b/lib/ansible/modules/packaging/language/npm.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Chris Hoffman -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -125,16 +115,11 @@ EXAMPLES = ''' state: present ''' +import json import os +import re -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - # Let snippet from module_utils/basic.py return a proper error in this case - pass +from ansible.module_utils.basic import AnsibleModule class Npm(object): @@ -289,8 +274,6 @@ def main(): module.exit_json(changed=changed) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/pear.py b/lib/ansible/modules/packaging/language/pear.py index cdf6861513..3f3e3d801a 100644 --- a/lib/ansible/modules/packaging/language/pear.py +++ b/lib/ansible/modules/packaging/language/pear.py @@ -5,20 +5,11 @@ # (c) 2013, Aaron Bull Schaefer # (c) 2015, Jonathan Lestrelin # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -72,6 +63,9 @@ EXAMPLES = ''' import os +from ansible.module_utils.basic import AnsibleModule + + def get_local_version(pear_output): """Take pear remoteinfo output and get the installed version""" lines = pear_output.split('\n') @@ -235,8 +229,6 @@ def main(): elif p['state'] == 'absent': remove_packages(module, pkgs) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 6015bd25b2..126a4e4fef 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2012, Matt Wright -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . -# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -222,15 +211,16 @@ EXAMPLES = ''' become: True ''' -import tempfile -import re import os +import re import sys +import tempfile from ansible.module_utils.basic import AnsibleModule, is_executable from ansible.module_utils._text import to_native from ansible.module_utils.six import PY3 + #: Python one-liners to be run at the command line that will determine the # installed version for these special libraries. These are libraries that # don't end up in the output of pip freeze. @@ -594,5 +584,6 @@ def main(): if old_umask is not None: os.umask(old_umask) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/bzr.py b/lib/ansible/modules/source_control/bzr.py index f36920f797..fa56d4385b 100644 --- a/lib/ansible/modules/source_control/bzr.py +++ b/lib/ansible/modules/source_control/bzr.py @@ -3,21 +3,11 @@ # (c) 2013, André Paramés # Based on the Git module by Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -73,8 +63,11 @@ EXAMPLES = ''' version: 22 ''' +import os import re +from ansible.module_utils.basic import AnsibleModule + class Bzr(object): def __init__(self, module, parent, dest, version, bzr_path): @@ -167,7 +160,7 @@ def main(): bzrconfig = os.path.join(dest, '.bzr', 'branch', 'branch.conf') - rc, out, err, status = (0, None, None, None) + rc, out, err = (0, None, None) bzr = Bzr(module, parent, dest, version, bzr_path) @@ -202,8 +195,6 @@ def main(): module.exit_json(changed=changed, before=before, after=after) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/git.py b/lib/ansible/modules/source_control/git.py index d56d101ab5..a5f8d9b4da 100644 --- a/lib/ansible/modules/source_control/git.py +++ b/lib/ansible/modules/source_control/git.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2012, Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -277,7 +267,6 @@ import tempfile from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule, get_module_path -from ansible.module_utils.basic import get_exception from ansible.module_utils.six import b, string_types from ansible.module_utils._text import to_native @@ -962,12 +951,11 @@ def create_archive(git_path, module, dest, archive, version, repo, result): shutil.move(new_archive, archive) shutil.remove(tempdir) result.update(changed=True) - except OSError: - exception = get_exception() + except OSError as e: module.fail_json(msg="Failed to move %s to %s" % (new_archive, archive), details="Error occured while moving : %s" - % exception) + % to_native(e)) else: # Perform archive from local directory git_archive(git_path, module, dest, archive, archive_fmt, version) diff --git a/lib/ansible/modules/source_control/git_config.py b/lib/ansible/modules/source_control/git_config.py index fc7b9729b6..aeb905519d 100644 --- a/lib/ansible/modules/source_control/git_config.py +++ b/lib/ansible/modules/source_control/git_config.py @@ -4,20 +4,11 @@ # (c) 2015, Marius Gedminas # (c) 2016, Matthew Gamble # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -156,6 +147,7 @@ config_values: alias.diffc: "diff --cached" alias.remotev: "remote -v" ''' +from ansible.module_utils.basic import AnsibleModule def main(): @@ -251,7 +243,6 @@ def main(): changed=True ) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/github_deploy_key.py b/lib/ansible/modules/source_control/github_deploy_key.py index f69581a244..bf88625bfa 100644 --- a/lib/ansible/modules/source_control/github_deploy_key.py +++ b/lib/ansible/modules/source_control/github_deploy_key.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = { 'metadata_version': '1.0', @@ -176,9 +167,10 @@ id: sample: 24381901 ''' +import json + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url -import json class GithubDeployKey(object): diff --git a/lib/ansible/modules/source_control/github_hooks.py b/lib/ansible/modules/source_control/github_hooks.py index 22790f63e3..0ee82f4ceb 100644 --- a/lib/ansible/modules/source_control/github_hooks.py +++ b/lib/ansible/modules/source_control/github_hooks.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2013, Phillip Gentry -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# 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 . ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -90,16 +80,9 @@ EXAMPLES = ''' delegate_to: localhost ''' -try: - import json -except ImportError: - try: - import simplejson as json - except ImportError: - # Let snippet from module_utils/basic.py return a proper error in this case - pass - import base64 +import json + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url diff --git a/lib/ansible/modules/source_control/github_issue.py b/lib/ansible/modules/source_control/github_issue.py index 73fb8e2156..b202e5abb3 100644 --- a/lib/ansible/modules/source_control/github_issue.py +++ b/lib/ansible/modules/source_control/github_issue.py @@ -1,20 +1,10 @@ #!/usr/bin/python # (c) 2017, Abhijeet Kasurde -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -86,6 +76,7 @@ try: HAS_GITHUB_PACKAGE = True except ImportError: HAS_GITHUB_PACKAGE = False + from ansible.module_utils.basic import AnsibleModule @@ -125,5 +116,6 @@ def main(): module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/github_key.py b/lib/ansible/modules/source_control/github_key.py index 39c4ef5d69..bde84c8366 100644 --- a/lib/ansible/modules/source_control/github_key.py +++ b/lib/ansible/modules/source_control/github_key.py @@ -1,18 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible # -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -89,10 +82,12 @@ EXAMPLES = ''' ''' -import sys # noqa import json import re +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url + API_BASE = 'https://api.github.com' @@ -241,8 +236,6 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.urls import * # noqa if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/github_release.py b/lib/ansible/modules/source_control/github_release.py index 9839282ded..f88106edf8 100644 --- a/lib/ansible/modules/source_control/github_release.py +++ b/lib/ansible/modules/source_control/github_release.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# Copyright: Ansible Team +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -138,7 +129,9 @@ try: HAS_GITHUB_API = True except ImportError: HAS_GITHUB_API = False -from ansible.module_utils.basic import AnsibleModule, get_exception + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native def main(): @@ -188,9 +181,8 @@ def main(): # test if we're actually logged in gh_obj.me() - except github3.AuthenticationFailed: - e = get_exception() - module.fail_json(msg='Failed to connect to GitHub: %s' % e, + except github3.AuthenticationFailed as e: + module.fail_json(msg='Failed to connect to GitHub: %s' % to_native(e), details="Please check username and password or token " "for repository %s" % repo) diff --git a/lib/ansible/modules/source_control/gitlab_group.py b/lib/ansible/modules/source_control/gitlab_group.py index 26f9c9abb4..ac00818033 100644 --- a/lib/ansible/modules/source_control/gitlab_group.py +++ b/lib/ansible/modules/source_control/gitlab_group.py @@ -1,20 +1,10 @@ #!/usr/bin/python # (c) 2015, Werner Dijkerman (ikben@werner-dijkerman.nl) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -108,8 +98,9 @@ try: except: HAS_GITLAB_PACKAGE = False -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + class GitLabGroup(object): def __init__(self, module, git): @@ -197,9 +188,8 @@ def main(): git.login(user=login_user, password=login_password) else: git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl) - except Exception: - e = get_exception() - module.fail_json(msg="Failed to connect to Gitlab server: %s " % e) + except Exception as e: + module.fail_json(msg="Failed to connect to Gitlab server: %s " % to_native(e)) # Check if user is authorized or not before proceeding to any operations # if not, exit from here @@ -228,7 +218,5 @@ def main(): module.exit_json(changed=True, result="Successfully created or updated the group %s" % group_name) - - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/gitlab_project.py b/lib/ansible/modules/source_control/gitlab_project.py index 34f558f9b3..ebe0db6ed7 100644 --- a/lib/ansible/modules/source_control/gitlab_project.py +++ b/lib/ansible/modules/source_control/gitlab_project.py @@ -1,20 +1,10 @@ #!/usr/bin/python # (c) 2015, Werner Dijkerman (ikben@werner-dijkerman.nl) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -170,8 +160,8 @@ try: except: HAS_GITLAB_PACKAGE = False -from ansible.module_utils.basic import * -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native class GitLabProject(object): @@ -371,9 +361,8 @@ def main(): git.login(user=login_user, password=login_password) else: git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl) - except Exception: - e = get_exception() - module.fail_json(msg="Failed to connect to Gitlab server: %s " % e) + except Exception as e: + module.fail_json(msg="Failed to connect to Gitlab server: %s " % to_native(e)) # Check if user is authorized or not before proceeding to any operations # if not, exit from here @@ -411,6 +400,5 @@ def main(): module.exit_json(changed=False) - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/gitlab_user.py b/lib/ansible/modules/source_control/gitlab_user.py index b4c4662d12..385906647f 100644 --- a/lib/ansible/modules/source_control/gitlab_user.py +++ b/lib/ansible/modules/source_control/gitlab_user.py @@ -1,20 +1,10 @@ #!/usr/bin/python # (c) 2015, Werner Dijkerman (ikben@werner-dijkerman.nl) -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -151,8 +141,8 @@ try: except: HAS_GITLAB_PACKAGE = False -from ansible.module_utils.pycompat24 import get_exception -from ansible.module_utils.basic import * +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native class GitLabUser(object): @@ -195,8 +185,6 @@ class GitLabUser(object): # Create the user user_username = arguments['username'] - user_name = arguments['name'] - user_email = arguments['email'] if self._gitlab.createuser(password=user_password, confirm=confirm, **arguments): user_id = self.getUserId(user_username) if self._gitlab.addsshkeyuser(user_id=user_id, title=user_sshkey_name, key=user_sshkey_file): @@ -344,9 +332,8 @@ def main(): git.login(user=login_user, password=login_password) else: git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl) - except Exception: - e = get_exception() - module.fail_json(msg="Failed to connect to Gitlab server: %s " % e) + except Exception as e: + module.fail_json(msg="Failed to connect to Gitlab server: %s " % to_native(e)) # Check if user is authorized or not before proceeding to any operations # if not, exit from here @@ -370,6 +357,5 @@ def main(): user.createOrUpdateUser(user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level, confirm) - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/source_control/hg.py b/lib/ansible/modules/source_control/hg.py index 9cb9e97982..c435983250 100644 --- a/lib/ansible/modules/source_control/hg.py +++ b/lib/ansible/modules/source_control/hg.py @@ -4,24 +4,11 @@ # (c) 2013, Yeukhon Wong # (c) 2014, Nate Coraor # -# This module was originally inspired by Brad Olson's ansible-module-mercurial -# . This module tends -# to follow the git module implementation. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -117,10 +104,10 @@ EXAMPLES = ''' import os -# import module snippets from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native + class Hg(object): def __init__(self, module, dest, repo, revision, hg_path): diff --git a/lib/ansible/modules/source_control/subversion.py b/lib/ansible/modules/source_control/subversion.py index 7f4db6bc06..afcb772413 100644 --- a/lib/ansible/modules/source_control/subversion.py +++ b/lib/ansible/modules/source_control/subversion.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2012, Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# 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 . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -127,8 +117,10 @@ EXAMPLES = ''' update: no ''' +import os import re -import tempfile + +from ansible.module_utils.basic import AnsibleModule class Subversion(object): @@ -309,8 +301,6 @@ def main(): changed = before != after or local_mods module.exit_json(changed=changed, before=before, after=after) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/test/sanity/code-smell/boilerplate.sh b/test/sanity/code-smell/boilerplate.sh index 279582a4e4..b03b6b9a5e 100755 --- a/test/sanity/code-smell/boilerplate.sh +++ b/test/sanity/code-smell/boilerplate.sh @@ -19,55 +19,37 @@ future2=$(find ./lib/ansible -path ./lib/ansible/modules -prune \ # Eventually we want metaclass3 and future3 to get down to 0 metaclass3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -prune \ - -o -path ./lib/ansible/modules/source_control -prune \ - -o -path ./lib/ansible/modules/packaging -prune \ - -o -path ./lib/ansible/modules/notification -prune \ + -o -path ./lib/ansible/modules/packaging/os -prune \ -o -path ./lib/ansible/modules/network -prune \ -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/identity -prune \ -o -path ./lib/ansible/modules/files -prune \ -o -path ./lib/ansible/modules/database -prune \ - -o -path ./lib/ansible/modules/cloud/vmware -prune \ - -o -path ./lib/ansible/modules/cloud/rackspace -prune \ -o -path ./lib/ansible/modules/cloud/ovirt -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \ - -o -path ./lib/ansible/modules/cloud/google -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ - -o -path ./lib/ansible/modules/cloud/centurylink -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -name '*.py' -type f -size +0c -exec grep -HL '__metaclass__ = type' '{}' '+') future3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -prune \ - -o -path ./lib/ansible/modules/source_control -prune \ - -o -path ./lib/ansible/modules/packaging -prune \ - -o -path ./lib/ansible/modules/notification -prune \ + -o -path ./lib/ansible/modules/packaging/os -prune \ -o -path ./lib/ansible/modules/network -prune \ -o -path ./lib/ansible/modules/monitoring -prune \ -o -path ./lib/ansible/modules/identity -prune \ -o -path ./lib/ansible/modules/files -prune \ -o -path ./lib/ansible/modules/database -prune \ - -o -path ./lib/ansible/modules/cloud/vmware -prune \ - -o -path ./lib/ansible/modules/cloud/rackspace -prune \ -o -path ./lib/ansible/modules/cloud/ovirt -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \ - -o -path ./lib/ansible/modules/cloud/google -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ - -o -path ./lib/ansible/modules/cloud/centurylink -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -name '*.py' -type f -size +0c -exec egrep -HL 'from __future__ import (?absolute_import, division, print_function)?' '{}' '+') # Ordered by approximate work, lowest to highest # identity ! -# cloud/centurylink * -# source_control *i # files ! -# cloud/google * -# notification *! # database ;; break up *! -# packaging ;; breakup *! -# cloud/rackspace * -# cloud/vmware *i # monitoring *! +# packaging/os *i # cloud/cloudstack * # cloud/openstack * # cloud/ovirt diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 207346c967..9c5f4c12fc 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -106,7 +106,6 @@ lib/ansible/modules/cloud/google/gce_net.py lib/ansible/modules/cloud/google/gce_pd.py lib/ansible/modules/cloud/google/gce_tag.py lib/ansible/modules/cloud/google/gcpubsub.py -lib/ansible/modules/cloud/google/gcpubsub_facts.py lib/ansible/modules/cloud/google/gcspanner.py lib/ansible/modules/cloud/linode/linode.py lib/ansible/modules/cloud/lxc/lxc_container.py @@ -171,8 +170,6 @@ lib/ansible/modules/cloud/rackspace/rax_mon_check.py lib/ansible/modules/cloud/rackspace/rax_mon_entity.py lib/ansible/modules/cloud/rackspace/rax_mon_notification.py lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py -lib/ansible/modules/cloud/rackspace/rax_network.py -lib/ansible/modules/cloud/rackspace/rax_queue.py lib/ansible/modules/cloud/smartos/vmadm.py lib/ansible/modules/cloud/softlayer/sl_vm.py lib/ansible/modules/cloud/univention/udm_dns_record.py @@ -187,7 +184,6 @@ lib/ansible/modules/cloud/vmware/vmware_cluster.py lib/ansible/modules/cloud/vmware/vmware_dvswitch.py lib/ansible/modules/cloud/vmware/vmware_local_user_manager.py lib/ansible/modules/cloud/vmware/vmware_migrate_vmk.py -lib/ansible/modules/cloud/vmware/vmware_target_canonical_facts.py lib/ansible/modules/cloud/vmware/vmware_vmotion.py lib/ansible/modules/cloud/vmware/vsphere_copy.py lib/ansible/modules/cloud/vmware/vsphere_guest.py @@ -445,9 +441,6 @@ lib/ansible/modules/remote_management/hpilo/hpilo_facts.py lib/ansible/modules/remote_management/hpilo/hponcfg.py lib/ansible/modules/remote_management/stacki/stacki_host.py lib/ansible/modules/source_control/bzr.py -lib/ansible/modules/source_control/gitlab_group.py -lib/ansible/modules/source_control/gitlab_project.py -lib/ansible/modules/source_control/gitlab_user.py lib/ansible/modules/source_control/hg.py lib/ansible/modules/source_control/subversion.py lib/ansible/modules/storage/infinidat/infini_export.py