summaryrefslogtreecommitdiff
path: root/clusterman/commands/frontend.py
blob: 4d7ecc4ab91475016ea632055ad92efc95958678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os, json, re
from datetime import datetime
from clusterman.config import CONF
import clusterman.commands.node as node

def info():
    nodes=node.get_node_list()
    cache=None
    if os.path.exists(CONF.CACHE_FILE):
        with open(CONF.CACHE_FILE) as f:
            cache=json.load(f)

    # Node 
    print("Node count: "+str(len(nodes)))

    # Groups
    print("Node groups: ",end="")
    if len(CONF["cluster"]["groups"]) > 0:
        content=list()
        for group in CONF["cluster"]["groups"].keys():
            content.append("{}({})".format(group,len(node.get_node_in_group(group))))
        print(", ".join(content))
    else:
        print("NA")

    
    # Cache
    print("Last node scan: ",end="")
    if cache!=None and "last_scan" in CONF["cache"]:
        dt=datetime.fromtimestamp(int(CONF["cache"]["last_scan"]), tz=None)
        print(dt)
    else:
        print("NA")

    # Plugins
    print("Plugins list:")
    for name in CONF["plugins"]:
        print("  "+name+":\t"+CONF["plugins"][name])