def run_script(script_filename, *script_params, **environment_variables):
"""uploads a script for SCRIPTS_PATH and executes it in the /tmp dir with given params.
ASSUMES YOU ARE CONNECTED TO A STACK"""
start = datetime.now()
remote_script = _put_temporary_script(script_filename)
def escape_string_parameter(parameter):
return "'%s'" % parameter
env_string = ['%s=%s' % (k, v) for k, v in environment_variables.items()]
cmd = ["/bin/bash", remote_script] + map(escape_string_parameter, list(script_params))
retval = sudo(" ".join(env_string + cmd))
sudo("rm " + remote_script) # remove the script after executing it
end = datetime.now()
LOG.info("Executed script %s in %2.4f seconds", script_filename, (end - start).total_seconds())
return retval
评论列表
文章目录