1
2
3
4
5
6
7
8
9
10
11
12
13
|
import subprocess
from clusterman.config import CONF
def ssh_exec(host,command,use_key=True):
user="root" if len(CONF["ssh"]["user"]) <= 0 else CONF["ssh"]["user"]
key_path=CONF["ssh"]["key_path"]
if use_key:
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-i", CONF["ssh"]["key_path"],"{}@{}".format(user,ip), command])
return output.decode("utf-8")
else:
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "{}@{}".format(user,ip), command])
return output.decode("utf-8")
|