mirror of
https://gitlab.com/manzerbredes/clusterman.git
synced 2025-04-18 03:42:07 +00:00
Minor changes
This commit is contained in:
parent
77ea2f3ee6
commit
b2835c72a3
3 changed files with 39 additions and 6 deletions
|
@ -18,7 +18,8 @@ def main():
|
||||||
# Run the proper handler
|
# Run the proper handler
|
||||||
if args.command == "node":
|
if args.command == "node":
|
||||||
print("Do node related stuff")
|
print("Do node related stuff")
|
||||||
node.scan("10.0.0.1","10.0.0.10")
|
#node.scan("10.0.0.1","10.0.0.10")
|
||||||
|
node.check()
|
||||||
if args.command == "frontend":
|
if args.command == "frontend":
|
||||||
print("Do frontend related stuff")
|
print("Do frontend related stuff")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os, json
|
||||||
|
from clusterman.config import CONF
|
||||||
|
|
||||||
|
|
||||||
def ls():
|
def ls():
|
||||||
|
@ -7,8 +7,9 @@ def ls():
|
||||||
|
|
||||||
|
|
||||||
def scan(ip4_from,ip4_to,timeout=0.1):
|
def scan(ip4_from,ip4_to,timeout=0.1):
|
||||||
from_split=[int(n) for n in ip4_from.split(".")]
|
from_split=[int(n) for n in CONF["cluster"]["ip4_from"].split(".")]
|
||||||
to_split=[int(n) for n in ip4_to.split(".")]
|
to_split=[int(n) for n in CONF["cluster"]["ip4_to"].split(".")]
|
||||||
|
ignore_list=[ip.strip(" ") for ip in CONF["cluster"]["ip4_ignore"]]
|
||||||
nodes=list()
|
nodes=list()
|
||||||
print("----- Starting node scan (timeout={}s) -----".format(timeout))
|
print("----- Starting node scan (timeout={}s) -----".format(timeout))
|
||||||
for W in range(from_split[0],to_split[0]+1):
|
for W in range(from_split[0],to_split[0]+1):
|
||||||
|
@ -16,11 +17,37 @@ def scan(ip4_from,ip4_to,timeout=0.1):
|
||||||
for Y in range(from_split[2],to_split[2]+1):
|
for Y in range(from_split[2],to_split[2]+1):
|
||||||
for Z in range(from_split[3],to_split[3]+1):
|
for Z in range(from_split[3],to_split[3]+1):
|
||||||
ip="{}.{}.{}.{}".format(W,X,Y,Z)
|
ip="{}.{}.{}.{}".format(W,X,Y,Z)
|
||||||
|
if ip in ignore_list:
|
||||||
|
print("Skipping {}".format(ip))
|
||||||
|
continue
|
||||||
response = os.system("ping -c 1 -W " + str(timeout)+ " " + ip + " &>/dev/null")
|
response = os.system("ping -c 1 -W " + str(timeout)+ " " + ip + " &>/dev/null")
|
||||||
print("Contacting {}...".format(ip),end='')
|
print("Contacting {}...".format(ip),end='')
|
||||||
if response==0:
|
if response==0:
|
||||||
nodes.append()
|
nodes.append(ip)
|
||||||
print("=> Found!!")
|
print("=> Found!!")
|
||||||
else:
|
else:
|
||||||
print("")
|
print("")
|
||||||
|
with open(CONF["paths"]["nodes"], "w") as f:
|
||||||
|
f.write(json.dumps(nodes))
|
||||||
|
|
||||||
|
def check(timeout=0.1):
|
||||||
|
nodes_path=CONF["paths"]["nodes"]
|
||||||
|
nodes=None
|
||||||
|
if os.path.exists(nodes_path):
|
||||||
|
with open(nodes_path) as f:
|
||||||
|
nodes=json.load(f)
|
||||||
|
if not nodes == None:
|
||||||
|
fail=False
|
||||||
|
for ip in nodes:
|
||||||
|
print("Contacting {}...".format(ip),end='')
|
||||||
|
response = os.system("ping -c 1 -W " + str(timeout)+ " " + ip + " &>/dev/null")
|
||||||
|
if response == 0:
|
||||||
|
print("")
|
||||||
|
else:
|
||||||
|
fail=True
|
||||||
|
print("=> Not responding!!")
|
||||||
|
|
||||||
|
if not fail:
|
||||||
|
print("Succeed: All nodes are reachable")
|
||||||
|
else:
|
||||||
|
print("Error: Some of your nodes are not reachable")
|
||||||
|
|
|
@ -8,6 +8,11 @@ class Config:
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
"paths": {
|
"paths": {
|
||||||
"nodes": os.path.join(CONF_DIR,"nodeslist.json")
|
"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"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue