mirror of
https://gitlab.com/manzerbredes/clusterman.git
synced 2025-04-05 11:36:25 +02:00
Minor changes
This commit is contained in:
parent
37ac5a14dd
commit
ade516e6f8
3 changed files with 29 additions and 26 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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" },
|
||||
|
|
Loading…
Add table
Reference in a new issue