diff --git a/clusterman/__main__.py b/clusterman/__main__.py index 5496ba5..598ea7a 100644 --- a/clusterman/__main__.py +++ b/clusterman/__main__.py @@ -17,6 +17,7 @@ def main(): node_cmd_scan.add_argument("-t", "--timeout" ,help="Timeout", type=float) # List node_cmd_list=node_subparsers.add_parser("list") + node_cmd_list.add_argument("-g", "--group" ,help="Group to list") ##### Frontend commands ##### target_frontend = subparsers.add_parser("frontend") @@ -49,7 +50,10 @@ def main(): else: node.check(CONF["timeout"]) elif args.command == "list": - node.ls() + if args.group: + node.ls(args.group) + else: + node.ls() else: target_node.print_help(sys.stderr) sys.exit(1) diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py index a04b1a7..e949887 100644 --- a/clusterman/commands/node.py +++ b/clusterman/commands/node.py @@ -1,8 +1,8 @@ -import os, json, time +import os, json, time, re, sys from clusterman.config import CONF -def ls(): +def ls(group=None): nodes_path=CONF.NODE_FILE nodes=None if os.path.exists(nodes_path): @@ -11,8 +11,21 @@ def ls(): 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: - print(node) + if pattern is not None: + if pattern.match(node): + print(node) + else: + print(node) def scan(timeout): from_split=[int(n) for n in CONF["cluster"]["ip4_from"].split(".")] diff --git a/clusterman/config.py b/clusterman/config.py index 58dbdbc..c39c8c2 100644 --- a/clusterman/config.py +++ b/clusterman/config.py @@ -13,6 +13,9 @@ class Config: "ip4_from": "10.128.0.133", "ip4_to": "10.128.0.140", "ip4_ignore": ["10.0.0.5", "10.0.0.1"], + "groups": { + "all": "*" + } }, "plugins": { "ls": "ls -al" }, "timeout": 0.5, @@ -27,7 +30,8 @@ class Config: "cluster": {"type": "object", "properties":{ "ip4_from": {"type": "string"}, "ip4_to": {"type": "string"}, - "ip4_ignore": {"type": "array", "items":{"type": "string"}} + "ip4_ignore": {"type": "array", "items":{"type": "string"}}, + "groups": {"type": "object"} }} }, "required":[