def exec_command(self, cmd, block = True):
"""Executes a command on the master node. If block is True, wait until command finishes and return stdout,
otherwise exit immediately and return (stdin, stdout, stderr)"""
if self.client == None:
self.client = ssh.SSHClient()
self.client.load_system_host_keys()
self.client.set_missing_host_key_policy(ssh.WarningPolicy)
self.client.connect(self.hostname, username = self.username)
self.exec_command('mkdir -p dsef')
(stdin, stdout, stderr) = self.client.exec_command("cd ~/{} && {}".format(self.dist_sys, cmd), get_pty = True)
if block:
return str(stdout.read(), 'ascii')
else:
return (stdin, stdout, stderr)
评论列表
文章目录