Convert the network subfolder to py3/py2.4 syntax (#3690)

pull/18777/head
Michael Scherer 9 years ago committed by Matt Clay
parent 09066f1518
commit c0217e14a7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save