summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clusterman/__main__.py6
-rw-r--r--clusterman/commands/node.py5
2 files changed, 8 insertions, 3 deletions
diff --git a/clusterman/__main__.py b/clusterman/__main__.py
index d22786b..be2ea22 100644
--- a/clusterman/__main__.py
+++ b/clusterman/__main__.py
@@ -20,6 +20,7 @@ def main():
node_cmd_list.add_argument("-g", "--group" ,help="Group to list")
# Exec
node_cmd_list=node_subparsers.add_parser("exec")
+ node_cmd_list.add_argument("-g", "--group" ,help="Group to run the command on")
node_cmd_list.add_argument("cmd",help="Command to run",nargs=argparse.REMAINDER)
##### Frontend commands #####
@@ -58,7 +59,10 @@ def main():
else:
node.ls()
elif args.command == "exec":
- node.exec(args.cmd)
+ if args.group:
+ node.exec(args.cmd,args.group)
+ else:
+ node.exec(args.cmd)
else:
target_node.print_help(sys.stderr)
sys.exit(1)
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index 6a32fb1..59fbdc5 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -83,10 +83,11 @@ def check(timeout):
else:
print("Error: Some of your nodes are not reachable")
-def exec(command):
+def exec(command, group=None):
user="root" if len(CONF["ssh"]["user"]) <= 0 else CONF["ssh"]["user"]
key_path=CONF["ssh"]["key_path"]
- for ip in get_node_list():
+ nodes=get_node_list() if group is None else get_node_in_group(group)
+ for ip in nodes:
print("----- Node {} -----".format(ip))
if len(key_path)>0:
output=subprocess.check_output(["ssh","-o", "StrictHostKeyChecking=no", "-i", CONF["ssh"]["key_path"],"{}@{}".format(user,ip), " ".join(command)])