Fix get_exception and wildcard imports for nxos modules
parent
c81314dcb9
commit
2f8831c787
|
@ -1,20 +1,10 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
# Copyright: Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -155,13 +145,13 @@ failed_conditions:
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.nxos import run_commands
|
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.six import string_types
|
|
||||||
from ansible.module_utils.netcli import Conditional, FailedConditionalError
|
from ansible.module_utils.netcli import Conditional, FailedConditionalError
|
||||||
from ansible.module_utils.network_common import ComplexList
|
from ansible.module_utils.network_common import ComplexList
|
||||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
from ansible.module_utils.nxos import check_args, nxos_argument_spec, run_commands
|
||||||
|
from ansible.module_utils.six import string_types
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
def to_lines(stdout):
|
def to_lines(stdout):
|
||||||
lines = list()
|
lines = list()
|
||||||
|
@ -171,6 +161,7 @@ def to_lines(stdout):
|
||||||
lines.append(item)
|
lines.append(item)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
def parse_commands(module, warnings):
|
def parse_commands(module, warnings):
|
||||||
transform = ComplexList(dict(
|
transform = ComplexList(dict(
|
||||||
command=dict(key=True),
|
command=dict(key=True),
|
||||||
|
@ -199,6 +190,7 @@ def to_cli(obj):
|
||||||
cmd += ' | json'
|
cmd += ' | json'
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""entry point for module execution
|
"""entry point for module execution
|
||||||
"""
|
"""
|
||||||
|
@ -218,7 +210,6 @@ def main():
|
||||||
module = AnsibleModule(argument_spec=argument_spec,
|
module = AnsibleModule(argument_spec=argument_spec,
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
|
|
||||||
result = {'changed': False}
|
result = {'changed': False}
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
|
@ -230,9 +221,8 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conditionals = [Conditional(c) for c in wait_for]
|
conditionals = [Conditional(c) for c in wait_for]
|
||||||
except AttributeError:
|
except AttributeError as exc:
|
||||||
exc = get_exception()
|
module.fail_json(msg=to_native(exc))
|
||||||
module.fail_json(msg=str(exc))
|
|
||||||
|
|
||||||
retries = module.params['retries']
|
retries = module.params['retries']
|
||||||
interval = module.params['interval']
|
interval = module.params['interval']
|
||||||
|
@ -248,9 +238,8 @@ def main():
|
||||||
conditionals = list()
|
conditionals = list()
|
||||||
break
|
break
|
||||||
conditionals.remove(item)
|
conditionals.remove(item)
|
||||||
except FailedConditionalError:
|
except FailedConditionalError as exc:
|
||||||
exc = get_exception()
|
module.fail_json(msg=to_native(exc))
|
||||||
module.fail_json(msg=str(exc))
|
|
||||||
|
|
||||||
if not conditionals:
|
if not conditionals:
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,20 +1,10 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
# Copyright: Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -127,12 +117,11 @@ changed:
|
||||||
sample: true
|
sample: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
|
||||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.nxos import check_args, load_config, nxos_argument_spec, run_commands
|
||||||
|
|
||||||
|
|
||||||
def execute_show_command(command, module, command_type='cli_show'):
|
def execute_show_command(command, module, command_type='cli_show'):
|
||||||
if 'show run' not in command:
|
if 'show run' not in command:
|
||||||
|
@ -319,10 +308,10 @@ def main():
|
||||||
argument_spec.update(nxos_argument_spec)
|
argument_spec.update(nxos_argument_spec)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec,
|
module = AnsibleModule(argument_spec=argument_spec,
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
['server','peer'],
|
['server', 'peer'],
|
||||||
['source_addr','source_int']],
|
['source_addr', 'source_int']],
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
check_args(module, warnings)
|
check_args(module, warnings)
|
||||||
|
@ -424,6 +413,5 @@ def main():
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue