bug fixes
This commit is contained in:
parent
25c4218ff6
commit
98dc22aeda
15
o_manager.py
15
o_manager.py
@ -120,6 +120,7 @@ class OManager:
|
|||||||
print("lb_cmd", lb_cmd)
|
print("lb_cmd", lb_cmd)
|
||||||
self.run_task.append(self.loop.create_task(
|
self.run_task.append(self.loop.create_task(
|
||||||
self.run_cmd(lb_cmd)))
|
self.run_cmd(lb_cmd)))
|
||||||
|
#print("pre calc weights:", self.calc_weights())
|
||||||
self.run_task.append(self.loop.create_task(
|
self.run_task.append(self.loop.create_task(
|
||||||
self.keep_applying_weights()))
|
self.keep_applying_weights()))
|
||||||
|
|
||||||
@ -131,25 +132,32 @@ class OManager:
|
|||||||
ping_stat = i["op"].get_ping_stat(
|
ping_stat = i["op"].get_ping_stat(
|
||||||
).splitlines()[-max(n_up, n_down):]
|
).splitlines()[-max(n_up, n_down):]
|
||||||
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
|
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
|
||||||
|
print("ping status:", ping_stat)
|
||||||
def all_equal(n, status):
|
def all_equal(n, status):
|
||||||
for j in range(n):
|
for j in range(min(n, len(ping_stat))):
|
||||||
if ping_stat[-j] != status:
|
if ping_stat[-(j+1)] != status:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
# all up
|
# all up
|
||||||
if all_equal(n_up, True):
|
if all_equal(n_up, True):
|
||||||
i["weight"] = 1
|
i["weight"] = 1
|
||||||
|
print("all_up")
|
||||||
if all_equal(n_down, False):
|
if all_equal(n_down, False):
|
||||||
i["weight"] = 0
|
i["weight"] = 0
|
||||||
|
print("all_down")
|
||||||
|
|
||||||
weights.append(i["weight"])
|
weights.append(i["weight"])
|
||||||
return weights
|
return weights
|
||||||
|
|
||||||
async def keep_applying_weights(self):
|
async def keep_applying_weights(self):
|
||||||
old_weights = []
|
old_weights = []
|
||||||
while True:
|
while True:
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
print("calculating weights")
|
||||||
new_weights = self.calc_weights()
|
new_weights = self.calc_weights()
|
||||||
|
print("finished calc")
|
||||||
if old_weights != new_weights:
|
if old_weights != new_weights:
|
||||||
|
old_weights = new_weights
|
||||||
print("weight changed, new weights:", new_weights)
|
print("weight changed, new weights:", new_weights)
|
||||||
try:
|
try:
|
||||||
self.generate_dynamic_weight(
|
self.generate_dynamic_weight(
|
||||||
@ -159,7 +167,6 @@ class OManager:
|
|||||||
print("error applying weights")
|
print("error applying weights")
|
||||||
else:
|
else:
|
||||||
print("weight not changed, weights:", new_weights)
|
print("weight not changed, weights:", new_weights)
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
async def run_cmd(self, cmd):
|
async def run_cmd(self, cmd):
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user