summaryrefslogtreecommitdiff
path: root/clusterman/commands/node.py
diff options
context:
space:
mode:
Diffstat (limited to 'clusterman/commands/node.py')
-rw-r--r--clusterman/commands/node.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index f57f743..ddadc49 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -1,16 +1,20 @@
import os, json, time, re, sys, subprocess
from clusterman.config import CONF
-
-def get_node_in_group(group):
+def get_node_list():
nodes_path=CONF.NODE_FILE
- nodes=None
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 nodes is not None and group in CONF["cluster"]["groups"]:
+ 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:
@@ -18,16 +22,11 @@ def get_node_in_group(group):
ingroup.append(node)
break;
return ingroup
-
-
def ls(group=None):
nodes_path=CONF.NODE_FILE
- nodes=None
- if os.path.exists(nodes_path):
- with open(nodes_path) as f:
- nodes=json.load(f)
- else:
+ nodes=get_node_list()
+ if len(nodes)<=0:
print("Please perform a scan before")
exit(0)
# Print nodes
@@ -88,3 +87,9 @@ def check(timeout):
print("Success: All nodes are reachable")
else:
print("Error: Some of your nodes are not reachable")
+
+def exec(command):
+ print(["ssh", "-i", CONF["ssh_key_path"], command])
+ for ip in get_node_list():
+ print("----- Node {} -----".format(ip))
+ subprocess.run(["ssh", "-i", CONF["ssh_key_path"],"root@"+ip, " ".join(command)])