summaryrefslogtreecommitdiff
path: root/clusterman
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2023-10-26 15:34:04 +0200
committerLoic Guegan <loic.guegan@mailbox.org>2023-10-26 15:34:04 +0200
commit068fba04843a8e1a9a96c13211f98a89c39100a5 (patch)
tree2a8488b82ff3cdfdab69c780dd4d07b8865b5c72 /clusterman
parent3e670642781b33825eee01f17cf79906e1e20897 (diff)
Minor changes
Diffstat (limited to 'clusterman')
-rw-r--r--clusterman/commands/node.py9
-rw-r--r--clusterman/config.py19
2 files changed, 19 insertions, 9 deletions
diff --git a/clusterman/commands/node.py b/clusterman/commands/node.py
index 280cb2e..a04b1a7 100644
--- a/clusterman/commands/node.py
+++ b/clusterman/commands/node.py
@@ -3,7 +3,7 @@ from clusterman.config import CONF
def ls():
- nodes_path=CONF["paths"]["nodes"]
+ nodes_path=CONF.NODE_FILE
nodes=None
if os.path.exists(nodes_path):
with open(nodes_path) as f:
@@ -14,7 +14,6 @@ def ls():
for node in nodes:
print(node)
-
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(".")]
@@ -36,13 +35,13 @@ def scan(timeout):
print("=> Found!!")
else:
print("")
- with open(CONF["paths"]["nodes"], "w") as f:
+ with open(CONF.NODE_FILE, "w") as f:
f.write(json.dumps(nodes,indent=4))
- CONF["cluster"]["last_scan"]=int(time.time())
+ CONF["cache"]["last_scan"]=int(time.time())
CONF.save()
def check(timeout):
- nodes_path=CONF["paths"]["nodes"]
+ nodes_path=CONF.NODE_FILE
nodes=None
if os.path.exists(nodes_path):
with open(nodes_path) as f:
diff --git a/clusterman/config.py b/clusterman/config.py
index db63778..804a2cc 100644
--- a/clusterman/config.py
+++ b/clusterman/config.py
@@ -5,22 +5,22 @@ import os, json
class Config:
CONF_DIR=os.path.join(os.environ['HOME'],".clusterman/")
CONF_FILE=os.path.join(CONF_DIR,"clusterman.json")
+ CACHE_FILE=os.path.join(CONF_DIR,"cache.json")
+ NODE_FILE=os.path.join(CONF_DIR,"nodeslist.json")
DEFAULT_CONFIG = {
- "paths": {
- "nodes": os.path.join(CONF_DIR,"nodeslist.json")
- },
"cluster": {
"ip4_from": "10.128.0.133",
"ip4_to": "10.128.0.140",
"ip4_ignore": ["10.0.0.5", "10.0.0.1"],
- "last_scan": None
},
+ "plugins": [],
"timeout": 0.5
}
def __init__(self):
Path(self.CONF_DIR).mkdir(parents=True, exist_ok=True)
self.config=self.DEFAULT_CONFIG
+ self.cache=dict()
self.load()
def load(self):
@@ -29,12 +29,23 @@ class Config:
self.config=json.load(f)
else:
self.save()
+
+ if os.path.exists(self.CACHE_FILE):
+ with open(self.CACHE_FILE) as f:
+ self.cache=json.load(f)
+ else:
+ self.save()
def save(self):
with open(self.CONF_FILE, "w") as f:
f.write(json.dumps(self.config,indent=4, sort_keys=True))
+ with open(self.CACHE_FILE, "w") as f:
+ f.write(json.dumps(self.cache,indent=4, sort_keys=True))
+
def __getitem__(self, key):
+ if key=="cache":
+ return self.cache;
return self.config[key]
def __setitem__(self, key, value):