add remove function
This commit is contained in:
parent
9013c32862
commit
67824caafb
24
o_manager.py
24
o_manager.py
@ -84,6 +84,23 @@ class OManager:
|
||||
instance["weight"] = 0
|
||||
self.reset_lb()
|
||||
|
||||
def remove_op(self, idx):
|
||||
instance = self.get_instance(idx)
|
||||
if not instance:
|
||||
return
|
||||
instance["op"].stop()
|
||||
instance["weight"] = 0
|
||||
self.instances.remove(instance)
|
||||
self.reset_lb()
|
||||
|
||||
def remove_all_op(self):
|
||||
for instance in self.instances:
|
||||
instance["op"].stop()
|
||||
instance["weight"] = 0
|
||||
self.instances = []
|
||||
self.new_idx = 0
|
||||
self.reset_lb()
|
||||
|
||||
def start_all(self):
|
||||
for instance in self.instances:
|
||||
instance["op"].start()
|
||||
@ -132,6 +149,7 @@ class OManager:
|
||||
ping_stat = i["op"].get_ping_stat(lines=max(n_up, n_down))
|
||||
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
|
||||
#print("ping status:", ping_stat)
|
||||
|
||||
def all_equal(n, status):
|
||||
for j in range(min(n, len(ping_stat))):
|
||||
if ping_stat[-(j+1)] != status:
|
||||
@ -140,10 +158,10 @@ class OManager:
|
||||
# all up
|
||||
if all_equal(n_up, True):
|
||||
i["weight"] = 1
|
||||
#print("all_up")
|
||||
# print("all_up")
|
||||
if all_equal(n_down, False):
|
||||
i["weight"] = 0
|
||||
#print("all_down")
|
||||
# print("all_down")
|
||||
weights.append(i["weight"])
|
||||
return weights
|
||||
|
||||
@ -163,7 +181,7 @@ class OManager:
|
||||
os.kill(self.PID, signal.SIGUSR1)
|
||||
except:
|
||||
print("error applying weights")
|
||||
#else:
|
||||
# else:
|
||||
#print("weight not changed, weights:", new_weights)
|
||||
|
||||
async def run_cmd(self, cmd):
|
||||
|
||||
16
test.py
16
test.py
@ -73,7 +73,7 @@ class StartInstatnceHandler(tornado.web.RequestHandler):
|
||||
self.write("start all")
|
||||
|
||||
|
||||
class StopAll(tornado.web.RequestHandler):
|
||||
class StopInstatnceHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
idx = self.get_query_argument("i", None)
|
||||
if idx != None:
|
||||
@ -84,13 +84,25 @@ class StopAll(tornado.web.RequestHandler):
|
||||
self.write("stop all")
|
||||
|
||||
|
||||
class RemoveInstatnceHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
idx = self.get_query_argument("i", None)
|
||||
if idx != None:
|
||||
om.remove_op(int(idx))
|
||||
self.write("remove sucess!")
|
||||
else:
|
||||
om.remove_all_op()
|
||||
self.write("remove all")
|
||||
|
||||
|
||||
def make_app():
|
||||
return tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/select", ConfigsHandeler),
|
||||
(r"/create", CreateInstantceHandler),
|
||||
(r"/start", StartInstatnceHandler),
|
||||
(r"/stop", StopAll)
|
||||
(r"/stop", StopInstatnceHandler),
|
||||
(r"/remove", RemoveInstatnceHandler),
|
||||
])
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user