From f741c9863db3acbe5f35b14ba2195537c9674731 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 26 Oct 2023 16:57:30 +0200 Subject: [PATCH] Minor changes --- clusterman/__main__.py | 13 ++++++++++--- clusterman/commands/frontend.py | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 clusterman/commands/frontend.py diff --git a/clusterman/__main__.py b/clusterman/__main__.py index 35953b4..5496ba5 100644 --- a/clusterman/__main__.py +++ b/clusterman/__main__.py @@ -1,6 +1,6 @@ import argparse,sys from clusterman.config import * -from clusterman.commands import node, plugins +from clusterman.commands import node, plugins, frontend def main(): parser = argparse.ArgumentParser() @@ -20,7 +20,10 @@ def main(): ##### Frontend commands ##### target_frontend = subparsers.add_parser("frontend") - + frontend_subparsers=target_frontend.add_subparsers(dest="command", help='Command') + # Info + node_cmd_scan=frontend_subparsers.add_parser("info") + ##### Plugins commands ##### target_plugins = subparsers.add_parser("plugins") target_plugins.add_argument("name", help="Plugin's name") @@ -51,7 +54,11 @@ def main(): target_node.print_help(sys.stderr) sys.exit(1) elif args.target == "frontend": - print("Do frontend related stuff") + if args.command == "info": + frontend.info() + else: + target_frontend.print_help(sys.stderr) + sys.exit(1) elif args.target == "plugins": plugins.execute(args.name,args.parameters) diff --git a/clusterman/commands/frontend.py b/clusterman/commands/frontend.py new file mode 100644 index 0000000..bcd4ab7 --- /dev/null +++ b/clusterman/commands/frontend.py @@ -0,0 +1,25 @@ +import os, json +from clusterman.config import CONF + + + + +def info(): + nodes=None + if os.path.exists(CONF.NODE_FILE): + with open(CONF.NODE_FILE) as f: + nodes=json.load(f) + + cache=None + if os.path.exists(CONF.CACHE_FILE): + with open(CONF.CACHE_FILE) as f: + cache=json.load(f) + + # Node + print("Node count: ",end="") + print("NA") if nodes==None else print(len(nodes)) + + # Cache + print("Last node scan: ",end="") + if cache!=None and "last_scan" in CONF["cache"]: + print(CONF["cache"]["last_scan"])