summaryrefslogtreecommitdiff
path: root/clusterman/commands/frontend.py
blob: bb930cb88ad83af8caf0f91713330199dff28121 (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
39
40
41
42
43
44
45
46
47
48
49
import os, json, re
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))

    # Groups
    print("Node groups: ",end="")
    if len(CONF["cluster"]["groups"]) > 0:
        pattern=None
        for group in CONF["cluster"]["groups"].keys():
            if not pattern == None:
                print(", ", end="")
            pattern = re.compile(CONF["cluster"]["groups"][group])
            count=0
            if not nodes == None:
                for ip in nodes:
                    if pattern.match(ip):
                        count=count+1
            print("{}({})".format(group,count),end="")
        print()
    else:
        print("NA")

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

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