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

@ -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)