summaryrefslogtreecommitdiff
path: root/clusterman/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'clusterman/utils.py')
-rw-r--r--clusterman/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/clusterman/utils.py b/clusterman/utils.py
new file mode 100644
index 0000000..ad79bd2
--- /dev/null
+++ b/clusterman/utils.py
@@ -0,0 +1,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")
+