add remove function
This commit is contained in:
parent
9013c32862
commit
67824caafb
18
o_manager.py
18
o_manager.py
@ -84,6 +84,23 @@ class OManager:
|
|||||||
instance["weight"] = 0
|
instance["weight"] = 0
|
||||||
self.reset_lb()
|
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):
|
def start_all(self):
|
||||||
for instance in self.instances:
|
for instance in self.instances:
|
||||||
instance["op"].start()
|
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["op"].get_ping_stat(lines=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)
|
#print("ping status:", ping_stat)
|
||||||
|
|
||||||
def all_equal(n, status):
|
def all_equal(n, status):
|
||||||
for j in range(min(n, len(ping_stat))):
|
for j in range(min(n, len(ping_stat))):
|
||||||
if ping_stat[-(j+1)] != status:
|
if ping_stat[-(j+1)] != status:
|
||||||
|
|||||||
16
test.py
16
test.py
@ -73,7 +73,7 @@ class StartInstatnceHandler(tornado.web.RequestHandler):
|
|||||||
self.write("start all")
|
self.write("start all")
|
||||||
|
|
||||||
|
|
||||||
class StopAll(tornado.web.RequestHandler):
|
class StopInstatnceHandler(tornado.web.RequestHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
idx = self.get_query_argument("i", None)
|
idx = self.get_query_argument("i", None)
|
||||||
if idx != None:
|
if idx != None:
|
||||||
@ -84,13 +84,25 @@ class StopAll(tornado.web.RequestHandler):
|
|||||||
self.write("stop all")
|
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():
|
def make_app():
|
||||||
return tornado.web.Application([
|
return tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/select", ConfigsHandeler),
|
(r"/select", ConfigsHandeler),
|
||||||
(r"/create", CreateInstantceHandler),
|
(r"/create", CreateInstantceHandler),
|
||||||
(r"/start", StartInstatnceHandler),
|
(r"/start", StartInstatnceHandler),
|
||||||
(r"/stop", StopAll)
|
(r"/stop", StopInstatnceHandler),
|
||||||
|
(r"/remove", RemoveInstatnceHandler),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user