def execute(self, command):
assert self.ssh is not None
environment = " ".join("{}='{}'".format(k, v) for k, v in os.environ.items()
if k.startswith("POSTGRES"))
env_command = "{} {}".format(environment, command)
LOG.debug("Executing command: %s", env_command)
stdout_content = None
stderr_content = None
try:
_, stdout, stderr = self.ssh.exec_command(env_command)
exit_status = stdout.channel.recv_exit_status()
if exit_status != 0:
raise paramiko.SSHException("'%s' failed with exit status %d", command, exit_status)
stdout_content = stdout.read()
stderr_content = stderr.read()
except paramiko.SSHException as e:
LOG.error("Unable to excute command '%s' on host: %s", command, e)
LOG.debug("stdout: %s", stdout.read())
LOG.debug("stderr: %s", stderr.read())
raise e
return stdout_content, stderr_content
评论列表
文章目录