Minor changes

This commit is contained in:
Loïc Guégan 2023-11-20 18:57:52 +01:00
parent 9d1fe3b046
commit a4d3e71342
3 changed files with 8 additions and 8 deletions

View file

@ -1,10 +1,10 @@
import os, json, re import os, json, re
from datetime import datetime from datetime import datetime
from clusterman.config import CONF from clusterman.config import CONF
import clusterman.commands.node as node import clusterman.utils as utils
def info(): def info():
nodes=node.get_node_list() nodes=utils.get_node_list()
cache=None cache=None
if os.path.exists(CONF.CACHE_FILE): if os.path.exists(CONF.CACHE_FILE):
with open(CONF.CACHE_FILE) as f: with open(CONF.CACHE_FILE) as f:
@ -18,7 +18,7 @@ def info():
if len(CONF["cluster"]["groups"]) > 0: if len(CONF["cluster"]["groups"]) > 0:
content=list() content=list()
for group in CONF["cluster"]["groups"].keys(): for group in CONF["cluster"]["groups"].keys():
content.append("{}({})".format(group,len(node.get_node_in_group(group)))) content.append("{}({})".format(group,len(utils.get_node_in_group(group))))
print(", ".join(content)) print(", ".join(content))
else: else:
print("NA") print("NA")

View file

@ -1,6 +1,6 @@
import os, json, time, re, sys, subprocess import os, json, time, re, sys, subprocess
from clusterman.config import CONF from clusterman.config import CONF
import clusterman.utils as utils import clusterman.utils as utils
def ls(group=None): def ls(group=None):
@ -61,7 +61,7 @@ def check(timeout):
print("Error: Some of your nodes are not reachable") print("Error: Some of your nodes are not reachable")
def exec(command, group=None): def exec(command, group=None):
nodes=utils.get_node_list() if group is None else get_node_in_group(group) nodes=utils.get_node_list() if group is None else utils.get_node_in_group(group)
for ip in nodes: for ip in nodes:
print("----- Node {} -----".format(ip)) print("----- Node {} -----".format(ip))
print(utils.ssh_exec(ip," ".join(command))) print(utils.ssh_exec(ip," ".join(command)))

6
clusterman/utils.py Normal file → Executable file
View file

@ -1,14 +1,14 @@
import subprocess, os, json import subprocess, os, json, re
from clusterman.config import CONF from clusterman.config import CONF
def ssh_exec(host,command,use_key=True): def ssh_exec(host,command,use_key=True):
user="root" if len(CONF["ssh"]["user"]) <= 0 else CONF["ssh"]["user"] user="root" if len(CONF["ssh"]["user"]) <= 0 else CONF["ssh"]["user"]
key_path=CONF["ssh"]["key_path"] key_path=CONF["ssh"]["key_path"]
if use_key: if use_key:
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-i", CONF["ssh"]["key_path"],"{}@{}".format(user,ip), command]) output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-i", CONF["ssh"]["key_path"],"{}@{}".format(user,host), command])
return output.decode("utf-8") return output.decode("utf-8")
else: else:
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "{}@{}".format(user,ip), command]) output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "{}@{}".format(user,host), command])
return output.decode("utf-8") return output.decode("utf-8")
def ping_test(host, timeout=None): def ping_test(host, timeout=None):