From c0217e14a7f063d193bb4954da2b8dbe6fe90f7e Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Wed, 18 May 2016 18:08:30 +0200 Subject: [PATCH] Convert the network subfolder to py3/py2.4 syntax (#3690) --- lib/ansible/modules/network/basics/get_url.py | 6 ++++-- lib/ansible/modules/network/basics/uri.py | 6 ++++-- .../modules/network/cumulus/cl_img_install.py | 3 ++- lib/ansible/modules/network/cumulus/cl_ports.py | 9 ++++++--- lib/ansible/modules/network/eos/eos_command.py | 3 ++- lib/ansible/modules/network/ios/ios_command.py | 3 ++- lib/ansible/modules/network/iosxr/iosxr_command.py | 3 ++- lib/ansible/modules/network/junos/junos_command.py | 3 ++- lib/ansible/modules/network/nxos/nxos_command.py | 6 ++++-- lib/ansible/modules/network/nxos/nxos_facts.py | 3 ++- lib/ansible/modules/network/nxos/nxos_feature.py | 14 +++++++++----- lib/ansible/modules/network/nxos/nxos_interface.py | 8 +++++--- .../modules/network/nxos/nxos_ip_interface.py | 8 +++++--- lib/ansible/modules/network/nxos/nxos_ping.py | 5 +++-- .../modules/network/nxos/nxos_switchport.py | 13 +++++++++---- lib/ansible/modules/network/nxos/nxos_vlan.py | 13 +++++++++---- lib/ansible/modules/network/nxos/nxos_vrf.py | 14 +++++++++----- .../modules/network/nxos/nxos_vrf_interface.py | 6 ++++-- lib/ansible/modules/network/nxos/nxos_vrrp.py | 8 +++++--- .../modules/network/openswitch/ops_command.py | 3 ++- 20 files changed, 90 insertions(+), 47 deletions(-) diff --git a/lib/ansible/modules/network/basics/get_url.py b/lib/ansible/modules/network/basics/get_url.py index d6527c0f501..6404676ed8d 100644 --- a/lib/ansible/modules/network/basics/get_url.py +++ b/lib/ansible/modules/network/basics/get_url.py @@ -225,7 +225,8 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head f = os.fdopen(fd, 'wb') try: shutil.copyfileobj(rsp, f) - except Exception, err: + except Exception: + err = get_exception() os.remove(tempname) module.fail_json(msg="failed to create temporary content file: %s" % str(err)) f.close() @@ -391,7 +392,8 @@ def main(): if os.path.exists(dest): backup_file = module.backup_local(dest) shutil.copyfile(tmpsrc, dest) - except Exception, err: + except Exception: + err = get_exception() os.remove(tmpsrc) module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err))) changed = True diff --git a/lib/ansible/modules/network/basics/uri.py b/lib/ansible/modules/network/basics/uri.py index 0c0bfd3e9c3..c0430f83cc9 100644 --- a/lib/ansible/modules/network/basics/uri.py +++ b/lib/ansible/modules/network/basics/uri.py @@ -220,7 +220,8 @@ def write_file(module, url, dest, content): f = open(tmpsrc, 'wb') try: f.write(content) - except Exception, err: + except Exception: + err = get_exception() os.remove(tmpsrc) module.fail_json(msg="failed to create temporary content file: %s" % str(err)) f.close() @@ -255,7 +256,8 @@ def write_file(module, url, dest, content): if checksum_src != checksum_dest: try: shutil.copyfile(tmpsrc, dest) - except Exception, err: + except Exception: + err = get_exception() os.remove(tmpsrc) module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err))) diff --git a/lib/ansible/modules/network/cumulus/cl_img_install.py b/lib/ansible/modules/network/cumulus/cl_img_install.py index 53b58e789ac..cb36abcb970 100644 --- a/lib/ansible/modules/network/cumulus/cl_img_install.py +++ b/lib/ansible/modules/network/cumulus/cl_img_install.py @@ -114,7 +114,8 @@ def check_url(module, url): def run_cl_cmd(module, cmd, check_rc=True): try: (rc, out, err) = module.run_command(cmd, check_rc=check_rc) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg=e.strerror) # trim last line as it is always empty ret = out.splitlines() diff --git a/lib/ansible/modules/network/cumulus/cl_ports.py b/lib/ansible/modules/network/cumulus/cl_ports.py index e632cdddac2..677ce18d5ca 100644 --- a/lib/ansible/modules/network/cumulus/cl_ports.py +++ b/lib/ansible/modules/network/cumulus/cl_ports.py @@ -84,7 +84,8 @@ def hash_existing_ports_conf(module): try: existing_ports_conf = open(PORTS_CONF).readlines() - except IOError, error_msg: + except IOError: + error_msg = get_exception() _msg = "Failed to open %s: %s" % (PORTS_CONF, error_msg) module.fail_json(msg=_msg) return # for testing only should return on module.fail_json @@ -143,7 +144,8 @@ def make_copy_of_orig_ports_conf(module): try: shutil.copyfile(PORTS_CONF, PORTS_CONF + '.orig') - except IOError, error_msg: + except IOError: + error_msg = get_exception() _msg = "Failed to save the original %s: %s" % (PORTS_CONF, error_msg) module.fail_json(msg=_msg) return # for testing only @@ -165,7 +167,8 @@ def write_to_ports_conf(module): temp.write(_str) temp.seek(0) shutil.copyfile(temp.name, PORTS_CONF) - except IOError, error_msg: + except IOError: + error_msg = get_exception() module.fail_json( msg="Failed to write to %s: %s" % (PORTS_CONF, error_msg)) finally: diff --git a/lib/ansible/modules/network/eos/eos_command.py b/lib/ansible/modules/network/eos/eos_command.py index 322725fec26..956bf8f1017 100644 --- a/lib/ansible/modules/network/eos/eos_command.py +++ b/lib/ansible/modules/network/eos/eos_command.py @@ -142,7 +142,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) result = dict(changed=False) diff --git a/lib/ansible/modules/network/ios/ios_command.py b/lib/ansible/modules/network/ios/ios_command.py index 81e06800005..68afb04566c 100644 --- a/lib/ansible/modules/network/ios/ios_command.py +++ b/lib/ansible/modules/network/ios/ios_command.py @@ -135,7 +135,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) result = dict(changed=False) diff --git a/lib/ansible/modules/network/iosxr/iosxr_command.py b/lib/ansible/modules/network/iosxr/iosxr_command.py index 88a05e9280c..af4291a3587 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_command.py +++ b/lib/ansible/modules/network/iosxr/iosxr_command.py @@ -140,7 +140,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) diff --git a/lib/ansible/modules/network/junos/junos_command.py b/lib/ansible/modules/network/junos/junos_command.py index 9ef7be5779d..42056320bd5 100644 --- a/lib/ansible/modules/network/junos/junos_command.py +++ b/lib/ansible/modules/network/junos/junos_command.py @@ -214,7 +214,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) result = dict(changed=False) diff --git a/lib/ansible/modules/network/nxos/nxos_command.py b/lib/ansible/modules/network/nxos/nxos_command.py index 2e09584dcc5..0e6e3b6f09c 100644 --- a/lib/ansible/modules/network/nxos/nxos_command.py +++ b/lib/ansible/modules/network/nxos/nxos_command.py @@ -147,7 +147,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) result = dict(changed=False, result=list()) @@ -164,7 +165,8 @@ def main(): if cmd.endswith('json'): try: response[index] = module.from_json(response[index]) - except ValueError, exc: + except ValueError: + exc = get_exception() module.fail_json(msg='failed to parse json response', exc_message=str(exc), response=response[index], cmd=cmd, response_dict=response) diff --git a/lib/ansible/modules/network/nxos/nxos_facts.py b/lib/ansible/modules/network/nxos/nxos_facts.py index 60a0f9d36f2..c37aa1af1f4 100644 --- a/lib/ansible/modules/network/nxos/nxos_facts.py +++ b/lib/ansible/modules/network/nxos/nxos_facts.py @@ -66,7 +66,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response diff --git a/lib/ansible/modules/network/nxos/nxos_feature.py b/lib/ansible/modules/network/nxos/nxos_feature.py index b0c5f1de909..9f11a51a8de 100644 --- a/lib/ansible/modules/network/nxos/nxos_feature.py +++ b/lib/ansible/modules/network/nxos/nxos_feature.py @@ -89,7 +89,8 @@ feature: def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -114,9 +115,12 @@ def get_cli_body_ssh(command, response): def execute_show(cmds, module, command_type=None): try: - response = module.execute(cmds, - command_type=command_type) if command_type else module.execute(cmds) - except ShellError, clie: + if command_type: + response = module.execute(cmds, command_type=command_type) + else: + response = module.execute(cmds) + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(cmds), error=str(clie)) return response @@ -267,4 +271,4 @@ from ansible.module_utils.shell import * from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index d60986af4ab..27562fc557a 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -525,7 +525,8 @@ def smart_existing(module, intf_type, normalized_interface): def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -556,7 +557,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response @@ -715,4 +717,4 @@ from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_ip_interface.py b/lib/ansible/modules/network/nxos/nxos_ip_interface.py index 74b796d28e0..da4edb1f65a 100644 --- a/lib/ansible/modules/network/nxos/nxos_ip_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_ip_interface.py @@ -102,7 +102,8 @@ changed: def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -134,7 +135,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(cmds), error=str(clie)) return response @@ -523,4 +525,4 @@ from ansible.module_utils.shell import * from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_ping.py b/lib/ansible/modules/network/nxos/nxos_ping.py index be3fab9db9b..9f7e912c9c2 100644 --- a/lib/ansible/modules/network/nxos/nxos_ping.py +++ b/lib/ansible/modules/network/nxos/nxos_ping.py @@ -150,7 +150,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(cmds), error=str(clie)) return response @@ -257,4 +258,4 @@ from ansible.module_utils.shell import * from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_switchport.py b/lib/ansible/modules/network/nxos/nxos_switchport.py index 8e17c41c7d6..ee9140d0f48 100644 --- a/lib/ansible/modules/network/nxos/nxos_switchport.py +++ b/lib/ansible/modules/network/nxos/nxos_switchport.py @@ -440,7 +440,8 @@ def apply_value_map(value_map, resource): def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -465,8 +466,12 @@ def get_cli_body_ssh(command, response, module): def execute_show(cmds, module, command_type=None): try: - response = module.execute(cmds, command_type=command_type) if command_type else module.execute(cmds) - except ShellError, clie: + if command_type: + response = module.execute(cmds, command_type=command_type) + else: + response = module.execute(cmds) + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response @@ -627,4 +632,4 @@ from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_vlan.py b/lib/ansible/modules/network/nxos/nxos_vlan.py index 900c5efe659..6d1e4839e99 100644 --- a/lib/ansible/modules/network/nxos/nxos_vlan.py +++ b/lib/ansible/modules/network/nxos/nxos_vlan.py @@ -280,7 +280,8 @@ def apply_value_map(value_map, resource): def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -305,8 +306,12 @@ def get_cli_body_ssh(command, response, module): def execute_show(cmds, module, command_type=None): try: - response = module.execute(cmds, command_type=command_type) if command_type else module.execute(cmds) - except ShellError, clie: + if command_type: + response = module.execute(cmds, command_type=command_type) + else: + response = module.execute(cmds) + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response @@ -424,4 +429,4 @@ from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_vrf.py b/lib/ansible/modules/network/nxos/nxos_vrf.py index 491e7067625..8106bf5ac2d 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf.py @@ -104,7 +104,8 @@ changed: def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -129,9 +130,12 @@ def get_cli_body_ssh_vrf(command, response): def execute_show(cmds, module, command_type=None): try: - response = module.execute(cmds, - command_type=command_type) if command_type else module.execute(cmds) - except ShellError, clie: + if command_type: + response = module.execute(cmds, command_type=command_type) + else: + response = module.execute(cmds) + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(cmds), error=str(clie)) return response @@ -307,4 +311,4 @@ from ansible.module_utils.shell import * from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index b3319225464..4bb0e8fa593 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -92,7 +92,8 @@ changed: def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -118,7 +119,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response diff --git a/lib/ansible/modules/network/nxos/nxos_vrrp.py b/lib/ansible/modules/network/nxos/nxos_vrrp.py index e1a940cdd9a..7db482cd623 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrrp.py +++ b/lib/ansible/modules/network/nxos/nxos_vrrp.py @@ -116,7 +116,8 @@ changed: def execute_config_command(commands, module): try: module.configure(commands) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) @@ -149,7 +150,8 @@ def execute_show(cmds, module, command_type=None): response = module.execute(cmds, command_type=command_type) else: response = module.execute(cmds) - except ShellError, clie: + except ShellError: + clie = get_exception() module.fail_json(msg='Error sending {0}'.format(command), error=str(clie)) return response @@ -422,4 +424,4 @@ from ansible.module_utils.shell import * from ansible.module_utils.netcfg import * from ansible.module_utils.nxos import * if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/ansible/modules/network/openswitch/ops_command.py b/lib/ansible/modules/network/openswitch/ops_command.py index acc01268821..b0354ba126c 100644 --- a/lib/ansible/modules/network/openswitch/ops_command.py +++ b/lib/ansible/modules/network/openswitch/ops_command.py @@ -131,7 +131,8 @@ def main(): queue = set() for entry in (module.params['waitfor'] or list()): queue.add(Conditional(entry)) - except AttributeError, exc: + except AttributeError: + exc = get_exception() module.fail_json(msg=exc.message) result = dict(changed=False)