summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-10-29 09:40:33 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-10-29 09:40:33 +0100
commitf4da1431425bb83e14f199ddd06896165182a0df (patch)
tree4f89293650005479e35bb1e63bf512a2ae6d815b
parente34fc73d5518bcd8acb7b86a16c0cd9e253393b7 (diff)
Minor changes
-rw-r--r--clusterman/commands/node.py33
-rw-r--r--clusterman/utils.py23
2 files changed, 28 insertions, 28 deletions
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index 24e37ba..4d7b762 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -1,38 +1,17 @@
import os, json, time, re, sys, subprocess
from clusterman.config import CONF
-from clusterman.utils import ssh_exec
+import clusterman.utils as utils
-def get_node_list():
- nodes_path=CONF.NODE_FILE
- if os.path.exists(nodes_path):
- with open(nodes_path) as f:
- nodes=json.load(f)
- return nodes
- return list()
-
-
-def get_node_in_group(group):
- nodes=get_node_list()
- # Search
- ingroup=list()
- if len(nodes) > 0 and group in CONF["cluster"]["groups"]:
- patterns=[re.compile(pattern) for pattern in CONF["cluster"]["groups"][group]]
- for node in nodes:
- for pattern in patterns:
- if pattern.match(node):
- ingroup.append(node)
- break;
- return ingroup
def ls(group=None):
nodes_path=CONF.NODE_FILE
- nodes=get_node_list()
+ nodes=utils.get_node_list()
if len(nodes)<=0:
print("Please perform a scan before")
exit(0)
# Print nodes
if group is not None:
- for node in get_node_in_group(group):
+ for node in utils.get_node_in_group(group):
print(node)
else:
for node in nodes:
@@ -65,7 +44,7 @@ def scan(timeout):
CONF.save()
def check(timeout):
- nodes=get_node_list()
+ nodes=utils.get_node_list()
if len(nodes) <= 0:
print("Please perform a scan before")
exit(0)
@@ -85,8 +64,8 @@ def check(timeout):
print("Error: Some of your nodes are not reachable")
def exec(command, group=None):
- nodes=get_node_list() if group is None else get_node_in_group(group)
+ nodes=utils.get_node_list() if group is None else get_node_in_group(group)
for ip in nodes:
print("----- Node {} -----".format(ip))
- print(ssh_exec(ip," ".join(command)))
+ print(utils.ssh_exec(ip," ".join(command)))
diff --git a/clusterman/utils.py b/clusterman/utils.py
index ad79bd2..36822fe 100644
--- a/clusterman/utils.py
+++ b/clusterman/utils.py
@@ -1,4 +1,4 @@
-import subprocess
+import subprocess, os, json
from clusterman.config import CONF
def ssh_exec(host,command,use_key=True):
@@ -11,3 +11,24 @@ def ssh_exec(host,command,use_key=True):
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "{}@{}".format(user,ip), command])
return output.decode("utf-8")
+
+def get_node_list():
+ nodes_path=CONF.NODE_FILE
+ if os.path.exists(nodes_path):
+ with open(nodes_path) as f:
+ nodes=json.load(f)
+ return nodes
+ return list()
+
+def get_node_in_group(group):
+ nodes=get_node_list()
+ # Search
+ ingroup=list()
+ if len(nodes) > 0 and group in CONF["cluster"]["groups"]:
+ patterns=[re.compile(pattern) for pattern in CONF["cluster"]["groups"][group]]
+ for node in nodes:
+ for pattern in patterns:
+ if pattern.match(node):
+ ingroup.append(node)
+ break;
+ return ingroup