Remove deprecated get_exception API

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-12-26 08:33:21 +05:30 committed by Brian Coca
commit 6bd0fbb63c
42 changed files with 284 additions and 409 deletions

View file

@ -134,7 +134,6 @@ build_errors:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aos.aos import get_aos_session, check_aos_version, find_collection_item
from ansible.module_utils.pycompat24 import get_exception
def create_blueprint(module, aos, name):
@ -149,8 +148,7 @@ def create_blueprint(module, aos, name):
blueprint = aos.Blueprints[name]
blueprint.create(template_id, reference_arch=margs['reference_arch'])
except:
exc = get_exception()
except Exception as exc:
msg = "Unable to create blueprint: %s" % exc.message
if 'UNPROCESSABLE ENTITY' in exc.message:
msg += ' (likely missing dependencies)'
@ -170,8 +168,7 @@ def ensure_absent(module, aos, blueprint):
if not module.check_mode:
try:
blueprint.delete()
except:
exc = get_exception()
except Exception as exc:
module.fail_json(msg='Unable to delete blueprint, %s' % exc.message)
module.exit_json(changed=True,
@ -294,5 +291,6 @@ def main():
aos_blueprint(module)
if __name__ == '__main__':
main()

View file

@ -163,7 +163,7 @@ import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aos.aos import get_aos_session, find_collection_item, check_aos_version
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
try:
import yaml
@ -238,10 +238,9 @@ def blueprint_param_present(module, aos, blueprint, param, param_value):
if not module.check_mode:
try:
param.value = param_value
except:
exc = get_exception()
module.fail_json(msg='unable to write to param %s: %r' %
(margs['name'], exc))
except Exception as exc:
module.fail_json(msg='unable to write to param %s: %s' %
(margs['name'], to_native(exc)))
module.exit_json(changed=True,
blueprint=blueprint.name,
@ -265,9 +264,8 @@ def blueprint_param_absent(module, aos, blueprint, param, param_value):
if not module.check_mode:
try:
param.value = {}
except:
exc = get_exception()
module.fail_json(msg='Unable to write to param %s: %r' % (margs['name'], exc))
except Exception as exc:
module.fail_json(msg='Unable to write to param %s: %s' % (margs['name'], to_native(exc)))
module.exit_json(changed=True,
blueprint=blueprint.name,

View file

@ -84,8 +84,8 @@ EXAMPLES = '''
import json
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.network.aos.aos import get_aos_session, find_collection_item, do_load_resource, check_aos_version, content_to_dict
@ -103,9 +103,8 @@ def ensure_present(module, aos, blueprint, virtnet):
if not module.check_mode:
try:
virtnet.create(module.params['content'])
except:
e = get_exception()
module.fail_json(msg="unable to create virtual-network : %r" % e)
except Exception as e:
module.fail_json(msg="unable to create virtual-network : %s" % to_native(e))
module.exit_json(changed=True,
blueprint=blueprint.name,
@ -120,9 +119,8 @@ def ensure_absent(module, aos, blueprint, virtnet):
if not module.check_mode:
try:
virtnet.delete()
except:
e = get_exception()
module.fail_json(msg="unable to delete virtual-network %s : %r" % (virtnet.name, e))
except Exception as e:
module.fail_json(msg="unable to delete virtual-network %s : %s" % (virtnet.name, to_native(e)))
module.exit_json(changed=True,
blueprint=blueprint.name)
@ -214,5 +212,6 @@ def main():
blueprint_virtnet(module)
if __name__ == '__main__':
main()

View file

@ -137,7 +137,7 @@ failed_conditions:
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
from ansible.module_utils.six import string_types
from ansible.module_utils.network.common.parsing import Conditional
from ansible.module_utils.network.common.utils import ComplexList
@ -216,9 +216,8 @@ def main():
try:
conditionals = [Conditional(c) for c in wait_for]
except AttributeError:
exc = get_exception()
module.fail_json(msg=str(exc))
except AttributeError as exc:
module.fail_json(msg=to_native(exc))
retries = module.params['retries']
interval = module.params['interval']

View file

@ -110,7 +110,6 @@ from ansible.module_utils.network.fortios.fortios import fortios_argument_spec,
from ansible.module_utils.network.fortios.fortios import backup, AnsibleFortios
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
# check for netaddr lib
@ -287,5 +286,6 @@ def main():
# Apply changes (check mode is managed directly by the fortigate object)
fortigate.apply_changes()
if __name__ == '__main__':
main()

View file

@ -81,7 +81,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.netconf import exec_rpc
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param
from ansible.module_utils.network.junos.junos import get_configuration, get_connection
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
from ansible.module_utils.six import iteritems
@ -263,9 +263,8 @@ class Facts(FactsBase):
device = Device(host, **kwargs)
device.open()
device.timeout = get_param(module, 'timeout') or 10
except ConnectError:
exc = get_exception()
module.fail_json('unable to connect to %s: %s' % (host, str(exc)))
except ConnectError as exc:
module.fail_json('unable to connect to %s: %s' % (host, to_native(exc)))
return device
@ -286,6 +285,7 @@ class Facts(FactsBase):
return facts
FACT_SUBSETS = dict(
default=Default,
hardware=Hardware,

View file

@ -103,7 +103,7 @@ EXAMPLES = """
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
try:
from jnpr.junos import Device
@ -134,9 +134,8 @@ def connect(module):
device = Device(host, **kwargs)
device.open()
device.timeout = get_param(module, 'timeout') or 10
except ConnectError:
exc = get_exception()
module.fail_json(msg='unable to connect to %s: %s' % (host, str(exc)))
except ConnectError as exc:
module.fail_json(msg='unable to connect to %s: %s' % (host, to_native(exc)))
return device

View file

@ -150,7 +150,7 @@ RETURN = '''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -345,9 +345,8 @@ def main():
module.exit_json(changed=changed, msg="okey dokey")
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
if __name__ == '__main__':

View file

@ -260,7 +260,7 @@ RETURN = '''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -508,9 +508,8 @@ def main():
module.fail_json(msg='Rule with the same name but different objects exists.')
try:
changed = add_security_rule(device, sec_rule, rule_exist)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
if changed and commit:
result = _commit(device, devicegroup)

View file

@ -91,7 +91,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
import time
try:
@ -193,11 +193,11 @@ def main():
cert_friendly_name,
signed_by,
rsa_nbits)
except Exception:
exc = get_exception()
module.fail_json(msg=exc.message)
except Exception as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=True, msg="okey dokey")
if __name__ == '__main__':
main()

View file

@ -83,7 +83,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
import os.path
import xml.etree
@ -183,9 +183,8 @@ def main():
try:
changed, filename = import_file(xapi, module, ip_address, file_, category)
except Exception:
exc = get_exception()
module.fail_json(msg=exc.message)
except Exception as exc:
module.fail_json(msg=to_native(exc))
# cleanup and delete file if local
if url is not None:
@ -193,5 +192,6 @@ def main():
module.exit_json(changed=changed, filename=filename, msg="okey dokey")
if __name__ == '__main__':
main()

View file

@ -83,8 +83,7 @@ RETURN = '''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -171,14 +170,14 @@ def main():
try:
changed = add_dhcp_if(xapi, if_name, zone_name, create_default_route)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
if changed and commit:
xapi.commit(cmd="<commit></commit>", sync=True, interval=1)
module.exit_json(changed=changed, msg="okey dokey")
if __name__ == '__main__':
main()

View file

@ -91,7 +91,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -196,11 +196,11 @@ def main():
if changed and commit:
xapi.commit(cmd="<commit></commit>", sync=True, interval=1)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg="okey dokey")
if __name__ == '__main__':
main()

View file

@ -149,7 +149,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
# import pydevd
# pydevd.settrace('localhost', port=60374, stdoutToServer=True, stderrToServer=True)
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -374,9 +374,8 @@ def main():
match.delete()
if commit:
device.commit(sync=True)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=True, msg='Rule \'%s\' successfully deleted.' % rule_name)
else:
@ -417,9 +416,8 @@ def main():
changed = add_rule(rulebase, new_rule)
if changed and commit:
device.commit(sync=True)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Rule \'%s\' successfully added.' % rule_name)
elif operation == 'update':
# Search for the rule. Update if found.
@ -450,9 +448,8 @@ def main():
changed = update_rule(rulebase, new_rule)
if changed and commit:
device.commit(sync=True)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Rule \'%s\' successfully updated.' % rule_name)
else:
module.fail_json(msg='Rule \'%s\' does not exist. Use operation: \'add\' to add it.' % rule_name)

View file

@ -167,7 +167,7 @@ RETURN = '''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -392,9 +392,8 @@ def main():
if match:
try:
match.delete()
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=True, msg='Object \'%s\' successfully deleted' % obj_name)
else:
@ -424,9 +423,8 @@ def main():
color=color
)
changed = add_object(device, dev_group, new_object)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Object \'%s\' successfully added' % obj_name)
elif operation == "update":
# Search for the object. Update if found.
@ -451,9 +449,8 @@ def main():
color=color
)
changed = add_object(device, dev_group, new_object)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Object \'%s\' successfully updated.' % obj_name)
else:
module.fail_json(msg='Object \'%s\' does not exist. Use operation: \'add\' to add it.' % obj_name)

View file

@ -111,7 +111,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
@ -214,9 +214,8 @@ def main():
if changed and commit:
xapi.commit(cmd="<commit></commit>", sync=True, interval=1)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg="okey dokey")

View file

@ -107,7 +107,8 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
from ansible.module_utils.basic import AnsibleModule, get_exception
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
try:
from pandevice import base
@ -183,8 +184,7 @@ def add_address_group(device, dev_group, ag_object):
exc = None
try:
ag_object.create()
except Exception:
exc = get_exception()
except Exception as exc:
return False, exc
return True, exc
@ -204,8 +204,7 @@ def delete_address_group(device, dev_group, obj_name):
if static_obj:
try:
static_obj.delete()
except Exception:
exc = get_exception()
except Exception as exc:
return False, exc
return True, None
else:
@ -263,9 +262,8 @@ def main():
if result and commit:
try:
device.commit(sync=True)
except Exception:
exc = get_exception()
module.fail_json(msg=exc.message)
except Exception as exc:
module.fail_json(msg=to_native(exc))
elif operation == 'delete':
obj_name = module.params.get('sag_name', None)

View file

@ -236,7 +236,7 @@ RETURN = '''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_exception
from ansible.module_utils._text import to_native
try:
import pan.xapi
@ -479,9 +479,8 @@ def main():
try:
if commit:
match.delete()
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=True, msg='Rule \'%s\' successfully deleted' % rule_name)
else:
@ -525,9 +524,8 @@ def main():
changed = add_rule(rulebase, new_rule)
if changed and commit:
device.commit(sync=True)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Rule \'%s\' successfully added' % rule_name)
elif operation == 'update':
# Search for the rule. Update if found.
@ -563,9 +561,8 @@ def main():
changed = update_rule(rulebase, new_rule)
if changed and commit:
device.commit(sync=True)
except PanXapiError:
exc = get_exception()
module.fail_json(msg=exc.message)
except PanXapiError as exc:
module.fail_json(msg=to_native(exc))
module.exit_json(changed=changed, msg='Rule \'%s\' successfully updated' % rule_name)
else:
module.fail_json(msg='Rule \'%s\' does not exist. Use operation: \'add\' to add it.' % rule_name)

View file

@ -144,7 +144,7 @@ warnings:
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
from ansible.module_utils.network.common.parsing import Conditional
from ansible.module_utils.network.common.utils import ComplexList
from ansible.module_utils.six import string_types
@ -200,9 +200,8 @@ def main():
wait_for = module.params['wait_for'] or list()
try:
conditionals = [Conditional(c) for c in wait_for]
except AttributeError:
exc = get_exception()
module.fail_json(msg=str(exc))
except AttributeError as exc:
module.fail_json(msg=to_native(exc))
retries = module.params['retries']
interval = module.params['interval']