summaryrefslogtreecommitdiff
path: root/clusterman/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'clusterman/utils.py')
-rw-r--r--clusterman/utils.py23
1 files changed, 22 insertions, 1 deletions
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