summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2023-10-27 10:56:14 +0200
committerLoic Guegan <loic.guegan@mailbox.org>2023-10-27 10:56:14 +0200
commitade516e6f80f5648594889acc9f32afb80b5f704 (patch)
tree20e9272c3ed1338fcf0cd6aa7723b7cfabea0166
parent37ac5a14dda2def4851122898ba3fd9acd690249 (diff)
Minor changes
-rw-r--r--clusterman/commands/frontend.py16
-rw-r--r--clusterman/commands/node.py37
-rw-r--r--clusterman/config.py2
3 files changed, 29 insertions, 26 deletions
diff --git a/clusterman/commands/frontend.py b/clusterman/commands/frontend.py
index bb930cb..f275827 100644
--- a/clusterman/commands/frontend.py
+++ b/clusterman/commands/frontend.py
@@ -1,6 +1,6 @@
import os, json, re
from clusterman.config import CONF
-
+from clusterman.commands.node import get_node_in_group
def info():
nodes=None
@@ -20,18 +20,10 @@ def info():
# Groups
print("Node groups: ",end="")
if len(CONF["cluster"]["groups"]) > 0:
- pattern=None
+ content=list()
for group in CONF["cluster"]["groups"].keys():
- if not pattern == None:
- print(", ", end="")
- pattern = re.compile(CONF["cluster"]["groups"][group])
- count=0
- if not nodes == None:
- for ip in nodes:
- if pattern.match(ip):
- count=count+1
- print("{}({})".format(group,count),end="")
- print()
+ content.append("{}({})".format(group,len(get_node_in_group(group))))
+ print(", ".join(content))
else:
print("NA")
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index e949887..24759f0 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -2,6 +2,25 @@ import os, json, time, re, sys
from clusterman.config import CONF
+def get_node_in_group(group):
+ nodes_path=CONF.NODE_FILE
+ nodes=None
+ if os.path.exists(nodes_path):
+ with open(nodes_path) as f:
+ nodes=json.load(f)
+ # Search
+ ingroup=list()
+ if nodes is not None 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=None
@@ -11,20 +30,12 @@ def ls(group=None):
else:
print("Please perform a scan before")
exit(0)
- # Setup group pattern
- pattern=None
- if group is not None:
- if group in CONF["cluster"]["groups"]:
- pattern = re.compile(CONF["cluster"]["groups"][group])
- else:
- print("Group {} not found".format(group))
- sys.exit(1)
# Print nodes
- for node in nodes:
- if pattern is not None:
- if pattern.match(node):
- print(node)
- else:
+ if group is not None:
+ for node in get_node_in_group(group):
+ print(node)
+ else:
+ for node in nodes:
print(node)
def scan(timeout):
diff --git a/clusterman/config.py b/clusterman/config.py
index c39c8c2..b70dc16 100644
--- a/clusterman/config.py
+++ b/clusterman/config.py
@@ -14,7 +14,7 @@ class Config:
"ip4_to": "10.128.0.140",
"ip4_ignore": ["10.0.0.5", "10.0.0.1"],
"groups": {
- "all": "*"
+ "all": [".*"]
}
},
"plugins": { "ls": "ls -al" },