summaryrefslogtreecommitdiff
path: root/clusterman
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2023-10-26 14:24:02 +0200
committerLoic Guegan <loic.guegan@mailbox.org>2023-10-26 14:24:02 +0200
commitd79342a340c7025f675df45a180866b47e43fec7 (patch)
tree13b677f5634637abdac7e991f08bca1c2398b95a /clusterman
parent21a83cd9736a742645179d899488bd9db62e80c9 (diff)
Minor changes
Diffstat (limited to 'clusterman')
-rw-r--r--clusterman/__main__.py37
-rw-r--r--clusterman/commands/node.py6
-rw-r--r--clusterman/config.py3
3 files changed, 36 insertions, 10 deletions
diff --git a/clusterman/__main__.py b/clusterman/__main__.py
index 8f3c416..4980427 100644
--- a/clusterman/__main__.py
+++ b/clusterman/__main__.py
@@ -4,10 +4,22 @@ from clusterman.commands import node
def main():
parser = argparse.ArgumentParser()
- subparsers = parser.add_subparsers(dest="command", help='Target')
- cmd_node = subparsers.add_parser("node")
- cmd_frontend = subparsers.add_parser("frontend")
+ subparsers = parser.add_subparsers(dest="target", help='Target')
+
+ ##### Node commands #####
+ target_node = subparsers.add_parser("node")
+ node_subparsers=target_node.add_subparsers(dest="command", help='Command')
+ # Scan
+ node_cmd_scan=node_subparsers.add_parser("scan")
+ node_cmd_scan.add_argument("-t", "--timeout" ,help="Timeout", type=float)
+ # Check
+ node_cmd_scan=node_subparsers.add_parser("check")
+ node_cmd_scan.add_argument("-t", "--timeout" ,help="Timeout", type=float)
+
+ ##### Frontend commands #####
+ target_frontend = subparsers.add_parser("frontend")
+
# Check if command specified:
if len(sys.argv)==1:
parser.print_help(sys.stderr)
@@ -16,11 +28,24 @@ def main():
args = parser.parse_args()
# Run the proper handler
- if args.command == "node":
+ if args.target == "node":
print("Do node related stuff")
#node.scan("10.0.0.1","10.0.0.10")
- node.check()
- if args.command == "frontend":
+ if args.command == "scan":
+ if args.timeout:
+ node.scan(node_cmd_scan.timeout)
+ else:
+ node.scan(CONF["timeout"])
+ elif args.command == "check":
+ if args.timeout:
+ node.check(node_cmd_scan.timeout)
+ else:
+ node.check(CONF["timeout"])
+ else:
+ target_node.print_help(sys.stderr)
+ sys.exit(1)
+
+ if args.target == "frontend":
print("Do frontend related stuff")
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index b7dca60..54de67c 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -6,7 +6,7 @@ def ls():
print("List nodes..")
-def scan(ip4_from,ip4_to,timeout=0.1):
+def scan(timeout):
from_split=[int(n) for n in CONF["cluster"]["ip4_from"].split(".")]
to_split=[int(n) for n in CONF["cluster"]["ip4_to"].split(".")]
ignore_list=[ip.strip(" ") for ip in CONF["cluster"]["ip4_ignore"]]
@@ -30,7 +30,7 @@ def scan(ip4_from,ip4_to,timeout=0.1):
with open(CONF["paths"]["nodes"], "w") as f:
f.write(json.dumps(nodes))
-def check(timeout=0.1):
+def check(timeout):
nodes_path=CONF["paths"]["nodes"]
nodes=None
if os.path.exists(nodes_path):
@@ -51,6 +51,6 @@ def check(timeout=0.1):
print("=> Not responding!!")
if not fail:
- print("Succeed: All nodes are reachable")
+ print("Success: All nodes are reachable")
else:
print("Error: Some of your nodes are not reachable")
diff --git a/clusterman/config.py b/clusterman/config.py
index 72a8b2b..2a9b95b 100644
--- a/clusterman/config.py
+++ b/clusterman/config.py
@@ -13,7 +13,8 @@ class Config:
"ip4_from": "10.128.0.133",
"ip4_to": "10.128.0.140",
"ip4_ignore": ["10.0.0.5", "10.0.0.1"]
- }
+ },
+ "timeout": 0.5
}
def __init__(self):