108
108
"""Execute raw shell script (as rendered from a template).
110
110
:param commands: String containing shell script.
111
:returns: Standard output and standard error returned by the execution
111
:return: Standard output and standard error returned by the execution
112
112
of the shell script.
113
113
:raises: :class:`PowerActionFail`
115
115
# This might need retrying but it could be better to leave that
116
116
# to the individual scripts.
118
output = subprocess.check_output(
119
commands, shell=True, stderr=subprocess.STDOUT, close_fds=True)
120
except subprocess.CalledProcessError as e:
121
raise PowerActionFail.from_action(self, e)
122
return output.strip()
118
process = subprocess.Popen(
119
shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
120
stderr=subprocess.STDOUT, close_fds=True)
121
output, _ = process.communicate(commands)
122
if process.wait() == 0:
123
return output.strip()
125
raise PowerActionFail.from_action(
126
self, subprocess.CalledProcessError(
127
process.returncode, shell, output))
124
129
def execute(self, **context):
125
130
"""Execute the template.
127
:returns: Standard output and standard error returned by the execution
132
:return: Standard output and standard error returned by the execution
130
135
Any supplied parameters will be passed to the template as substitution