summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-10-29 09:37:06 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-10-29 09:37:06 +0100
commite34fc73d5518bcd8acb7b86a16c0cd9e253393b7 (patch)
tree0827f5985416df87e21b179853fd0d14fa7ba8d9
parent38019cabe817fe0d771391d68b76dcf565c0faaf (diff)
Minor changes
-rw-r--r--clusterman/commands/node.py10
-rw-r--r--clusterman/utils.py13
2 files changed, 15 insertions, 8 deletions
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index 9c7be5f..24e37ba 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -1,5 +1,6 @@
import os, json, time, re, sys, subprocess
from clusterman.config import CONF
+from clusterman.utils import ssh_exec
def get_node_list():
nodes_path=CONF.NODE_FILE
@@ -84,15 +85,8 @@ def check(timeout):
print("Error: Some of your nodes are not reachable")
def exec(command, group=None):
- user="root" if len(CONF["ssh"]["user"]) <= 0 else CONF["ssh"]["user"]
- key_path=CONF["ssh"]["key_path"]
nodes=get_node_list() if group is None else get_node_in_group(group)
for ip in nodes:
print("----- Node {} -----".format(ip))
- if len(key_path)>0:
- output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-i", CONF["ssh"]["key_path"],"{}@{}".format(user,ip), " ".join(command)])
- print(output.decode("utf-8"),end="")
- else:
- output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "{}@{}".format(user,ip), " ".join(command)])
- print(output.decode("utf-8"),end="")
+ print(ssh_exec(ip," ".join(command)))
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")
+