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.py33
1 files changed, 6 insertions, 27 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)))