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
|
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:
|
||||||
@ -140,10 +158,10 @@ class OManager:
|
|||||||
# 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")
|
# print("all_up")
|
||||||
if all_equal(n_down, False):
|
if all_equal(n_down, False):
|
||||||
i["weight"] = 0
|
i["weight"] = 0
|
||||||
#print("all_down")
|
# print("all_down")
|
||||||
weights.append(i["weight"])
|
weights.append(i["weight"])
|
||||||
return weights
|
return weights
|
||||||
|
|
||||||
@ -163,7 +181,7 @@ class OManager:
|
|||||||
os.kill(self.PID, signal.SIGUSR1)
|
os.kill(self.PID, signal.SIGUSR1)
|
||||||
except:
|
except:
|
||||||
print("error applying weights")
|
print("error applying weights")
|
||||||
#else:
|
# else:
|
||||||
#print("weight not changed, weights:", new_weights)
|
#print("weight not changed, weights:", new_weights)
|
||||||
|
|
||||||
async def run_cmd(self, cmd):
|
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")
|
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