summaryrefslogtreecommitdiff
path: root/clusterman/utils.py
blob: ad79bd23ebc9f6f026b3ce34a5d9159be4b5d637 (plain)
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")