From 0b9a78f0b31be52db24180310c98b7b7629f440b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sat, 29 Jul 2017 14:14:16 -0700 Subject: [PATCH] Remove wildcard, add boilerplate and get rid of get_exception * smaller collections of database modules * Some of the smaller collections of network modules --- .../database/influxdb/influxdb_database.py | 23 ++---- .../influxdb/influxdb_retention_policy.py | 24 ++---- .../database/misc/elasticsearch_plugin.py | 25 +++--- .../modules/database/misc/kibana_plugin.py | 24 +++--- lib/ansible/modules/database/misc/redis.py | 57 ++++++-------- lib/ansible/modules/database/misc/riak.py | 41 +++------- .../database/mongodb/mongodb_parameter.py | 39 ++++------ .../modules/database/mongodb/mongodb_user.py | 20 ++--- .../modules/database/mssql/mssql_db.py | 28 +++---- .../modules/database/mysql/mysql_db.py | 57 ++++++-------- .../database/mysql/mysql_replication.py | 43 ++++------- .../modules/database/mysql/mysql_user.py | 58 ++++++-------- .../modules/database/mysql/mysql_variables.py | 54 +++++-------- .../database/postgresql/postgresql_db.py | 72 +++++++---------- .../database/postgresql/postgresql_ext.py | 43 ++++------- .../database/postgresql/postgresql_lang.py | 38 ++++----- .../database/postgresql/postgresql_privs.py | 20 ++--- .../database/postgresql/postgresql_schema.py | 50 +++++------- .../database/postgresql/postgresql_user.py | 74 +++++++----------- .../database/vertica/vertica_configuration.py | 47 ++++------- .../modules/database/vertica/vertica_facts.py | 37 ++++----- .../modules/database/vertica/vertica_role.py | 52 +++++-------- .../database/vertica/vertica_schema.py | 52 +++++-------- .../modules/database/vertica/vertica_user.py | 49 ++++-------- lib/ansible/modules/network/a10/a10_server.py | 33 +++----- .../modules/network/a10/a10_server_axapi3.py | 30 +++----- .../modules/network/a10/a10_service_group.py | 31 +++----- .../modules/network/a10/a10_virtual_server.py | 33 +++----- lib/ansible/modules/network/aci/aci_rest.py | 20 ++--- .../modules/network/aireos/aireos_command.py | 21 ++--- .../modules/network/aireos/aireos_config.py | 26 ++----- .../modules/network/aruba/aruba_command.py | 21 ++--- lib/ansible/modules/network/asa/asa_acl.py | 28 ++----- .../modules/network/asa/asa_command.py | 20 ++--- lib/ansible/modules/network/asa/asa_config.py | 34 +++----- .../modules/network/bigswitch/bcf_switch.py | 38 ++++----- .../modules/network/bigswitch/bigmon_chain.py | 38 ++++----- .../network/bigswitch/bigmon_policy.py | 39 ++++------ .../modules/network/citrix/netscaler.py | 36 +++------ .../modules/network/cumulus/_cl_bond.py | 17 ++-- .../modules/network/cumulus/_cl_bridge.py | 17 ++-- .../network/cumulus/_cl_img_install.py | 22 ++---- .../modules/network/cumulus/_cl_interface.py | 18 ++--- .../network/cumulus/_cl_interface_policy.py | 27 +++---- .../modules/network/cumulus/_cl_license.py | 20 ++--- .../modules/network/cumulus/_cl_ports.py | 48 +++++------- lib/ansible/modules/network/cumulus/nclu.py | 24 +++--- .../network/dellos10/dellos10_command.py | 24 ++---- .../network/dellos10/dellos10_config.py | 24 ++---- .../network/dellos10/dellos10_facts.py | 28 ++----- .../network/dellos6/dellos6_command.py | 22 ++---- .../modules/network/dellos6/dellos6_config.py | 25 ++---- .../modules/network/dellos6/dellos6_facts.py | 35 +++------ .../network/dellos9/dellos9_command.py | 22 ++---- .../modules/network/dellos9/dellos9_config.py | 25 ++---- .../modules/network/dellos9/dellos9_facts.py | 29 ++----- .../modules/network/fortios/fortios_config.py | 40 +++------- .../network/fortios/fortios_ipv4_policy.py | 59 ++++++-------- .../network/illumos/dladm_etherstub.py | 23 ++---- .../modules/network/illumos/dladm_iptun.py | 21 ++--- .../modules/network/illumos/dladm_linkprop.py | 21 ++--- .../modules/network/illumos/dladm_vlan.py | 21 ++--- .../modules/network/illumos/dladm_vnic.py | 23 ++---- .../modules/network/illumos/flowadm.py | 26 ++----- .../modules/network/illumos/ipadm_addr.py | 23 ++---- .../modules/network/illumos/ipadm_addrprop.py | 21 ++--- .../modules/network/illumos/ipadm_if.py | 23 ++---- .../modules/network/illumos/ipadm_ifprop.py | 22 ++---- .../modules/network/illumos/ipadm_prop.py | 26 ++----- .../network/interface/net_interface.py | 21 ++--- .../modules/network/interface/net_linkagg.py | 21 ++--- .../network/interface/net_lldp_interface.py | 21 ++--- .../modules/network/iosxr/iosxr_banner.py | 22 ++---- .../modules/network/iosxr/iosxr_command.py | 28 +++---- .../modules/network/iosxr/iosxr_config.py | 26 +++---- .../modules/network/iosxr/iosxr_facts.py | 25 ++---- .../modules/network/iosxr/iosxr_logging.py | 21 ++--- .../modules/network/iosxr/iosxr_system.py | 20 ++--- .../modules/network/iosxr/iosxr_user.py | 24 ++---- .../network/layer2/net_l2_interface.py | 21 ++--- .../network/layer2/net_lldp_interface.py | 21 ++--- .../modules/network/layer2/net_vlan.py | 21 ++--- .../network/layer3/net_l3_interface.py | 21 ++--- lib/ansible/modules/network/layer3/net_vrf.py | 21 ++--- .../modules/network/netconf/netconf_config.py | 49 ++++-------- .../network/netscaler/netscaler_cs_action.py | 36 +++------ .../netscaler/netscaler_save_config.py | 27 ++----- .../network/netscaler/netscaler_server.py | 28 ++----- .../network/netscaler/netscaler_service.py | 27 +++---- .../modules/network/nuage/nuage_vspk.py | 23 ++---- .../modules/network/openswitch/ops_command.py | 38 ++++----- .../modules/network/openswitch/ops_config.py | 31 +++----- .../modules/network/openswitch/ops_facts.py | 22 ++---- .../network/ordnance/ordnance_config.py | 34 +++----- .../network/ordnance/ordnance_facts.py | 24 ++---- .../modules/network/ovs/openvswitch_bridge.py | 29 ++----- .../modules/network/ovs/openvswitch_db.py | 35 ++------- .../modules/network/ovs/openvswitch_port.py | 26 ++----- .../modules/network/protocol/net_lldp.py | 21 ++--- .../network/routing/net_static_route.py | 21 ++--- .../modules/network/sros/sros_command.py | 27 +++---- .../modules/network/sros/sros_config.py | 28 +++---- .../modules/network/sros/sros_rollback.py | 24 ++---- .../modules/network/system/net_banner.py | 22 ++---- .../modules/network/system/net_command.py | 21 ++--- .../modules/network/system/net_logging.py | 21 ++--- .../modules/network/system/net_system.py | 21 ++--- .../modules/network/system/net_user.py | 21 ++--- test/sanity/code-smell/boilerplate.sh | 77 ++++++++++++++----- test/sanity/pep8/legacy-files.txt | 2 - 110 files changed, 1095 insertions(+), 2225 deletions(-) diff --git a/lib/ansible/modules/database/influxdb/influxdb_database.py b/lib/ansible/modules/database/influxdb/influxdb_database.py index 93fefac8d2a..4c524ab77ca 100644 --- a/lib/ansible/modules/database/influxdb/influxdb_database.py +++ b/lib/ansible/modules/database/influxdb/influxdb_database.py @@ -1,21 +1,11 @@ #!/usr/bin/python # (c) 2016, Kamil Szczygiel -# -# 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,8 @@ try: except ImportError: HAS_INFLUXDB = False +from ansible.module_utils.basic import AnsibleModule + def influxdb_argument_spec(): return dict( @@ -193,7 +185,6 @@ def main(): else: module.exit_json(changed=False) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py b/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py index 847cf83379b..a9b238ad571 100644 --- a/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py +++ b/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py @@ -1,21 +1,11 @@ #!/usr/bin/python # (c) 2016, Kamil Szczygiel -# -# 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'], @@ -115,6 +105,7 @@ RETURN = ''' ''' import re + try: import requests.exceptions from influxdb import InfluxDBClient @@ -123,6 +114,8 @@ try: except ImportError: HAS_INFLUXDB = False +from ansible.module_utils.basic import AnsibleModule + def influxdb_argument_spec(): return dict( @@ -238,7 +231,6 @@ def main(): else: create_retention_policy(module, client) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/misc/elasticsearch_plugin.py b/lib/ansible/modules/database/misc/elasticsearch_plugin.py index 0a78c6e9cab..108d32548b1 100644 --- a/lib/ansible/modules/database/misc/elasticsearch_plugin.py +++ b/lib/ansible/modules/database/misc/elasticsearch_plugin.py @@ -1,22 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Ansible module to manage elasticsearch plugins # (c) 2015, Mathew Davies -# -# 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,11 +92,15 @@ EXAMPLES = ''' import os +from ansible.module_utils.basic import AnsibleModule + + PACKAGE_STATE_MAP = dict( present="install", absent="remove" ) + def parse_plugin_repo(string): elements = string.split("/") @@ -219,7 +213,6 @@ def main(): module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/misc/kibana_plugin.py b/lib/ansible/modules/database/misc/kibana_plugin.py index 3ce5d9a413d..103619fea32 100644 --- a/lib/ansible/modules/database/misc/kibana_plugin.py +++ b/lib/ansible/modules/database/misc/kibana_plugin.py @@ -1,23 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Ansible module to manage elasticsearch shield role # (c) 2016, Thierno IB. BARRY @barryib # Sponsored by Polyconseil http://polyconseil.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'], @@ -129,11 +120,15 @@ state: import os +from ansible.module_utils.basic import AnsibleModule + + PACKAGE_STATE_MAP = dict( present="--install", absent="--remove" ) + def parse_plugin_repo(string): elements = string.split("/") @@ -241,7 +236,6 @@ def main(): module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/misc/redis.py b/lib/ansible/modules/database/misc/redis.py index 225e5c62b95..921b9110a4f 100644 --- a/lib/ansible/modules/database/misc/redis.py +++ b/lib/ansible/modules/database/misc/redis.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'], @@ -141,6 +133,7 @@ EXAMPLES = ''' name: lua-time-limit value: 100 ''' +import traceback try: import redis @@ -149,6 +142,9 @@ except ImportError: else: redis_found = True +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + # =========================================== # Redis module specific support methods. @@ -231,9 +227,9 @@ def main(): password=login_password) try: r.ping() - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), + exception=traceback.format_exc()) #Check if we are already in the mode that we want info = r.info() @@ -291,9 +287,9 @@ def main(): db=db) try: r.ping() - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), + exception=traceback.format_exc()) # Do the stuff # (Check Check_mode before commands so the commands aren't evaluated @@ -319,16 +315,16 @@ def main(): try: r.ping() - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), + exception=traceback.format_exc()) try: old_value = r.config_get(name)[name] - except Exception: - e = get_exception() - module.fail_json(msg="unable to read config: %s" % e) + except Exception as e: + module.fail_json(msg="unable to read config: %s" % to_native(e), + exception=traceback.format_exc()) changed = old_value != value if module.check_mode or not changed: @@ -336,16 +332,13 @@ def main(): else: try: r.config_set(name, value) - except Exception: - e = get_exception() - module.fail_json(msg="unable to write config: %s" % e) + except Exception as e: + module.fail_json(msg="unable to write config: %s" % to_native(e), + exception=traceback.format_exc()) module.exit_json(changed=changed, name=name, value=value) else: module.fail_json(msg='A valid command must be provided') -# 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/database/misc/riak.py b/lib/ansible/modules/database/misc/riak.py index 44a963251f1..1e4ff06f03d 100644 --- a/lib/ansible/modules/database/misc/riak.py +++ b/lib/ansible/modules/database/misc/riak.py @@ -2,22 +2,12 @@ # -*- coding: utf-8 -*- # (c) 2013, James Martin , Drew Kerrigan -# -# 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'], 'supported_by': 'community'} @@ -97,18 +87,11 @@ EXAMPLES = ''' wait_for_service: kv ''' +import json import time -import socket -import sys -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 +from ansible.module_utils.urls import fetch_url def ring_check(module, riak_admin_bin): @@ -137,13 +120,11 @@ def main(): command = module.params.get('command') - config_dir = module.params.get('config_dir') http_conn = module.params.get('http_conn') target_node = module.params.get('target_node') wait_for_handoffs = module.params.get('wait_for_handoffs') wait_for_ring = module.params.get('wait_for_ring') wait_for_service = module.params.get('wait_for_service') - validate_certs = module.params.get('validate_certs') #make sure riak commands are on the path @@ -255,8 +236,6 @@ def main(): module.exit_json(**result) -# 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/database/mongodb/mongodb_parameter.py b/lib/ansible/modules/database/mongodb/mongodb_parameter.py index 82786b8f547..567cbd53583 100644 --- a/lib/ansible/modules/database/mongodb/mongodb_parameter.py +++ b/lib/ansible/modules/database/mongodb/mongodb_parameter.py @@ -1,26 +1,15 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -(c) 2016, Loic Blot -Sponsored by Infopro Digital. http://www.infopro-digital.com/ -Sponsored by E.T.A.I. http://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. +# (c) 2016, Loic Blot +# Sponsored by Infopro Digital. http://www.infopro-digital.com/ +# Sponsored by E.T.A.I. http://www.etai.fr/ +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -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. +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -115,6 +104,7 @@ after: ''' import os +import traceback try: from pymongo.errors import ConnectionFailure @@ -132,8 +122,8 @@ else: pymongo_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.six.moves import configparser +from ansible.module_utils._text import to_native # ========================================= @@ -197,7 +187,6 @@ def main(): if param_type == 'int': value = int(value) except ValueError: - e = get_exception() module.fail_json(msg="value '%s' is not %s" % (value, param_type)) try: @@ -217,17 +206,15 @@ def main(): if login_user is not None and login_password is not None: client.admin.authenticate(login_user, login_password, source=login_database) - except ConnectionFailure: - e = get_exception() - module.fail_json(msg='unable to connect to database: %s' % str(e)) + except ConnectionFailure as e: + module.fail_json(msg='unable to connect to database: %s' % to_native(e), exception=traceback.format_exc()) db = client.admin try: after_value = db.command("setParameter", **{param: value}) - except OperationFailure: - e = get_exception() - module.fail_json(msg="unable to change parameter: %s" % str(e)) + except OperationFailure as e: + module.fail_json(msg="unable to change parameter: %s" % to_native(e), exception=traceback.format_exc()) if "was" not in after_value: module.exit_json(changed=True, msg="Unable to determine old value, assume it changed.") diff --git a/lib/ansible/modules/database/mongodb/mongodb_user.py b/lib/ansible/modules/database/mongodb/mongodb_user.py index ed9e43b7edc..5a295d01ad5 100644 --- a/lib/ansible/modules/database/mongodb/mongodb_user.py +++ b/lib/ansible/modules/database/mongodb/mongodb_user.py @@ -4,20 +4,11 @@ # Sponsored by Four Kitchens http://fourkitchens.com. # (c) 2014, Epic Games, 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'], @@ -390,7 +381,6 @@ def main(): user = module.params['name'] password = module.params['password'] ssl = module.params['ssl'] - ssl_cert_reqs = None roles = module.params['roles'] or [] state = module.params['state'] update_password = module.params['update_password'] diff --git a/lib/ansible/modules/database/mssql/mssql_db.py b/lib/ansible/modules/database/mssql/mssql_db.py index 6929b7b6c3a..e4134c645a9 100644 --- a/lib/ansible/modules/database/mssql/mssql_db.py +++ b/lib/ansible/modules/database/mssql/mssql_db.py @@ -1,24 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Ansible module to manage mssql databases # (c) 2014, Vedit Firat Arig # Outline and parts are reused from Mark Theunissen's mysql_db module -# -# 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'], @@ -107,6 +96,7 @@ RETURN = ''' ''' import os + try: import pymssql except ImportError: @@ -114,6 +104,8 @@ except ImportError: else: mssql_found = True +from ansible.module_utils.basic import AnsibleModule + def db_exists(conn, cursor, db): cursor.execute("SELECT name FROM master.sys.databases WHERE name = %s", db) @@ -241,8 +233,6 @@ def main(): module.exit_json(changed=changed, db=db) -# import module snippets -from ansible.module_utils.basic import * + if __name__ == '__main__': main() - diff --git a/lib/ansible/modules/database/mysql/mysql_db.py b/lib/ansible/modules/database/mysql/mysql_db.py index f3bf10611ab..947d8c8edac 100644 --- a/lib/ansible/modules/database/mysql/mysql_db.py +++ b/lib/ansible/modules/database/mysql/mysql_db.py @@ -3,21 +3,11 @@ # (c) 2012, Mark Theunissen # Sponsored by Four Kitchens http://fourkitchens.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 = {'metadata_version': '1.0', 'status': ['preview'], @@ -114,8 +104,8 @@ EXAMPLES = ''' import os import pipes -import stat import subprocess +import traceback try: import MySQLdb @@ -124,6 +114,12 @@ except ImportError: else: mysqldb_found = True +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.database import mysql_quote_identifier +from ansible.module_utils.mysql import mysql_connect, mysqldb_found +from ansible.module_utils._text import to_native + + # =========================================== # MySQL module specific support methods. # @@ -316,13 +312,12 @@ def main(): try: cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, connect_timeout=connect_timeout) - except Exception: - e = get_exception() + except Exception as e: if os.path.exists(config_file): module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " - "Exception message: %s" % (config_file, e)) + "Exception message: %s" % (config_file, to_native(e))) else: - module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e)) + module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e))) changed = False if not os.path.exists(config_file): @@ -334,9 +329,8 @@ def main(): else: try: changed = db_delete(cursor, db) - except Exception: - e = get_exception() - module.fail_json(msg="error deleting database: " + str(e)) + except Exception as e: + module.fail_json(msg="error deleting database: %s" % to_native(e)) module.exit_json(changed=changed, db=db) elif state == "dump": @@ -378,9 +372,9 @@ def main(): else: try: changed = db_create(cursor, db, encoding, collation) - except Exception: - e = get_exception() - module.fail_json(msg="error creating database: " + str(e)) + except Exception as e: + module.fail_json(msg="error creating database: %s" % to_native(e), + exception=traceback.format_exc()) module.exit_json(changed=changed, db=db) elif state == "import": @@ -397,9 +391,9 @@ def main(): module.fail_json(msg="%s" % stderr) else: module.exit_json(changed=True, db=db, msg=stdout) - except Exception: - e = get_exception() - module.fail_json(msg="error creating database: " + str(e)) + except Exception as e: + module.fail_json(msg="error creating database: %s" % to_native(e), + exception=traceback.format_exc()) elif state == "absent": if module.check_mode: @@ -411,9 +405,6 @@ def main(): module.exit_json(changed=False, db=db) module.fail_json(msg="Cannot dump database %s - not found" % (db)) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.database import * -from ansible.module_utils.mysql import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/mysql/mysql_replication.py b/lib/ansible/modules/database/mysql/mysql_replication.py index 24c8e1bc8aa..2baf14918b8 100644 --- a/lib/ansible/modules/database/mysql/mysql_replication.py +++ b/lib/ansible/modules/database/mysql/mysql_replication.py @@ -1,26 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" +# (c) 2013, Balazs Pocze +# Certain parts are taken from Mark Theunissen's mysqldb module +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -Ansible module to manage mysql replication -(c) 2013, Balazs Pocze -Certain parts are taken from Mark Theunissen's mysqldb module +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'], @@ -142,7 +130,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.mysql import mysql_connect -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native def get_master_status(cursor): @@ -265,13 +253,12 @@ def main(): try: cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, None, 'MySQLdb.cursors.DictCursor', connect_timeout=connect_timeout) - except Exception: - e = get_exception() + except Exception as e: if os.path.exists(config_file): module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " - "Exception message: %s" % (config_file, e)) + "Exception message: %s" % (config_file, to_native(e))) else: - module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e)) + module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e))) if mode in "getmaster": status = get_master_status(cursor) @@ -341,12 +328,10 @@ def main(): chm.append("MASTER_AUTO_POSITION = 1") try: changemaster(cursor, chm, chm_params) - except MySQLdb.Warning: - e = get_exception() - result['warning'] = str(e) - except Exception: - e = get_exception() - module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (e, chm)) + except MySQLdb.Warning as e: + result['warning'] = to_native(e) + except Exception as e: + module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (to_native(e), chm)) result['changed'] = True module.exit_json(**result) elif mode in "startslave": diff --git a/lib/ansible/modules/database/mysql/mysql_user.py b/lib/ansible/modules/database/mysql/mysql_user.py index 49c7a173268..c9f69b0b3e4 100644 --- a/lib/ansible/modules/database/mysql/mysql_user.py +++ b/lib/ansible/modules/database/mysql/mysql_user.py @@ -2,21 +2,11 @@ # (c) 2012, Mark Theunissen # Sponsored by Four Kitchens http://fourkitchens.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 = {'metadata_version': '1.0', 'status': ['preview'], @@ -214,16 +204,23 @@ EXAMPLES = """ # password=n<_665{vS43y """ - import re import string +import traceback + try: import MySQLdb except ImportError: mysqldb_found = False else: mysqldb_found = True + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.database import SQLParseError +from ansible.module_utils.mysql import mysql_connect, mysqldb_found from ansible.module_utils.six import iteritems +from ansible.module_utils._text import to_native + VALID_PRIVS = frozenset(('CREATE', 'DROP', 'GRANT', 'GRANT OPTION', 'LOCK TABLES', 'REFERENCES', 'EVENT', 'ALTER', @@ -608,10 +605,9 @@ def main(): if not cursor: cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db, connect_timeout=connect_timeout) - except Exception: - e = get_exception() + except Exception as e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " - "Exception message: %s" % (config_file, e)) + "Exception message: %s" % (config_file, to_native(e))) if not sql_log_bin: cursor.execute("SET SQL_LOG_BIN=0;") @@ -619,14 +615,12 @@ def main(): if priv is not None: try: mode = get_mode(cursor) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) try: priv = privileges_unpack(priv, mode) - except Exception: - e = get_exception() - module.fail_json(msg="invalid privileges string: %s" % str(e)) + except Exception as e: + module.fail_json(msg="invalid privileges string: %s" % to_native(e)) if state == "present": if user_exists(cursor, user, host, host_all): @@ -636,17 +630,15 @@ def main(): else: changed = user_mod(cursor, user, host, host_all, None, encrypted, priv, append_privs, module) - except (SQLParseError, InvalidPrivsError, MySQLdb.Error): - e = get_exception() - module.fail_json(msg=str(e)) + except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) else: if host_all: module.fail_json(msg="host_all parameter cannot be used when adding a user") try: changed = user_add(cursor, user, host, host_all, password, encrypted, priv, module.check_mode) - except (SQLParseError, InvalidPrivsError, MySQLdb.Error): - e = get_exception() - module.fail_json(msg=str(e)) + except (SQLParseError, InvalidPrivsError, MySQLdb.Error) as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state == "absent": if user_exists(cursor, user, host, host_all): changed = user_delete(cursor, user, host, host_all, module.check_mode) @@ -654,10 +646,6 @@ def main(): changed = False module.exit_json(changed=changed, user=user) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.database import * -from ansible.module_utils.mysql import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/mysql/mysql_variables.py b/lib/ansible/modules/database/mysql/mysql_variables.py index 0f6950c7b57..190fe008006 100644 --- a/lib/ansible/modules/database/mysql/mysql_variables.py +++ b/lib/ansible/modules/database/mysql/mysql_variables.py @@ -1,26 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" +# (c) 2013, Balazs Pocze +# Certain parts are taken from Mark Theunissen's mysqldb module +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -Ansible module to manage mysql variables -(c) 2013, Balazs Pocze -Certain parts are taken from Mark Theunissen's mysqldb module +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'], @@ -58,7 +46,7 @@ EXAMPLES = ''' value: 1 ''' - +import os import warnings from re import match @@ -69,6 +57,11 @@ except ImportError: else: mysqldb_found = True +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.database import SQLParseError, mysql_quote_identifier +from ansible.module_utils.mysql import mysql_connect, mysqldb_found +from ansible.module_utils._text import to_native + def typedvalue(value): """ @@ -118,9 +111,8 @@ def setvariable(cursor, mysqlvar, value): cursor.execute(query + "%s", (value,)) cursor.fetchall() result = True - except Exception: - e = get_exception() - result = str(e) + except Exception as e: + result = to_native(e) return result @@ -164,13 +156,12 @@ def main(): try: cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db, connect_timeout=connect_timeout) - except Exception: - e = get_exception() + except Exception as e: if os.path.exists(config_file): module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " - "Exception message: %s" % (config_file, e)) + "Exception message: %s" % (config_file, to_native(e))) else: - module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e)) + module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e))) mysqlvar_val = getvariable(cursor, mysqlvar) if mysqlvar_val is None: @@ -185,17 +176,14 @@ def main(): module.exit_json(msg="Variable already set to requested value", changed=False) try: result = setvariable(cursor, mysqlvar, value_wanted) - except SQLParseError: - e = get_exception() - result = str(e) + except SQLParseError as e: + result = to_native(e) + if result is True: module.exit_json(msg="Variable change succeeded prev_value=%s" % value_actual, changed=True) else: module.fail_json(msg=result, changed=False) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.database import * -from ansible.module_utils.mysql import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/postgresql/postgresql_db.py b/lib/ansible/modules/database/postgresql/postgresql_db.py index f15510c5be8..a3a23f4845c 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_db.py +++ b/lib/ansible/modules/database/postgresql/postgresql_db.py @@ -1,20 +1,11 @@ #!/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': ['stableinterface'], @@ -120,6 +111,8 @@ EXAMPLES = ''' target_opts: "-n public" ''' +import traceback + HAS_PSYCOPG2 = False try: import psycopg2 @@ -132,13 +125,12 @@ except ImportError: pass else: HAS_PSYCOPG2 = True -from ansible.module_utils.six import iteritems - -import traceback import ansible.module_utils.postgres as pgutils +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.database import SQLParseError, pg_quote_identifier -from ansible.module_utils.basic import get_exception, AnsibleModule +from ansible.module_utils.six import iteritems +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -386,7 +378,6 @@ def main(): module.fail_json(msg="the python psycopg2 module is required") db = module.params["db"] - port = module.params["port"] owner = module.params["owner"] template = module.params["template"] encoding = module.params["encoding"] @@ -395,7 +386,6 @@ def main(): target = module.params["target"] target_opts = module.params["target_opts"] state = module.params["state"] - sslrootcert = module.params["ssl_rootcert"] changed = False # To use defaults values, keyword arguments must be absent, so @@ -435,20 +425,17 @@ def main(): db_connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) cursor = db_connection.cursor(cursor_factory=psycopg2.extras.DictCursor) - except pgutils.LibraryError: - e = get_exception() - module.fail_json(msg="unable to connect to database: {0}".format(str(e)), exception=traceback.format_exc()) + except pgutils.LibraryError as e: + module.fail_json(msg="unable to connect to database: {0}".format(to_native(e)), exception=traceback.format_exc()) - except TypeError: - e = get_exception() + except TypeError as e: if 'sslrootcert' in e.args[0]: - module.fail_json(msg='Postgresql server must be at least version 8.4 to support sslrootcert. Exception: {0}'.format(e), + module.fail_json(msg='Postgresql server must be at least version 8.4 to support sslrootcert. Exception: {0}'.format(to_native(e)), exception=traceback.format_exc()) - module.fail_json(msg="unable to connect to database: %s" % e, exception=traceback.format_exc()) + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e, exception=traceback.format_exc()) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) try: if module.check_mode: @@ -461,16 +448,14 @@ def main(): if state == "absent": try: changed = db_delete(cursor, db) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state == "present": try: changed = db_create(cursor, db, owner, template, encoding, lc_collate, lc_ctype) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state in ("dump", "restore"): method = state == "dump" and db_dump or db_restore @@ -480,19 +465,16 @@ def main(): module.fail_json(msg=stderr, stdout=stdout, rc=rc, cmd=cmd) else: module.exit_json(changed=True, msg=stdout, stderr=stderr, rc=rc, cmd=cmd) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e)) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) except SystemExit: # Avoid catching this on Python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg="Database query failed: %s" % e) + except Exception as e: + module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, db=db) diff --git a/lib/ansible/modules/database/postgresql/postgresql_ext.py b/lib/ansible/modules/database/postgresql/postgresql_ext.py index e9e9844a4c1..01f2f1a8b16 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_ext.py +++ b/lib/ansible/modules/database/postgresql/postgresql_ext.py @@ -1,20 +1,11 @@ #!/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'], @@ -81,6 +72,7 @@ EXAMPLES = ''' name: postgis db: acme ''' +import traceback try: import psycopg2 @@ -90,6 +82,10 @@ except ImportError: else: postgresqldb_found = True +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + + class NotSupportedError(Exception): pass @@ -142,7 +138,6 @@ def main(): db = module.params["db"] ext = module.params["ext"] - port = module.params["port"] state = module.params["state"] changed = False @@ -168,9 +163,8 @@ def main(): .ISOLATION_LEVEL_AUTOCOMMIT) cursor = db_connection.cursor( cursor_factory=psycopg2.extras.DictCursor) - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) try: if module.check_mode: @@ -184,18 +178,13 @@ def main(): elif state == "present": changed = ext_create(cursor, ext) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e)) - except Exception: - e = get_exception() - module.fail_json(msg="Database query failed: %s" % e) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except Exception as e: + module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, db=db, ext=ext) -# 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/database/postgresql/postgresql_lang.py b/lib/ansible/modules/database/postgresql/postgresql_lang.py index 8ee957b238c..d57ce454006 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_lang.py +++ b/lib/ansible/modules/database/postgresql/postgresql_lang.py @@ -2,21 +2,12 @@ # -*- coding: utf-8 -*- # # (c) 2014, Jens Depuydt -# -# 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'], 'supported_by': 'community'} @@ -151,6 +142,7 @@ EXAMPLES = ''' state: absent fail_on_drop: no ''' +import traceback try: import psycopg2 @@ -159,6 +151,10 @@ except ImportError: else: postgresqldb_found = True +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + + def lang_exists(cursor, lang): """Checks if language exists for db""" query = "SELECT lanname FROM pg_language WHERE lanname='%s'" % lang @@ -220,7 +216,6 @@ def main(): ) db = module.params["db"] - port = module.params["port"] lang = module.params["lang"] state = module.params["state"] trust = module.params["trust"] @@ -243,12 +238,10 @@ def main(): try: db_connection = psycopg2.connect(**kw) cursor = db_connection.cursor() - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) changed = False - lang_dropped = False - kw = dict(db=db,lang=lang,trust=trust) + kw = {'db': db, 'lang': lang, 'trust': trust} if state == "present": if lang_exists(cursor, lang): @@ -287,9 +280,6 @@ def main(): kw['changed'] = changed module.exit_json(**kw) -# 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/database/postgresql/postgresql_privs.py b/lib/ansible/modules/database/postgresql/postgresql_privs.py index c187909a01e..ae60c06e10b 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_privs.py +++ b/lib/ansible/modules/database/postgresql/postgresql_privs.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': ['stableinterface'], diff --git a/lib/ansible/modules/database/postgresql/postgresql_schema.py b/lib/ansible/modules/database/postgresql/postgresql_schema.py index 499e704e5ab..9f652684f48 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_schema.py +++ b/lib/ansible/modules/database/postgresql/postgresql_schema.py @@ -1,20 +1,11 @@ #!/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'], @@ -104,6 +95,8 @@ schema: sample: "acme" ''' +import traceback + try: import psycopg2 import psycopg2.extras @@ -112,10 +105,11 @@ except ImportError: else: postgresqldb_found = True -import traceback - +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.database import SQLParseError, pg_quote_identifier from ansible.module_utils._text import to_native + class NotSupportedError(Exception): pass @@ -235,8 +229,7 @@ def main(): .ISOLATION_LEVEL_AUTOCOMMIT) cursor = db_connection.cursor( cursor_factory=psycopg2.extras.DictCursor) - except Exception: - e = get_exception() + except Exception as e: module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) try: @@ -250,31 +243,24 @@ def main(): if state == "absent": try: changed = schema_delete(cursor, schema) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state == "present": try: changed = schema_create(cursor, schema, owner) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) except SystemExit: # Avoid catching this on Python 2.4 raise - except Exception: - e = get_exception() + except Exception as e: module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, schema=schema) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.database import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/database/postgresql/postgresql_user.py b/lib/ansible/modules/database/postgresql/postgresql_user.py index ff6deee3415..cab6bf3de9d 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_user.py +++ b/lib/ansible/modules/database/postgresql/postgresql_user.py @@ -1,20 +1,11 @@ #!/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': ['stableinterface'], @@ -209,13 +200,10 @@ EXAMPLES = ''' import itertools import re +import traceback from distutils.version import StrictVersion from hashlib import md5 -from ansible.module_utils.basic import get_exception, AnsibleModule -from ansible.module_utils.database import pg_quote_identifier, SQLParseError - - try: import psycopg2 import psycopg2.extras @@ -224,9 +212,12 @@ except ImportError: else: postgresqldb_found = True -from ansible.module_utils._text import to_bytes +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.database import pg_quote_identifier, SQLParseError +from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils.six import iteritems + FLAGS = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION') FLAGS_BY_VERSION = {'BYPASSRLS': '9.5.0'} @@ -378,13 +369,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted try: cursor.execute(' '.join(alter), query_password_data) changed = True - except psycopg2.InternalError: - e = get_exception() + except psycopg2.InternalError as e: if e.pgcode == '25006': # Handle errors due to read-only transactions indicated by pgcode 25006 # ERROR: cannot execute ALTER ROLE in a read-only transaction changed = False - module.fail_json(msg=e.pgerror) + module.fail_json(msg=e.pgerror, exception=traceback.format_exc()) return changed else: raise psycopg2.InternalError(e) @@ -420,13 +410,12 @@ def user_alter(db_connection, module, user, password, role_attr_flags, encrypted try: cursor.execute(' '.join(alter)) - except psycopg2.InternalError: - e = get_exception() + except psycopg2.InternalError as e: if e.pgcode == '25006': # Handle errors due to read-only transactions indicated by pgcode 25006 # ERROR: cannot execute ALTER ROLE in a read-only transaction changed = False - module.fail_json(msg=e.pgerror) + module.fail_json(msg=e.pgerror, exception=traceback.format_exc()) return changed else: raise psycopg2.InternalError(e) @@ -794,22 +783,19 @@ def main(): cursor = db_connection.cursor( cursor_factory=psycopg2.extras.DictCursor) - except TypeError: - e = get_exception() + except TypeError as e: if 'sslrootcert' in e.args[0]: module.fail_json( msg='Postgresql server must be at least version 8.4 to support sslrootcert') - module.fail_json(msg="unable to connect to database: %s" % e) + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) - except Exception: - e = get_exception() - module.fail_json(msg="unable to connect to database: %s" % e) + except Exception as e: + module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc()) try: role_attr_flags = parse_role_attrs(cursor, module.params["role_attr_flags"]) - except InvalidFlagsError: - e = get_exception() - module.fail_json(msg=str(e)) + except InvalidFlagsError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) kw = dict(user=user) changed = False @@ -820,21 +806,18 @@ def main(): try: changed = user_alter(db_connection, module, user, password, role_attr_flags, encrypted, expires, no_password_changes) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) else: try: changed = user_add(cursor, user, password, role_attr_flags, encrypted, expires) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) try: changed = grant_privileges(cursor, user, privs) or changed - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) else: if user_exists(cursor, user): if module.check_mode: @@ -844,9 +827,8 @@ def main(): try: changed = revoke_privileges(cursor, user, privs) user_removed = user_delete(cursor, user) - except SQLParseError: - e = get_exception() - module.fail_json(msg=str(e)) + except SQLParseError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) changed = changed or user_removed if fail_on_user and not user_removed: msg = "unable to remove user" diff --git a/lib/ansible/modules/database/vertica/vertica_configuration.py b/lib/ansible/modules/database/vertica/vertica_configuration.py index f0cd22616fb..97af16f70f3 100644 --- a/lib/ansible/modules/database/vertica/vertica_configuration.py +++ b/lib/ansible/modules/database/vertica/vertica_configuration.py @@ -1,20 +1,11 @@ #!/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'], @@ -79,6 +70,7 @@ EXAMPLES = """ - name: updating load_balance_policy vertica_configuration: name=failovertostandbyafter value='8 hours' """ +import traceback try: import pyodbc @@ -88,7 +80,6 @@ else: pyodbc_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native @@ -174,9 +165,9 @@ def main(): module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() - except Exception: - e = get_exception() - module.fail_json(msg="Unable to connect to database: {0}.".format(e)) + except Exception as e: + module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e)), + exception=traceback.format_exc()) try: configuration_facts = get_configuration_facts(cursor) @@ -185,21 +176,17 @@ def main(): else: try: changed = present(configuration_facts, cursor, parameter_name, current_value) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts}) - except CannotDropError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_configuration': configuration_facts}) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_configuration': configuration_facts}) + except CannotDropError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_configuration': configuration_facts}) except SystemExit: # avoid catching this on python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg=to_native(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_facts.py b/lib/ansible/modules/database/vertica/vertica_facts.py index ba0dcd3b16d..90d1a4372c5 100644 --- a/lib/ansible/modules/database/vertica/vertica_facts.py +++ b/lib/ansible/modules/database/vertica/vertica_facts.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'], @@ -71,6 +63,7 @@ EXAMPLES = """ - name: gathering vertica facts vertica_facts: db=db_name """ +import traceback try: import pyodbc @@ -80,7 +73,6 @@ else: pyodbc_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native @@ -255,9 +247,8 @@ def main(): module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() - except Exception: - e = get_exception() - module.fail_json(msg="Unable to connect to database: %s." % str(e)) + except Exception as e: + module.fail_json(msg="Unable to connect to database: %s." % to_native(e), exception=traceback.format_exc()) try: schema_facts = get_schema_facts(cursor) @@ -271,15 +262,13 @@ def main(): 'vertica_roles': role_facts, 'vertica_configuration': configuration_facts, 'vertica_nodes': node_facts}) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e)) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) except SystemExit: # avoid catching this on python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg=to_native(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) if __name__ == '__main__': diff --git a/lib/ansible/modules/database/vertica/vertica_role.py b/lib/ansible/modules/database/vertica/vertica_role.py index f0878083c64..0e052740b97 100644 --- a/lib/ansible/modules/database/vertica/vertica_role.py +++ b/lib/ansible/modules/database/vertica/vertica_role.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'], @@ -90,6 +82,7 @@ EXAMPLES = """ - name: creating a new vertica role with other role assigned vertica_role: name=role_name assigned_role=other_role_name state=present """ +import traceback try: import pyodbc @@ -99,7 +92,6 @@ else: pyodbc_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native @@ -218,9 +210,8 @@ def main(): module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() - except Exception: - e = get_exception() - module.fail_json(msg="Unable to connect to database: {0}.".format(e)) + except Exception as e: + module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e))) try: role_facts = get_role_facts(cursor) @@ -229,27 +220,22 @@ def main(): elif state == 'absent': try: changed = absent(role_facts, cursor, role, assigned_roles) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state == 'present': try: changed = present(role_facts, cursor, role, assigned_roles) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts}) - except CannotDropError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts}) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_roles': role_facts}) + except CannotDropError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_roles': role_facts}) except SystemExit: # avoid catching this on python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg=to_native(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_schema.py b/lib/ansible/modules/database/vertica/vertica_schema.py index 0546105a104..e4321a08737 100644 --- a/lib/ansible/modules/database/vertica/vertica_schema.py +++ b/lib/ansible/modules/database/vertica/vertica_schema.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'], @@ -114,6 +106,7 @@ EXAMPLES = """ db=db_name state=present """ +import traceback try: import pyodbc @@ -123,7 +116,6 @@ else: pyodbc_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native @@ -293,9 +285,8 @@ def main(): module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() - except Exception: - e = get_exception() - module.fail_json(msg="Unable to connect to database: {0}.".format(e)) + except Exception as e: + module.fail_json(msg="Unable to connect to database: {0}.".format(to_native(e))) try: schema_facts = get_schema_facts(cursor) @@ -304,27 +295,22 @@ def main(): elif state == 'absent': try: changed = absent(schema_facts, cursor, schema, usage_roles, create_roles) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state == 'present': try: changed = present(schema_facts, cursor, schema, usage_roles, create_roles, owner) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_schemas': schema_facts}) - except CannotDropError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_schemas': schema_facts}) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_schemas': schema_facts}) + except CannotDropError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_schemas': schema_facts}) except SystemExit: # avoid catching this on python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg=to_native(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, schema=schema, ansible_facts={'vertica_schemas': schema_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_user.py b/lib/ansible/modules/database/vertica/vertica_user.py index 27cb39428de..0d5f58b4719 100644 --- a/lib/ansible/modules/database/vertica/vertica_user.py +++ b/lib/ansible/modules/database/vertica/vertica_user.py @@ -1,20 +1,11 @@ #!/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'], @@ -127,6 +118,7 @@ EXAMPLES = """ roles=schema_name_ro state=present """ +import traceback try: import pyodbc @@ -136,7 +128,6 @@ else: pyodbc_found = True from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native @@ -361,8 +352,7 @@ def main(): module.params['login_user'], module.params['login_password'], 'true') db_conn = pyodbc.connect(dsn, autocommit=True) cursor = db_conn.cursor() - except Exception: - e = get_exception() + except Exception as e: module.fail_json(msg="Unable to connect to database: {0}.".format(e)) try: @@ -373,28 +363,23 @@ def main(): elif state == 'absent': try: changed = absent(user_facts, cursor, user, roles) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) elif state in ['present', 'locked']: try: changed = present(user_facts, cursor, user, profile, resource_pool, locked, password, expired, ldap, roles) - except pyodbc.Error: - e = get_exception() - module.fail_json(msg=str(e)) - except NotSupportedError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_users': user_facts}) - except CannotDropError: - e = get_exception() - module.fail_json(msg=str(e), ansible_facts={'vertica_users': user_facts}) + except pyodbc.Error as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + except NotSupportedError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_users': user_facts}) + except CannotDropError as e: + module.fail_json(msg=to_native(e), ansible_facts={'vertica_users': user_facts}) except SystemExit: # avoid catching this on python 2.4 raise - except Exception: - e = get_exception() - module.fail_json(msg=to_native(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=changed, user=user, ansible_facts={'vertica_users': user_facts}) diff --git a/lib/ansible/modules/network/a10/a10_server.py b/lib/ansible/modules/network/a10/a10_server.py index f1f96f968c4..c7d54c8f6d7 100644 --- a/lib/ansible/modules/network/a10/a10_server.py +++ b/lib/ansible/modules/network/a10/a10_server.py @@ -1,26 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Ansible module to manage A10 Networks slb server objects -(c) 2014, Mischa Peters , -2016, Eric Chou +# (c) 2014, Mischa Peters , +# (c) 2016, Eric Chou +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -This file is part of Ansible +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -114,13 +102,15 @@ content: ''' import json +from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure, + axapi_get_port_protocol, axapi_enabled_disabled, AXAPI_PORT_PROTOCOLS) from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import url_argument_spec -from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure -from ansible.module_utils.a10 import axapi_get_port_protocol, axapi_enabled_disabled, AXAPI_PORT_PROTOCOLS + VALID_PORT_FIELDS = ['port_num', 'protocol', 'status'] + def validate_ports(module, ports): for item in ports: for key in item: @@ -209,7 +199,7 @@ def main(): if slb_server_status: json_post['server']['status'] = axapi_enabled_disabled(slb_server_status) - slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) + axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) slb_server_data = axapi_call(module, session_url + '&method=slb.server.search', json.dumps({'name': slb_server})) slb_server_exists = not axapi_failure(slb_server_data) @@ -296,5 +286,6 @@ def main(): axapi_call(module, session_url + '&method=session.close') module.exit_json(changed=changed, content=result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/a10/a10_server_axapi3.py b/lib/ansible/modules/network/a10/a10_server_axapi3.py index 29f68735a79..c58ac9792fd 100644 --- a/lib/ansible/modules/network/a10/a10_server_axapi3.py +++ b/lib/ansible/modules/network/a10/a10_server_axapi3.py @@ -1,25 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Ansible module to manage A10 Networks slb server objects -(c) 2014, Mischa Peters , 2016, Eric Chou - -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. +# (c) 2014, Mischa Peters +# (c) 2016, Eric Chou +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -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. +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -102,13 +91,15 @@ EXAMPLES = ''' ''' import json -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import url_argument_spec from ansible.module_utils.a10 import axapi_call_v3, a10_argument_spec, axapi_authenticate_v3, axapi_failure from ansible.module_utils.a10 import AXAPI_PORT_PROTOCOLS +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import url_argument_spec + VALID_PORT_FIELDS = ['port-number', 'protocol', 'action'] + def validate_ports(module, ports): for item in ports: for key in item: @@ -251,5 +242,6 @@ def main(): axapi_call_v3(module, axapi_base_url + 'logoff/', method='POST', body='', signature=signature) module.exit_json(changed=changed, content=result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/a10/a10_service_group.py b/lib/ansible/modules/network/a10/a10_service_group.py index 001a58962cd..c4bb40f4c04 100644 --- a/lib/ansible/modules/network/a10/a10_service_group.py +++ b/lib/ansible/modules/network/a10/a10_service_group.py @@ -1,26 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Ansible module to manage A10 Networks slb service-group objects -(c) 2014, Mischa Peters , -Eric Chou +# (c) 2014, Mischa Peters , +# Eric Chou +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -This file is part of Ansible +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -124,13 +112,16 @@ content: ''' import json +from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure, + axapi_enabled_disabled) from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import url_argument_spec -from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure, axapi_enabled_disabled + VALID_SERVICE_GROUP_FIELDS = ['name', 'protocol', 'lb_method'] VALID_SERVER_FIELDS = ['server', 'port', 'status'] + def validate_servers(module, servers): for item in servers: for key in item: @@ -234,7 +225,7 @@ def main(): # first we authenticate to get a session id session_url = axapi_authenticate(module, axapi_base_url, username, password) # then we select the active-partition - slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) + axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) # then we check to see if the specified group exists slb_result = axapi_call(module, session_url + '&method=slb.service_group.search', json.dumps({'name': slb_service_group})) slb_service_group_exist = not axapi_failure(slb_result) diff --git a/lib/ansible/modules/network/a10/a10_virtual_server.py b/lib/ansible/modules/network/a10/a10_virtual_server.py index 561fb13d877..a2340059c20 100644 --- a/lib/ansible/modules/network/a10/a10_virtual_server.py +++ b/lib/ansible/modules/network/a10/a10_virtual_server.py @@ -1,26 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Ansible module to manage A10 Networks slb virtual server objects -(c) 2014, Mischa Peters , -Eric Chou +# (c) 2014, Mischa Peters , +# Eric Chou +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -This file is part of Ansible +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -113,13 +101,15 @@ content: ''' import json +from ansible.module_utils.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure, + axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS) from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import url_argument_spec -from ansible.module_utils.a10 import axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure -from ansible.module_utils.a10 import axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS + VALID_PORT_FIELDS = ['port', 'protocol', 'service_group', 'status'] + def validate_ports(module, ports): for item in ports: for key in item: @@ -194,7 +184,7 @@ def main(): axapi_base_url = 'https://%s/services/rest/V2.1/?format=json' % host session_url = axapi_authenticate(module, axapi_base_url, username, password) - slb_server_partition = axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) + axapi_call(module, session_url + '&method=system.partition.active', json.dumps({'name': partition})) slb_virtual_data = axapi_call(module, session_url + '&method=slb.virtual_server.search', json.dumps({'name': slb_virtual})) slb_virtual_exists = not axapi_failure(slb_virtual_data) @@ -287,5 +277,6 @@ def main(): axapi_call(module, session_url + '&method=session.close') module.exit_json(changed=changed, content=result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/aci/aci_rest.py b/lib/ansible/modules/network/aci/aci_rest.py index 9bd78146678..ee461b2975d 100644 --- a/lib/ansible/modules/network/aci/aci_rest.py +++ b/lib/ansible/modules/network/aci/aci_rest.py @@ -3,21 +3,11 @@ # Copyright 2017 Dag Wieers # Copyright 2017 Swetha Chunduri (@schunduri) +# 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 by Red Hat -# -# 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'], @@ -175,7 +165,6 @@ totalCount: sample: '0' ''' -import json import os # Optional, only used for XML payload @@ -288,5 +277,6 @@ def main(): # Report success module.exit_json(**aci.result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/aireos/aireos_command.py b/lib/ansible/modules/network/aireos/aireos_command.py index 9dc60c569d7..61f616b267b 100644 --- a/lib/ansible/modules/network/aireos/aireos_command.py +++ b/lib/ansible/modules/network/aireos/aireos_command.py @@ -1,20 +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 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', 'status': ['preview'], diff --git a/lib/ansible/modules/network/aireos/aireos_config.py b/lib/ansible/modules/network/aireos/aireos_config.py index 7d9ce8f42db..f57ed4c5118 100644 --- a/lib/ansible/modules/network/aireos/aireos_config.py +++ b/lib/ansible/modules/network/aireos/aireos_config.py @@ -1,20 +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 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', 'status': ['preview'], @@ -176,16 +167,11 @@ backup_path: type: string sample: /playbooks/ansible/backup/aireos_config.2016-07-16@22:28:34 """ -import re -import time - from ansible.module_utils.aireos import run_commands, get_config, load_config, sanitize from ansible.module_utils.aireos import aireos_argument_spec from ansible.module_utils.aireos import check_args as aireos_check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcli import Conditional from ansible.module_utils.netcfg import NetworkConfig, dumps -from ansible.module_utils.six import iteritems def get_running_config(module, config=None): diff --git a/lib/ansible/modules/network/aruba/aruba_command.py b/lib/ansible/modules/network/aruba/aruba_command.py index b0982e8d193..94351294625 100644 --- a/lib/ansible/modules/network/aruba/aruba_command.py +++ b/lib/ansible/modules/network/aruba/aruba_command.py @@ -1,20 +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 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', 'status': ['preview'], diff --git a/lib/ansible/modules/network/asa/asa_acl.py b/lib/ansible/modules/network/asa/asa_acl.py index c27432e9fed..483a4236672 100644 --- a/lib/ansible/modules/network/asa/asa_acl.py +++ b/lib/ansible/modules/network/asa/asa_acl.py @@ -1,20 +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'], @@ -147,7 +138,6 @@ responses: type: list sample: ['...', '...'] """ -import ansible.module_utils.asa from ansible.module_utils.network import NetworkModule from ansible.module_utils.netcfg import NetworkConfig, dumps @@ -199,12 +189,6 @@ def main(): lines = module.params['lines'] - before = module.params['before'] - after = module.params['after'] - - match = module.params['match'] - replace = module.params['replace'] - result = dict(changed=False) candidate = NetworkConfig(indent=1) diff --git a/lib/ansible/modules/network/asa/asa_command.py b/lib/ansible/modules/network/asa/asa_command.py index 0e8f79849d4..142e8a9533e 100644 --- a/lib/ansible/modules/network/asa/asa_command.py +++ b/lib/ansible/modules/network/asa/asa_command.py @@ -1,20 +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', diff --git a/lib/ansible/modules/network/asa/asa_config.py b/lib/ansible/modules/network/asa/asa_config.py index 30616210040..66982b523b1 100644 --- a/lib/ansible/modules/network/asa/asa_config.py +++ b/lib/ansible/modules/network/asa/asa_config.py @@ -1,20 +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'], @@ -231,13 +222,12 @@ responses: type: list sample: ['...', '...'] """ -import re - -import ansible.module_utils.asa +import traceback -from ansible.module_utils.basic import get_exception from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.netcfg import NetworkConfig, dumps +from ansible.module_utils._text import to_native + def get_config(module): contents = module.params['config'] @@ -339,11 +329,11 @@ def main(): try: run(module, result) - except NetworkError: - exc = get_exception() - module.fail_json(msg=str(exc), **exc.kwargs) + except NetworkError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **e.kwargs) module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/bigswitch/bcf_switch.py b/lib/ansible/modules/network/bigswitch/bcf_switch.py index bb81af48b7f..b2d7a711e5c 100755 --- a/lib/ansible/modules/network/bigswitch/bcf_switch.py +++ b/lib/ansible/modules/network/bigswitch/bcf_switch.py @@ -1,23 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Ansible module to manage Big Cloud Fabric (versions 4.1) switches # (c) 2017, Ted Elhourani -# -# 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', @@ -86,19 +74,19 @@ EXAMPLES = ''' RETURN = ''' # ''' - import os +import traceback + from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.bigswitch_utils import Rest, Response -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.bigswitch_utils import Rest +from ansible.module_utils._text import to_native def switch(module, check_mode): try: access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] - except KeyError: - e = get_exception() - module.fail_json(msg='Unable to load %s' % e.message) + except KeyError as e: + module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc()) name = module.params['name'] fabric_role = module.params['fabric_role'] @@ -166,9 +154,9 @@ def main(): try: switch(module, check_mode=module.check_mode) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/bigswitch/bigmon_chain.py b/lib/ansible/modules/network/bigswitch/bigmon_chain.py index bf3f4b6077a..8bab6fa8469 100755 --- a/lib/ansible/modules/network/bigswitch/bigmon_chain.py +++ b/lib/ansible/modules/network/bigswitch/bigmon_chain.py @@ -3,21 +3,11 @@ # Ansible module to manage Big Monitoring Fabric service chains # (c) 2016, Ted Elhourani -# -# 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,16 +62,18 @@ EXAMPLES = ''' RETURN = ''' # ''' import os +import traceback + from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.bigswitch_utils import Rest, Response -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.bigswitch_utils import Rest +from ansible.module_utils._text import to_native + def chain(module): try: access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] - except KeyError: - e = get_exception() - module.fail_json(msg='Unable to load %s' % e.message ) + except KeyError as e: + module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc()) name = module.params['name'] state = module.params['state'] @@ -136,9 +128,9 @@ def main(): try: chain(module) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/bigswitch/bigmon_policy.py b/lib/ansible/modules/network/bigswitch/bigmon_policy.py index c2fdaebaaa5..a1709be3712 100644 --- a/lib/ansible/modules/network/bigswitch/bigmon_policy.py +++ b/lib/ansible/modules/network/bigswitch/bigmon_policy.py @@ -3,21 +3,11 @@ # Ansible module to manage Big Monitoring Fabric service chains # (c) 2016, Ted Elhourani -# -# 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'], @@ -97,18 +87,20 @@ EXAMPLES = ''' RETURN = ''' # ''' -import os import datetime +import os +import traceback + from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.bigswitch_utils import Rest, Response -from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.bigswitch_utils import Rest +from ansible.module_utils._text import to_native + def policy(module): try: access_token = module.params['access_token'] or os.environ['BIGSWITCH_ACCESS_TOKEN'] - except KeyError: - e = get_exception() - module.fail_json(msg='Unable to load %s' % e.message) + except KeyError as e: + module.fail_json(msg='Unable to load %s' % e.message, exception=traceback.format_exc()) name = module.params['name'] policy_description = module.params['policy_description'] @@ -187,9 +179,8 @@ def main(): try: policy(module) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/citrix/netscaler.py b/lib/ansible/modules/network/citrix/netscaler.py index 5cf3c96a302..3f00ff85743 100644 --- a/lib/ansible/modules/network/citrix/netscaler.py +++ b/lib/ansible/modules/network/citrix/netscaler.py @@ -1,25 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -Ansible module to manage Citrix NetScaler entities -(c) 2013, Nandor Sivok +# (c) 2013, Nandor Sivok +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -This file is part of Ansible +from __future__ import absolute_import, division, print_function +__metaclass__ = type -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'], @@ -116,9 +103,14 @@ EXAMPLES = ''' import base64 +import json import socket +import traceback +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible.module_utils._text import to_native +from ansible.module_utils.urls import fetch_url class netscaler(object): @@ -193,9 +185,8 @@ def main(): rc = 0 try: rc, result = core(module) - except Exception: - e = get_exception() - module.fail_json(msg=str(e)) + except Exception as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) if rc != 0: module.fail_json(rc=rc, msg=result) @@ -204,10 +195,5 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * -from ansible.module_utils.pycompat24 import get_exception - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/cumulus/_cl_bond.py b/lib/ansible/modules/network/cumulus/_cl_bond.py index c7fc5c987d0..8a48d0368c7 100644 --- a/lib/ansible/modules/network/cumulus/_cl_bond.py +++ b/lib/ansible/modules/network/cumulus/_cl_bond.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], diff --git a/lib/ansible/modules/network/cumulus/_cl_bridge.py b/lib/ansible/modules/network/cumulus/_cl_bridge.py index 066adf1af99..e8ac0b59baa 100644 --- a/lib/ansible/modules/network/cumulus/_cl_bridge.py +++ b/lib/ansible/modules/network/cumulus/_cl_bridge.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], diff --git a/lib/ansible/modules/network/cumulus/_cl_img_install.py b/lib/ansible/modules/network/cumulus/_cl_img_install.py index 6ac582e97fe..1f6f0170712 100644 --- a/lib/ansible/modules/network/cumulus/_cl_img_install.py +++ b/lib/ansible/modules/network/cumulus/_cl_img_install.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], @@ -111,12 +104,9 @@ msg: ''' import re -from urlparse import urlparse -# import module snippets from ansible.module_utils.basic import AnsibleModule, platform -# incompatible with ansible 1.4.4 - ubuntu 12.04 version -# from ansible.module_utils.urls import * +from ansible.module_utils.six.moves.urllib import parse as urlparse def check_url(module, url): diff --git a/lib/ansible/modules/network/cumulus/_cl_interface.py b/lib/ansible/modules/network/cumulus/_cl_interface.py index 02a033c9722..85d925ffb4c 100644 --- a/lib/ansible/modules/network/cumulus/_cl_interface.py +++ b/lib/ansible/modules/network/cumulus/_cl_interface.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], @@ -210,7 +203,6 @@ msg: ''' import os -import platform import re import tempfile diff --git a/lib/ansible/modules/network/cumulus/_cl_interface_policy.py b/lib/ansible/modules/network/cumulus/_cl_interface_policy.py index 3106e3393f0..191f5683f38 100644 --- a/lib/ansible/modules/network/cumulus/_cl_interface_policy.py +++ b/lib/ansible/modules/network/cumulus/_cl_interface_policy.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], @@ -71,6 +64,10 @@ msg: type: string sample: "interface bond0 config updated" ''' +import os +import re + +from ansible.module_utils.basic import AnsibleModule # get list of interface files that are currently "configured". @@ -144,11 +141,5 @@ def main(): module.exit_json(changed=module.changed, msg=module.msg) -# import module snippets -from ansible.module_utils.basic import * -# from ansible.module_utils.urls import * -import os -import shutil - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/cumulus/_cl_license.py b/lib/ansible/modules/network/cumulus/_cl_license.py index 48956b34fc6..77f2d502c68 100644 --- a/lib/ansible/modules/network/cumulus/_cl_license.py +++ b/lib/ansible/modules/network/cumulus/_cl_license.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], @@ -107,11 +100,12 @@ msg: sample: "interface bond0 config updated" ''' -# import module snippets from ansible.module_utils.basic import AnsibleModule + CL_LICENSE_PATH='/usr/cumulus/bin/cl-license' + def install_license(module): # license is not installed, install it _url = module.params.get('src') diff --git a/lib/ansible/modules/network/cumulus/_cl_ports.py b/lib/ansible/modules/network/cumulus/_cl_ports.py index 56b5b949f10..3fb4fec80e5 100644 --- a/lib/ansible/modules/network/cumulus/_cl_ports.py +++ b/lib/ansible/modules/network/cumulus/_cl_ports.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Cumulus Networks -# -# 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': ['deprecated'], @@ -84,6 +77,14 @@ msg: type: string sample: "interface bond0 config updated" ''' +import os +import re +import tempfile +import shutil + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + PORTS_CONF = '/etc/cumulus/ports.conf' @@ -95,9 +96,8 @@ def hash_existing_ports_conf(module): try: existing_ports_conf = open(PORTS_CONF).readlines() - except IOError: - error_msg = get_exception() - _msg = "Failed to open %s: %s" % (PORTS_CONF, error_msg) + except IOError as e: + _msg = "Failed to open %s: %s" % (PORTS_CONF, to_native(e)) module.fail_json(msg=_msg) return # for testing only should return on module.fail_json @@ -155,9 +155,8 @@ def make_copy_of_orig_ports_conf(module): try: shutil.copyfile(PORTS_CONF, PORTS_CONF + '.orig') - except IOError: - error_msg = get_exception() - _msg = "Failed to save the original %s: %s" % (PORTS_CONF, error_msg) + except IOError as e: + _msg = "Failed to save the original %s: %s" % (PORTS_CONF, to_native(e)) module.fail_json(msg=_msg) return # for testing only @@ -178,10 +177,8 @@ def write_to_ports_conf(module): temp.write(_str) temp.seek(0) shutil.copyfile(temp.name, PORTS_CONF) - except IOError: - error_msg = get_exception() - module.fail_json( - msg="Failed to write to %s: %s" % (PORTS_CONF, error_msg)) + except IOError as e: + module.fail_json(msg="Failed to write to %s: %s" % (PORTS_CONF, to_native(e))) finally: temp.close() @@ -213,12 +210,5 @@ def main(): module.exit_json(changed=_changed, msg=_msg) -# import module snippets -from ansible.module_utils.basic import * -# from ansible.module_utils.urls import * -import os -import tempfile -import shutil - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/cumulus/nclu.py b/lib/ansible/modules/network/cumulus/nclu.py index 9ae6b9f4574..8261cc02cf6 100644 --- a/lib/ansible/modules/network/cumulus/nclu.py +++ b/lib/ansible/modules/network/cumulus/nclu.py @@ -2,18 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016-2017, Cumulus Networks -# -# 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'], @@ -101,6 +94,8 @@ msg: sample: "interface bond0 config updated" ''' +from ansible.module_utils.basic import AnsibleModule + def command_helper(module, command, errmsg=None): """Run a command, catch any nclu errors""" @@ -118,7 +113,7 @@ def check_pending(module): color1 = '\x1b[94m' if delimeter1 in pending: pending = pending.split(delimeter1)[0] - pending = pending.replace('\x1b[94m', '') + pending = pending.replace(color1, '') return pending.strip() @@ -193,7 +188,6 @@ def main(testing=False): elif testing: return {"changed": _changed, "msg": output} -# import module snippets -from ansible.module_utils.basic import AnsibleModule + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/dellos10/dellos10_command.py b/lib/ansible/modules/network/dellos10/dellos10_command.py index 900a8ac0017..c927c8a239a 100644 --- a/lib/ansible/modules/network/dellos10/dellos10_command.py +++ b/lib/ansible/modules/network/dellos10/dellos10_command.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2017 Dell 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'], @@ -142,9 +130,9 @@ warnings: """ import time +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.dellos10 import run_commands from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args -from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network_common import ComplexList from ansible.module_utils.netcli import Conditional from ansible.module_utils.six import string_types diff --git a/lib/ansible/modules/network/dellos10/dellos10_config.py b/lib/ansible/modules/network/dellos10/dellos10_config.py index 744c8619e5e..ed694435e85 100644 --- a/lib/ansible/modules/network/dellos10/dellos10_config.py +++ b/lib/ansible/modules/network/dellos10/dellos10_config.py @@ -1,24 +1,13 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2017 Dell 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'], @@ -196,11 +185,11 @@ saved: """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.dellos10 import get_config, get_sublevel_config from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args from ansible.module_utils.dellos10 import load_config, run_commands from ansible.module_utils.dellos10 import WARNING_PROMPTS_RE +from ansible.module_utils.netcfg import NetworkConfig, dumps def get_candidate(module): @@ -294,5 +283,6 @@ def main(): module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/dellos10/dellos10_facts.py b/lib/ansible/modules/network/dellos10/dellos10_facts.py index b1910ed7a30..8baf10a492c 100644 --- a/lib/ansible/modules/network/dellos10/dellos10_facts.py +++ b/lib/ansible/modules/network/dellos10/dellos10_facts.py @@ -1,24 +1,13 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2017 Dell 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'], 'supported_by': 'community'} @@ -143,7 +132,6 @@ from ansible.module_utils.dellos10 import run_commands from ansible.module_utils.dellos10 import dellos10_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems -from ansible.module_utils.six.moves import zip class FactsBase(object): @@ -239,8 +227,8 @@ class Hardware(FactsBase): data = self.responses[1] match = self.parse_memory(data) if match: - self.facts['memtotal_mb'] = int(match[0]) / 1024 - self.facts['memfree_mb'] = int(match[2]) / 1024 + self.facts['memtotal_mb'] = int(match[0]) // 1024 + self.facts['memfree_mb'] = int(match[2]) // 1024 def parse_cpu_arch(self, data): cpu_arch = data.find('./data/system-sw-state/sw-version/cpu-arch') diff --git a/lib/ansible/modules/network/dellos6/dellos6_command.py b/lib/ansible/modules/network/dellos6/dellos6_command.py index 14add0cc1c8..e291d61e9c8 100644 --- a/lib/ansible/modules/network/dellos6/dellos6_command.py +++ b/lib/ansible/modules/network/dellos6/dellos6_command.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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'], diff --git a/lib/ansible/modules/network/dellos6/dellos6_config.py b/lib/ansible/modules/network/dellos6/dellos6_config.py index 262ae023dd4..a1564e4b3f4 100644 --- a/lib/ansible/modules/network/dellos6/dellos6_config.py +++ b/lib/ansible/modules/network/dellos6/dellos6_config.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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'], @@ -195,11 +183,11 @@ saved: """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.dellos6 import get_config, get_sublevel_config, Dellos6NetworkConfig from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args from ansible.module_utils.dellos6 import load_config, run_commands from ansible.module_utils.dellos6 import WARNING_PROMPTS_RE +from ansible.module_utils.netcfg import dumps def get_candidate(module): @@ -288,5 +276,6 @@ def main(): result['updates'] = commands module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/dellos6/dellos6_facts.py b/lib/ansible/modules/network/dellos6/dellos6_facts.py index d92d1b0e38d..d6b4daf680c 100644 --- a/lib/ansible/modules/network/dellos6/dellos6_facts.py +++ b/lib/ansible/modules/network/dellos6/dellos6_facts.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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'], @@ -122,13 +110,11 @@ ansible_net_neighbors: """ import re -import itertools +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.dellos6 import run_commands from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args -from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems -from ansible.module_utils.six.moves import zip class FactsBase(object): @@ -201,8 +187,8 @@ class Hardware(FactsBase): data = self.responses[0] match = re.findall('\s(\d+)\s', data) if match: - self.facts['memtotal_mb'] = int(match[0]) / 1024 - self.facts['memfree_mb'] = int(match[1]) / 1024 + self.facts['memtotal_mb'] = int(match[0]) // 1024 + self.facts['memfree_mb'] = int(match[1]) // 1024 class Config(FactsBase): @@ -348,7 +334,7 @@ class Interfaces(FactsBase): match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) if match: strval = match.group(3) - return match.group(3) + return strval if flag == 1: return "null" @@ -361,7 +347,7 @@ class Interfaces(FactsBase): match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) if match: strval = match.group(2) - return match.group(2) + return strval if flag == 1: return "null" @@ -471,5 +457,6 @@ def main(): module.exit_json(ansible_facts=ansible_facts, warnings=warnings) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/dellos9/dellos9_command.py b/lib/ansible/modules/network/dellos9/dellos9_command.py index d453767d88d..33af9340a29 100644 --- a/lib/ansible/modules/network/dellos9/dellos9_command.py +++ b/lib/ansible/modules/network/dellos9/dellos9_command.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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 = {'status': ['preview'], 'supported_by': 'community', diff --git a/lib/ansible/modules/network/dellos9/dellos9_config.py b/lib/ansible/modules/network/dellos9/dellos9_config.py index 6820d7c7fb3..cfc9bb34105 100644 --- a/lib/ansible/modules/network/dellos9/dellos9_config.py +++ b/lib/ansible/modules/network/dellos9/dellos9_config.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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'], @@ -202,11 +190,11 @@ saved: """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.dellos9 import get_config, get_sublevel_config from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args from ansible.module_utils.dellos9 import load_config, run_commands from ansible.module_utils.dellos9 import WARNING_PROMPTS_RE +from ansible.module_utils.netcfg import NetworkConfig, dumps def get_candidate(module): @@ -301,5 +289,6 @@ def main(): module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/dellos9/dellos9_facts.py b/lib/ansible/modules/network/dellos9/dellos9_facts.py index fc49516407b..5de3754c8a3 100644 --- a/lib/ansible/modules/network/dellos9/dellos9_facts.py +++ b/lib/ansible/modules/network/dellos9/dellos9_facts.py @@ -1,24 +1,12 @@ #!/usr/bin/python # # (c) 2015 Peter Sprygada, -# # Copyright (c) 2016 Dell 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'], @@ -142,11 +130,10 @@ ansible_net_neighbors: import re import itertools +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.dellos9 import run_commands from ansible.module_utils.dellos9 import dellos9_argument_spec, check_args -from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems -from ansible.module_utils.six.moves import zip class FactsBase(object): @@ -230,8 +217,8 @@ class Hardware(FactsBase): data = self.responses[1] match = re.findall('\s(\d+)\s', data) if match: - self.facts['memtotal_mb'] = int(match[0]) / 1024 - self.facts['memfree_mb'] = int(match[2]) / 1024 + self.facts['memtotal_mb'] = int(match[0]) // 1024 + self.facts['memfree_mb'] = int(match[2]) // 1024 def parse_filesystems(self, data): return re.findall(r'\s(\S+):$', data, re.M) diff --git a/lib/ansible/modules/network/fortios/fortios_config.py b/lib/ansible/modules/network/fortios/fortios_config.py index 248566145cb..cc318ef18b3 100644 --- a/lib/ansible/modules/network/fortios/fortios_config.py +++ b/lib/ansible/modules/network/fortios/fortios_config.py @@ -2,22 +2,11 @@ # # Ansible module to manage configuration on fortios devices # (c) 2016, Benjamin Jolivot -# -# 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,15 +72,10 @@ change_string: type: string """ - - +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if from ansible.module_utils.fortios import backup -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception - - #check for pyFG lib try: from pyFG import FortiOS, FortiConfig @@ -101,11 +85,13 @@ try: except: HAS_PYFG=False + # some blocks don't support update, so remove them NOT_UPDATABLE_CONFIG_OBJECTS=[ "vpn certificate local", ] + def main(): argument_spec = dict( src = dict(type='str', default=None), @@ -183,18 +169,16 @@ def main(): if module.check_mode is False and change_string != "": try: f.commit(change_string) - except CommandExecutionException: - e = get_exception() + except CommandExecutionException as e: module.fail_json(msg="Unable to execute command, check your args, the error was {0}".format(e.message)) - except FailedCommit: - e = get_exception() + except FailedCommit as e: module.fail_json(msg="Unable to commit, check your args, the error was {0}".format(e.message)) - except ForcedCommit: - e = get_exception() + except ForcedCommit as e: module.fail_json(msg="Failed to force commit, check your args, the error was {0}".format(e.message)) module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/fortios/fortios_ipv4_policy.py b/lib/ansible/modules/network/fortios/fortios_ipv4_policy.py index 99b3f15f231..4b646c35d92 100644 --- a/lib/ansible/modules/network/fortios/fortios_ipv4_policy.py +++ b/lib/ansible/modules/network/fortios/fortios_ipv4_policy.py @@ -2,22 +2,11 @@ # # Ansible module to manage IPv4 policy objects in fortigate devices # (c) 2017, Benjamin Jolivot -# -# 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'], @@ -181,12 +170,10 @@ msg_error_list: type: string """ +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.fortios import fortios_argument_spec, fortios_required_if from ansible.module_utils.fortios import backup, AnsibleFortios -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.pycompat24 import get_exception - def main(): argument_spec = dict( @@ -214,7 +201,7 @@ def main(): logtraffic_start = dict(type='bool', default=False), ) - #merge global required_if & argument_spec from module_utils/fortios.py + # merge global required_if & argument_spec from module_utils/fortios.py argument_spec.update(fortios_argument_spec) ipv4_policy_required_if = [ @@ -227,40 +214,40 @@ def main(): required_if=fortios_required_if + ipv4_policy_required_if , ) - #init forti object + # init forti object fortigate = AnsibleFortios(module) - #Security policies root path + # Security policies root path config_path = 'firewall policy' - #test params - #NAT related + # test params + # NAT related if not module.params['nat']: if module.params['poolname']: module.fail_json(msg='Poolname param requires NAT to be true.') if module.params['fixedport']: module.fail_json(msg='Fixedport param requires NAT to be true.') - #log options + # log options if module.params['logtraffic_start']: if not module.params['logtraffic'] == 'all': module.fail_json(msg='Logtraffic_start param requires logtraffic to be set to "all".') - #id must be str(int) for pyFG to work + # id must be str(int) for pyFG to work policy_id = str(module.params['id']) - #load config + # load config fortigate.load_config(config_path) - #Absent State + # Absent State if module.params['state'] == 'absent': fortigate.candidate_config[config_path].del_block(policy_id) - #Present state + # Present state elif module.params['state'] == 'present': new_policy = fortigate.get_empty_configuration_block(policy_id, 'edit') - #src / dest / service / interfaces + # src / dest / service / interfaces new_policy.set_param('srcintf', '"%s"' % (module.params['src_intf'])) new_policy.set_param('dstintf', '"%s"' % (module.params['dst_intf'])) @@ -280,7 +267,7 @@ def main(): # action new_policy.set_param('action', '%s' % (module.params['policy_action'])) - #logging + # logging new_policy.set_param('logtraffic', '%s' % (module.params['logtraffic'])) if module.params['logtraffic'] == 'all': if module.params['logtraffic_start']: @@ -291,7 +278,7 @@ def main(): # Schedule new_policy.set_param('schedule', '%s' % (module.params['schedule'])) - #NAT + # NAT if module.params['nat']: new_policy.set_param('nat', 'enable') if module.params['fixedport']: @@ -300,7 +287,7 @@ def main(): new_policy.set_param('ippool', 'enable') new_policy.set_param('poolname', '"%s"' % (module.params['poolname'])) - #security profiles: + # security profiles: if module.params['av_profile'] is not None: new_policy.set_param('av-profile', '"%s"' % (module.params['av_profile'])) if module.params['webfilter_profile'] is not None: @@ -314,12 +301,12 @@ def main(): if module.params['comment'] is not None: new_policy.set_param('comment', '"%s"' % (module.params['comment'])) - #add the new policy to the device + # add the new policy to the device fortigate.add_block(policy_id, new_policy) - #Apply changes + # Apply changes fortigate.apply_changes() + if __name__ == '__main__': main() - diff --git a/lib/ansible/modules/network/illumos/dladm_etherstub.py b/lib/ansible/modules/network/illumos/dladm_etherstub.py index e81593c7cca..a4d00a77dfb 100644 --- a/lib/ansible/modules/network/illumos/dladm_etherstub.py +++ b/lib/ansible/modules/network/illumos/dladm_etherstub.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Adam Å tevko -# -# 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 +70,7 @@ temporary: type: boolean sample: "True" ''' +from ansible.module_utils.basic import AnsibleModule class Etherstub(object): @@ -176,7 +166,6 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/illumos/dladm_iptun.py b/lib/ansible/modules/network/illumos/dladm_iptun.py index 06a746baeee..8c0a4eede23 100644 --- a/lib/ansible/modules/network/illumos/dladm_iptun.py +++ b/lib/ansible/modules/network/illumos/dladm_iptun.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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/network/illumos/dladm_linkprop.py b/lib/ansible/modules/network/illumos/dladm_linkprop.py index 5bd3a159ec3..206b385577d 100644 --- a/lib/ansible/modules/network/illumos/dladm_linkprop.py +++ b/lib/ansible/modules/network/illumos/dladm_linkprop.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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/network/illumos/dladm_vlan.py b/lib/ansible/modules/network/illumos/dladm_vlan.py index e9a5db1ec2a..0acd8b6e4a0 100644 --- a/lib/ansible/modules/network/illumos/dladm_vlan.py +++ b/lib/ansible/modules/network/illumos/dladm_vlan.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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/network/illumos/dladm_vnic.py b/lib/ansible/modules/network/illumos/dladm_vnic.py index 70860e10146..626e20cd892 100644 --- a/lib/ansible/modules/network/illumos/dladm_vnic.py +++ b/lib/ansible/modules/network/illumos/dladm_vnic.py @@ -3,21 +3,11 @@ # (c) 2015, Adam Å tevko # -# 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,6 +115,8 @@ vlan: import re +from ansible.module_utils.basic import AnsibleModule + class VNIC(object): @@ -269,7 +261,6 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/illumos/flowadm.py b/lib/ansible/modules/network/illumos/flowadm.py index 8777bff63d7..0a60685aa47 100644 --- a/lib/ansible/modules/network/illumos/flowadm.py +++ b/lib/ansible/modules/network/illumos/flowadm.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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'], @@ -181,6 +170,9 @@ dsfield: import socket +from ansible.module_utils.basic import AnsibleModule + + SUPPORTED_TRANSPORTS = ['tcp', 'udp', 'sctp', 'icmp', 'icmpv6'] SUPPORTED_PRIORITIES = ['low', 'medium', 'high'] @@ -518,7 +510,5 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/illumos/ipadm_addr.py b/lib/ansible/modules/network/illumos/ipadm_addr.py index 0ed634535b1..01d25620b89 100644 --- a/lib/ansible/modules/network/illumos/ipadm_addr.py +++ b/lib/ansible/modules/network/illumos/ipadm_addr.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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,8 +106,10 @@ wait: ''' import socket + from ansible.module_utils.basic import AnsibleModule + SUPPORTED_TYPES = ['static', 'addrconf', 'dhcp'] diff --git a/lib/ansible/modules/network/illumos/ipadm_addrprop.py b/lib/ansible/modules/network/illumos/ipadm_addrprop.py index 753cd4c813a..028955d8da2 100644 --- a/lib/ansible/modules/network/illumos/ipadm_addrprop.py +++ b/lib/ansible/modules/network/illumos/ipadm_addrprop.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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/network/illumos/ipadm_if.py b/lib/ansible/modules/network/illumos/ipadm_if.py index d780460d09e..2dc7eeedd86 100644 --- a/lib/ansible/modules/network/illumos/ipadm_if.py +++ b/lib/ansible/modules/network/illumos/ipadm_if.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Adam Å tevko -# -# 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'], @@ -82,6 +71,7 @@ temporary: type: boolean sample: "True" ''' +from ansible.module_utils.basic import AnsibleModule class IPInterface(object): @@ -227,7 +217,6 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/illumos/ipadm_ifprop.py b/lib/ansible/modules/network/illumos/ipadm_ifprop.py index c5e24c4f86d..758f4aa5fc1 100644 --- a/lib/ansible/modules/network/illumos/ipadm_ifprop.py +++ b/lib/ansible/modules/network/illumos/ipadm_ifprop.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2016, Adam Å tevko -# -# 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,6 +98,7 @@ value: from ansible.module_utils.basic import AnsibleModule + SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6'] diff --git a/lib/ansible/modules/network/illumos/ipadm_prop.py b/lib/ansible/modules/network/illumos/ipadm_prop.py index cd2fa692f67..efa9a808437 100644 --- a/lib/ansible/modules/network/illumos/ipadm_prop.py +++ b/lib/ansible/modules/network/illumos/ipadm_prop.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2015, Adam Å tevko -# -# 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,6 +85,9 @@ value: sample: "'1024' or 'never'" ''' +from ansible.module_utils.basic import AnsibleModule + + SUPPORTED_PROTOCOLS = ['ipv4', 'ipv6', 'icmp', 'tcp', 'udp', 'sctp'] @@ -265,7 +257,5 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/interface/net_interface.py b/lib/ansible/modules/network/interface/net_interface.py index f9d4f6f425b..fab4704ebf2 100644 --- a/lib/ansible/modules/network/interface/net_interface.py +++ b/lib/ansible/modules/network/interface/net_interface.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/interface/net_linkagg.py b/lib/ansible/modules/network/interface/net_linkagg.py index 83210857f62..52cc545cf68 100644 --- a/lib/ansible/modules/network/interface/net_linkagg.py +++ b/lib/ansible/modules/network/interface/net_linkagg.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/interface/net_lldp_interface.py b/lib/ansible/modules/network/interface/net_lldp_interface.py index d3106915366..5f27a8f68d4 100644 --- a/lib/ansible/modules/network/interface/net_lldp_interface.py +++ b/lib/ansible/modules/network/interface/net_lldp_interface.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/iosxr/iosxr_banner.py b/lib/ansible/modules/network/iosxr/iosxr_banner.py index 1740c51e2c4..98c19b531b2 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_banner.py +++ b/lib/ansible/modules/network/iosxr/iosxr_banner.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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,5 +169,6 @@ def main(): module.exit_json(**result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/iosxr/iosxr_command.py b/lib/ansible/modules/network/iosxr/iosxr_command.py index 70bc429cf25..518dc87ca9b 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_command.py +++ b/lib/ansible/modules/network/iosxr/iosxr_command.py @@ -1,20 +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'], @@ -132,19 +123,20 @@ failed_conditions: import time from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.iosxr import run_commands -from ansible.module_utils.network_common import ComplexList +from ansible.module_utils.iosxr import run_commands, iosxr_argument_spec, check_args from ansible.module_utils.netcli import Conditional +from ansible.module_utils.network_common import ComplexList from ansible.module_utils.six import string_types -from ansible.module_utils.iosxr import iosxr_argument_spec, check_args from ansible.module_utils._text import to_native + def to_lines(stdout): for item in stdout: if isinstance(item, string_types): item = to_native(item, errors='surrogate_or_strict').split('\n') yield item + def parse_commands(module, warnings): command = ComplexList(dict( command=dict(key=True), diff --git a/lib/ansible/modules/network/iosxr/iosxr_config.py b/lib/ansible/modules/network/iosxr/iosxr_config.py index 6de819c5d61..d105dc2eec5 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_config.py +++ b/lib/ansible/modules/network/iosxr/iosxr_config.py @@ -1,20 +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'], @@ -187,10 +178,11 @@ backup_path: sample: /playbooks/ansible/backup/iosxr01.2016-07-16@22:28:34 """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.iosxr import load_config,get_config from ansible.module_utils.iosxr import iosxr_argument_spec from ansible.module_utils.iosxr import check_args as iosxr_check_args +from ansible.module_utils.netcfg import NetworkConfig, dumps + DEFAULT_COMMIT_COMMENT = 'configured by iosxr_config' @@ -205,12 +197,14 @@ def check_args(module, warnings): 'match=none instead. This argument will be ' 'removed in the future') + def get_running_config(module): contents = module.params['config'] if not contents: contents = get_config(module) return NetworkConfig(indent=1, contents=contents) + def get_candidate(module): candidate = NetworkConfig(indent=1) if module.params['src']: diff --git a/lib/ansible/modules/network/iosxr/iosxr_facts.py b/lib/ansible/modules/network/iosxr/iosxr_facts.py index 19c4c521d7c..0e25d283fe5 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_facts.py +++ b/lib/ansible/modules/network/iosxr/iosxr_facts.py @@ -1,20 +1,12 @@ #!/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'], 'supported_by': 'core'} @@ -122,11 +114,10 @@ ansible_net_neighbors: """ import re -from ansible.module_utils.iosxr import run_commands from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.iosxr import iosxr_argument_spec, check_args, run_commands from ansible.module_utils.six import iteritems from ansible.module_utils.six.moves import zip -from ansible.module_utils.iosxr import iosxr_argument_spec, check_args class FactsBase(object): diff --git a/lib/ansible/modules/network/iosxr/iosxr_logging.py b/lib/ansible/modules/network/iosxr/iosxr_logging.py index 54e36089286..3e5bfc41126 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_logging.py +++ b/lib/ansible/modules/network/iosxr/iosxr_logging.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/iosxr/iosxr_system.py b/lib/ansible/modules/network/iosxr/iosxr_system.py index 30c469f637d..0e0aaad0c25 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_system.py +++ b/lib/ansible/modules/network/iosxr/iosxr_system.py @@ -1,20 +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 . -# +# 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/network/iosxr/iosxr_user.py b/lib/ansible/modules/network/iosxr/iosxr_user.py index f109f7a76aa..3cb71f1a6c0 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_user.py +++ b/lib/ansible/modules/network/iosxr/iosxr_user.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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'], @@ -122,13 +111,10 @@ commands: - username admin secret admin """ -import re - from functools import partial from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.iosxr import get_config, load_config -from ansible.module_utils.six import iteritems from ansible.module_utils.iosxr import iosxr_argument_spec, check_args diff --git a/lib/ansible/modules/network/layer2/net_l2_interface.py b/lib/ansible/modules/network/layer2/net_l2_interface.py index 5f34280152c..c3d50019305 100644 --- a/lib/ansible/modules/network/layer2/net_l2_interface.py +++ b/lib/ansible/modules/network/layer2/net_l2_interface.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/layer2/net_lldp_interface.py b/lib/ansible/modules/network/layer2/net_lldp_interface.py index 004f927835a..7124a538b91 100644 --- a/lib/ansible/modules/network/layer2/net_lldp_interface.py +++ b/lib/ansible/modules/network/layer2/net_lldp_interface.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/layer2/net_vlan.py b/lib/ansible/modules/network/layer2/net_vlan.py index 95f1dc94a9c..fdd64b0c9d0 100644 --- a/lib/ansible/modules/network/layer2/net_vlan.py +++ b/lib/ansible/modules/network/layer2/net_vlan.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/layer3/net_l3_interface.py b/lib/ansible/modules/network/layer3/net_l3_interface.py index 689f9893c67..976a316bac1 100644 --- a/lib/ansible/modules/network/layer3/net_l3_interface.py +++ b/lib/ansible/modules/network/layer3/net_l3_interface.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/layer3/net_vrf.py b/lib/ansible/modules/network/layer3/net_vrf.py index b8bf472fca7..1927b15f9e0 100644 --- a/lib/ansible/modules/network/layer3/net_vrf.py +++ b/lib/ansible/modules/network/layer3/net_vrf.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/netconf/netconf_config.py b/lib/ansible/modules/network/netconf/netconf_config.py index ac10600acce..de6fac60b0f 100644 --- a/lib/ansible/modules/network/netconf/netconf_config.py +++ b/lib/ansible/modules/network/netconf/netconf_config.py @@ -1,21 +1,11 @@ #!/usr/bin/python # (c) 2016, Leandro Lisboa Penz -# -# 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'], @@ -157,15 +147,17 @@ server_capabilities: ''' +import traceback import xml.dom.minidom + try: import ncclient.manager HAS_NCCLIENT = True except ImportError: HAS_NCCLIENT = False - -import logging +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native def netconf_edit_config(m, xml, commit, retkwargs, datastore): @@ -225,11 +217,8 @@ def main(): try: xml.dom.minidom.parseString(config_xml) - except: - e = get_exception() - module.fail_json( - msg='error parsing XML: ' + str(e) - ) + except Exception as e: + module.fail_json(msg='error parsing XML: %s' % to_native(e), exception=traceback.format_exc()) nckwargs = dict( host=module.params['host'], @@ -247,11 +236,8 @@ def main(): module.fail_json( msg='authentication failed while connecting to device' ) - except: - e = get_exception() - module.fail_json( - msg='error connecting to the device: ' + str(e) - ) + except Exception as e: + module.fail_json(msg='error connecting to the device: %s' % to_native(e), exception=traceback.format_exc()) retkwargs = dict() retkwargs['server_capabilities'] = list(m.server_capabilities) @@ -304,18 +290,13 @@ def main(): ) if changed and module.params['save']: m.copy_config(source="running", target="startup") - except: - e = get_exception() - module.fail_json( - msg='error editing configuration: ' + str(e) - ) + except Exception as e: + module.fail_json(msg='error editing configuration: %s' % to_native(e), exception=traceback.format_exc()) finally: m.close_session() module.exit_json(changed=changed, **retkwargs) -# import module snippets -from ansible.module_utils.basic import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/netscaler/netscaler_cs_action.py b/lib/ansible/modules/network/netscaler/netscaler_cs_action.py index f02ff4c2391..80560c9d2d5 100644 --- a/lib/ansible/modules/network/netscaler/netscaler_cs_action.py +++ b/lib/ansible/modules/network/netscaler/netscaler_cs_action.py @@ -2,22 +2,10 @@ # -*- coding: utf-8 -*- # Copyright (c) 2017 Citrix Systems -# -# 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'], @@ -105,9 +93,16 @@ diff: sample: "{ 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' }" ''' -from ansible.module_utils.basic import AnsibleModule import json +try: + from nssrc.com.citrix.netscaler.nitro.resource.config.cs.csaction import csaction + from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception + PYTHON_SDK_IMPORTED = True +except ImportError as e: + PYTHON_SDK_IMPORTED = False + +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.netscaler import ( ConfigProxy, get_nitro_client, @@ -117,13 +112,6 @@ from ansible.module_utils.netscaler import ( get_immutables_intersection ) -try: - from nssrc.com.citrix.netscaler.nitro.resource.config.cs.csaction import csaction - from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception - PYTHON_SDK_IMPORTED = True -except ImportError as e: - PYTHON_SDK_IMPORTED = False - def action_exists(client, module): if csaction.count_filtered(client, 'name:%s' % module.params['name']) > 0: diff --git a/lib/ansible/modules/network/netscaler/netscaler_save_config.py b/lib/ansible/modules/network/netscaler/netscaler_save_config.py index 128afc67e0b..d6b758cbb11 100644 --- a/lib/ansible/modules/network/netscaler/netscaler_save_config.py +++ b/lib/ansible/modules/network/netscaler/netscaler_save_config.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # Copyright (c) 2017 Citrix Systems -# -# 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'], @@ -124,15 +113,15 @@ msg: import copy -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netscaler import get_nitro_client, log, loglines, netscaler_common_arguments - try: from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception PYTHON_SDK_IMPORTED = True except ImportError as e: PYTHON_SDK_IMPORTED = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.netscaler import get_nitro_client, log, loglines, netscaler_common_arguments + def main(): diff --git a/lib/ansible/modules/network/netscaler/netscaler_server.py b/lib/ansible/modules/network/netscaler/netscaler_server.py index 4af68f9b251..e2dc4a81d13 100644 --- a/lib/ansible/modules/network/netscaler/netscaler_server.py +++ b/lib/ansible/modules/network/netscaler/netscaler_server.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # Copyright (c) 2017 Citrix Systems -# -# 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'], @@ -147,10 +136,6 @@ diff: sample: { 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' } ''' -from ansible.module_utils.basic import AnsibleModule - -from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection - try: from nssrc.com.citrix.netscaler.nitro.resource.config.basic.server import server from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception @@ -158,6 +143,9 @@ try: except ImportError as e: PYTHON_SDK_IMPORTED = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.netscaler import ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection + def server_exists(client, module): log('Checking if server exists') diff --git a/lib/ansible/modules/network/netscaler/netscaler_service.py b/lib/ansible/modules/network/netscaler/netscaler_service.py index dbcb49dad4d..b084953af7a 100644 --- a/lib/ansible/modules/network/netscaler/netscaler_service.py +++ b/lib/ansible/modules/network/netscaler/netscaler_service.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # Copyright (c) 2017 Citrix Systems -# -# 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'], @@ -413,8 +402,6 @@ diff: sample: "{ 'clttimeout': 'difference. ours: (float) 10.0 other: (float) 20.0' }" ''' -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netscaler import (ConfigProxy, get_nitro_client, netscaler_common_arguments, log, loglines, get_immutables_intersection) import copy try: @@ -426,6 +413,10 @@ try: except ImportError as e: PYTHON_SDK_IMPORTED = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.netscaler import (ConfigProxy, get_nitro_client, netscaler_common_arguments, + log, loglines, get_immutables_intersection) + def service_exists(client, module): if service.count_filtered(client, 'name:%s' % module.params['name']) > 0: diff --git a/lib/ansible/modules/network/nuage/nuage_vspk.py b/lib/ansible/modules/network/nuage/nuage_vspk.py index efe3e219110..b1dab7e897a 100644 --- a/lib/ansible/modules/network/nuage/nuage_vspk.py +++ b/lib/ansible/modules/network/nuage/nuage_vspk.py @@ -2,20 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Nokia -# 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', @@ -373,7 +364,6 @@ entities: ''' import time -from ansible.module_utils.basic import AnsibleModule try: import importlib @@ -387,6 +377,9 @@ try: except ImportError: HAS_BAMBOU = False +from ansible.module_utils.basic import AnsibleModule + + SUPPORTED_COMMANDS = ['find', 'change_password', 'wait_for_job', 'get_csp_enterprise'] VSPK = None diff --git a/lib/ansible/modules/network/openswitch/ops_command.py b/lib/ansible/modules/network/openswitch/ops_command.py index 14931201451..eb99119b6d7 100644 --- a/lib/ansible/modules/network/openswitch/ops_command.py +++ b/lib/ansible/modules/network/openswitch/ops_command.py @@ -1,20 +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'], @@ -133,12 +124,15 @@ failed_conditions: type: list sample: ['...', '...'] """ +import traceback + import ansible.module_utils.openswitch -from ansible.module_utils.basic import get_exception from ansible.module_utils.netcli import CommandRunner from ansible.module_utils.netcli import AddCommandError, FailedConditionsError from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.six import string_types +from ansible.module_utils._text import to_native + VALID_KEYS = ['command', 'prompt', 'response'] @@ -193,7 +187,6 @@ def main(): try: runner.add_command(**cmd) except AddCommandError: - exc = get_exception() warnings.append('duplicate command detected: %s' % cmd) for item in conditionals: @@ -205,12 +198,11 @@ def main(): try: runner.run() - except FailedConditionsError: - exc = get_exception() - module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions) - except NetworkError: - exc = get_exception() - module.fail_json(msg=str(exc)) + except FailedConditionsError as e: + module.fail_json(msg=to_native(e), failed_conditions=e.failed_conditions, + exception=traceback.format_exc()) + except NetworkError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) result = dict(changed=False, stdout=list()) diff --git a/lib/ansible/modules/network/openswitch/ops_config.py b/lib/ansible/modules/network/openswitch/ops_config.py index 58077f0888f..516120521ef 100644 --- a/lib/ansible/modules/network/openswitch/ops_config.py +++ b/lib/ansible/modules/network/openswitch/ops_config.py @@ -1,20 +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'], @@ -182,11 +173,12 @@ backup_path: type: string sample: /playbooks/ansible/backup/ops_config.2016-07-16@22:28:34 """ -import re +import traceback -from ansible.module_utils.basic import get_exception from ansible.module_utils.openswitch import NetworkModule, NetworkError from ansible.module_utils.netcfg import NetworkConfig, dumps +from ansible.module_utils._text import to_native + def check_args(module, warnings): if module.params['force']: @@ -304,9 +296,8 @@ def main(): try: run(module, result) - except NetworkError: - exc = get_exception() - module.fail_json(msg=str(exc)) + except NetworkError as e: + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.exit_json(**result) diff --git a/lib/ansible/modules/network/openswitch/ops_facts.py b/lib/ansible/modules/network/openswitch/ops_facts.py index 4dff8988358..f12d998a148 100644 --- a/lib/ansible/modules/network/openswitch/ops_facts.py +++ b/lib/ansible/modules/network/openswitch/ops_facts.py @@ -1,20 +1,12 @@ #!/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'], 'supported_by': 'community'} diff --git a/lib/ansible/modules/network/ordnance/ordnance_config.py b/lib/ansible/modules/network/ordnance/ordnance_config.py index d95f51744dd..f72f14aa57b 100644 --- a/lib/ansible/modules/network/ordnance/ordnance_config.py +++ b/lib/ansible/modules/network/ordnance/ordnance_config.py @@ -1,20 +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'], @@ -195,14 +186,14 @@ backup_path: """ import re import time +import traceback - -from ansible.module_utils.basic import get_exception -from ansible.module_utils.six import iteritems -from ansible.module_utils.ordnance import get_config from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.netcfg import NetworkConfig, dumps from ansible.module_utils.netcli import Command +from ansible.module_utils.ordnance import get_config +from ansible.module_utils.six import iteritems +from ansible.module_utils._text import to_native def check_args(module, warnings): @@ -369,10 +360,9 @@ def main(): try: run(module, result) - except NetworkError: - exc = get_exception() + except NetworkError as e: module.disconnect() - module.fail_json(msg=str(exc)) + module.fail_json(msg=to_native(e), exception=traceback.format_exc()) module.disconnect() module.exit_json(**result) diff --git a/lib/ansible/modules/network/ordnance/ordnance_facts.py b/lib/ansible/modules/network/ordnance/ordnance_facts.py index 9f98ed703e2..c2efa0cc012 100644 --- a/lib/ansible/modules/network/ordnance/ordnance_facts.py +++ b/lib/ansible/modules/network/ordnance/ordnance_facts.py @@ -1,20 +1,12 @@ #!/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'], 'supported_by': 'community'} @@ -101,7 +93,6 @@ ansible_net_interfaces: returned: when interfaces is configured type: dict """ -import itertools import re import traceback @@ -124,6 +115,7 @@ class FactsBase(object): except: self.failed_commands.append(cmd) + class Config(FactsBase): def populate(self): diff --git a/lib/ansible/modules/network/ovs/openvswitch_bridge.py b/lib/ansible/modules/network/ovs/openvswitch_bridge.py index 4e4b4c6645f..76bc5007c58 100644 --- a/lib/ansible/modules/network/ovs/openvswitch_bridge.py +++ b/lib/ansible/modules/network/ovs/openvswitch_bridge.py @@ -2,25 +2,12 @@ #coding: utf-8 -*- # (c) 2013, David Stygstra -# # Portions copyright @ 2015 VMware, Inc. -# -# This file is part of Ansible -# -# 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 . - -# pylint: disable=C0111 +# 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'], @@ -114,7 +101,7 @@ EXAMPLES = ''' from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems -from ansible.module_utils.pycompat24 import get_exception + def _fail_mode_to_str(text): if not text: @@ -246,10 +233,10 @@ def map_params_to_obj(module): return obj -# pylint: disable=E0602 + def main(): """ Entry point. """ - argument_spec={ + argument_spec = { 'bridge': {'required': True}, 'parent': {'default': None}, 'vlan': {'default': None, 'type': 'int'}, diff --git a/lib/ansible/modules/network/ovs/openvswitch_db.py b/lib/ansible/modules/network/ovs/openvswitch_db.py index cc9391dabf6..1086627d8f0 100644 --- a/lib/ansible/modules/network/ovs/openvswitch_db.py +++ b/lib/ansible/modules/network/ovs/openvswitch_db.py @@ -1,27 +1,14 @@ #!/usr/bin/python # coding: utf-8 -*- -# pylint: disable=C0111 - # # (c) 2015, Mark Hamilton -# # Portions copyright @ 2015 VMware, Inc. -# -# This file is part of Ansible -# -# 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'], @@ -101,6 +88,9 @@ EXAMPLES = ''' col: other_config key: disable-in-band ''' +import re + +from ansible.module_utils.basic import AnsibleModule def map_obj_to_commands(want, have, module): @@ -166,7 +156,6 @@ def map_params_to_obj(module): return obj -# pylint: disable=E0602 def main(): """ Entry point for ansible module. """ argument_spec = { @@ -202,13 +191,5 @@ def main(): module.exit_json(**result) -# pylint: disable=W0614 -# pylint: disable=W0401 -# pylint: disable=W0622 - -# import module snippets -from ansible.module_utils.basic import * -import re - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/ovs/openvswitch_port.py b/lib/ansible/modules/network/ovs/openvswitch_port.py index e6ee2770f72..e7c01914539 100644 --- a/lib/ansible/modules/network/ovs/openvswitch_port.py +++ b/lib/ansible/modules/network/ovs/openvswitch_port.py @@ -1,26 +1,13 @@ #!/usr/bin/python #coding: utf-8 -*- -# pylint: disable=C0111 - # (c) 2013, David Stygstra -# # Portions copyright @ 2015 VMware, Inc. -# -# This file is part of Ansible -# -# 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'], @@ -114,7 +101,7 @@ EXAMPLES = ''' from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems -from ansible.module_utils.pycompat24 import get_exception + def _external_ids_to_dict(text): text = text.strip() @@ -239,7 +226,6 @@ def map_params_to_obj(module): return obj -# pylint: disable=E0602 def main(): """ Entry point. """ argument_spec={ diff --git a/lib/ansible/modules/network/protocol/net_lldp.py b/lib/ansible/modules/network/protocol/net_lldp.py index 7f3f9e34a7d..7f3d923cf82 100644 --- a/lib/ansible/modules/network/protocol/net_lldp.py +++ b/lib/ansible/modules/network/protocol/net_lldp.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/routing/net_static_route.py b/lib/ansible/modules/network/routing/net_static_route.py index eb6efa22c4b..79924b6d1e0 100644 --- a/lib/ansible/modules/network/routing/net_static_route.py +++ b/lib/ansible/modules/network/routing/net_static_route.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/sros/sros_command.py b/lib/ansible/modules/network/sros/sros_command.py index 61b24dc47bd..f0c39a2788d 100644 --- a/lib/ansible/modules/network/sros/sros_command.py +++ b/lib/ansible/modules/network/sros/sros_command.py @@ -1,20 +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', @@ -146,12 +137,12 @@ failed_conditions: """ import time -from ansible.module_utils.sros import run_commands -from ansible.module_utils.sros import sros_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network_common import ComplexList from ansible.module_utils.netcli import Conditional +from ansible.module_utils.network_common import ComplexList from ansible.module_utils.six import string_types +from ansible.module_utils.sros import run_commands, sros_argument_spec, check_args + def to_lines(stdout): for item in stdout: diff --git a/lib/ansible/modules/network/sros/sros_config.py b/lib/ansible/modules/network/sros/sros_config.py index 29e8e990c4b..f19bb7406c9 100644 --- a/lib/ansible/modules/network/sros/sros_config.py +++ b/lib/ansible/modules/network/sros/sros_config.py @@ -1,20 +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', @@ -219,8 +210,8 @@ backup_path: """ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.netcfg import NetworkConfig, dumps -from ansible.module_utils.sros import sros_argument_spec, check_args -from ansible.module_utils.sros import load_config, run_commands, get_config +from ansible.module_utils.sros import sros_argument_spec, check_args, load_config, run_commands, get_config + def sanitize_config(lines): commands = list() @@ -232,6 +223,7 @@ def sanitize_config(lines): commands.append(line) return commands + def get_active_config(module): contents = module.params['config'] if not contents: @@ -241,6 +233,7 @@ def get_active_config(module): return get_config(module, flags) return contents + def get_candidate(module): candidate = NetworkConfig(indent=4) if module.params['src']: @@ -250,6 +243,7 @@ def get_candidate(module): candidate.add(module.params['lines'], parents=parents) return candidate + def run(module, result): match = module.params['match'] diff --git a/lib/ansible/modules/network/sros/sros_rollback.py b/lib/ansible/modules/network/sros/sros_rollback.py index b6746c0e9c3..d201dc61bb4 100644 --- a/lib/ansible/modules/network/sros/sros_rollback.py +++ b/lib/ansible/modules/network/sros/sros_rollback.py @@ -1,20 +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', @@ -110,9 +101,8 @@ updates: sample: ['...', '...'] """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.sros import load_config, get_config -from ansible.module_utils.sros import sros_argument_spec, check_args from ansible.module_utils.netcfg import NetworkConfig, dumps +from ansible.module_utils.sros import load_config, get_config, sros_argument_spec, check_args def invoke(name, *args, **kwargs): diff --git a/lib/ansible/modules/network/system/net_banner.py b/lib/ansible/modules/network/system/net_banner.py index ff036c8b331..38930a1c57f 100644 --- a/lib/ansible/modules/network/system/net_banner.py +++ b/lib/ansible/modules/network/system/net_banner.py @@ -1,20 +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'], diff --git a/lib/ansible/modules/network/system/net_command.py b/lib/ansible/modules/network/system/net_command.py index c86a75daefe..a9608408844 100644 --- a/lib/ansible/modules/network/system/net_command.py +++ b/lib/ansible/modules/network/system/net_command.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/system/net_logging.py b/lib/ansible/modules/network/system/net_logging.py index 5247b081fbf..9bab08d7df7 100644 --- a/lib/ansible/modules/network/system/net_logging.py +++ b/lib/ansible/modules/network/system/net_logging.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/system/net_system.py b/lib/ansible/modules/network/system/net_system.py index bd55892d795..af394dcb691 100644 --- a/lib/ansible/modules/network/system/net_system.py +++ b/lib/ansible/modules/network/system/net_system.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/network/system/net_user.py b/lib/ansible/modules/network/system/net_user.py index 2ab3d9b0f1e..96f601c8c97 100644 --- a/lib/ansible/modules/network/system/net_user.py +++ b/lib/ansible/modules/network/system/net_user.py @@ -2,22 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# 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/test/sanity/code-smell/boilerplate.sh b/test/sanity/code-smell/boilerplate.sh index b03b6b9a5e4..2aa2a4c1f56 100755 --- a/test/sanity/code-smell/boilerplate.sh +++ b/test/sanity/code-smell/boilerplate.sh @@ -20,45 +20,86 @@ 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/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/database/proxysql -prune \ -o -path ./lib/ansible/modules/cloud/ovirt -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ + -o -path ./lib/ansible/modules/monitoring -prune \ + -o -path ./lib/ansible/modules/network/aos -prune \ + -o -path ./lib/ansible/modules/network/avi -prune \ + -o -path ./lib/ansible/modules/network/cloudengine -prune \ + -o -path ./lib/ansible/modules/network/eos -prune \ + -o -path ./lib/ansible/modules/network/f5 -prune \ + -o -path ./lib/ansible/modules/network/ios -prune \ + -o -path ./lib/ansible/modules/network/junos -prune \ + -o -path ./lib/ansible/modules/network/lenovo -prune \ + -o -path ./lib/ansible/modules/network/netvisor -prune \ + -o -path ./lib/ansible/modules/network/nxos -prune \ + -o -path ./lib/ansible/modules/network/panos -prune \ + -o -path ./lib/ansible/modules/network/vyos -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/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/database/proxysql -prune \ -o -path ./lib/ansible/modules/cloud/ovirt -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \ + -o -path ./lib/ansible/modules/monitoring -prune \ + -o -path ./lib/ansible/modules/network/aos -prune \ + -o -path ./lib/ansible/modules/network/avi -prune \ + -o -path ./lib/ansible/modules/network/cloudengine -prune \ + -o -path ./lib/ansible/modules/network/eos -prune \ + -o -path ./lib/ansible/modules/network/f5 -prune \ + -o -path ./lib/ansible/modules/network/ios -prune \ + -o -path ./lib/ansible/modules/network/junos -prune \ + -o -path ./lib/ansible/modules/network/lenovo -prune \ + -o -path ./lib/ansible/modules/network/netvisor -prune \ + -o -path ./lib/ansible/modules/network/nxos -prune \ + -o -path ./lib/ansible/modules/network/panos -prune \ + -o -path ./lib/ansible/modules/network/vyos -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 ! -# files ! -# database ;; break up *! -# monitoring *! -# packaging/os *i -# cloud/cloudstack * -# cloud/openstack * +# Key: +# [*]: import * fixes +# [!]: many get_exception fixes +# [i]: a few get_exception fixes +# (everything below needs boilerplate added) +# Priorities: import*, get_exception, then boilerplate-only +# +# database/proxysql [!] +# network/ios +# network/eos [i] +# network/netvisor +# network/aos [!] +# network/vyos [i] +# identity [!] +# network/lenovo +# network/panos [!] +# network/junos [i] +# files [!] +# network/avi +# network/f5 [*][i] +# monitoring [*][!] +# packaging/os [*][i] +# cloud/cloudstack [*] +# cloud/openstack [*] # cloud/ovirt -# cloud/amazon * -# network ;; break up *! -# ( * == import* fixes, ! == many get_exception fixes, i == a few get_exception fixes) +# network/cloudengine [i] +# network/nxos [*][i] +# cloud/amazon [*] + ### TODO: -### - module_utils -### - contrib/ +### - module_utils <=== these are important but not well organized so we'd +### have to construct the teset file by file +### - contrib/ <=== Not a priority as these will move to inventory plugins over time if test -n "$metaclass1" -o -n "$metaclass2" -o -n "$metaclass3" ; then diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 9c5f4c12fc7..3598545d5fc 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -254,9 +254,7 @@ lib/ansible/modules/monitoring/zabbix_host.py lib/ansible/modules/monitoring/zabbix_hostmacro.py lib/ansible/modules/monitoring/zabbix_maintenance.py lib/ansible/modules/monitoring/zabbix_screen.py -lib/ansible/modules/network/a10/a10_server.py lib/ansible/modules/network/a10/a10_server_axapi3.py -lib/ansible/modules/network/a10/a10_service_group.py lib/ansible/modules/network/a10/a10_virtual_server.py lib/ansible/modules/network/aos/aos_asn_pool.py lib/ansible/modules/network/aos/aos_blueprint.py