add users' locks to port_mapping

This commit is contained in:
zhuyj17 2018-01-21 22:57:29 +08:00
parent 5877440f3a
commit 63d5f01d8c
1 changed files with 11 additions and 1 deletions

View File

@ -294,16 +294,20 @@ def list_cluster(user, beans, form):
@auth_key_required @auth_key_required
def stopall_cluster(): def stopall_cluster():
global G_vclustermgr global G_vclustermgr
global G_ulockmgr
user = request.form.get('username',None) user = request.form.get('username',None)
if user is None: if user is None:
return json.dumps({'success':'false', 'message':'User is required!'}) return json.dumps({'success':'false', 'message':'User is required!'})
G_ulockmgr.acquire(user)
logger.info ("handle request : stop all clusters for %s" % user) logger.info ("handle request : stop all clusters for %s" % user)
[status, clusterlist] = G_vclustermgr.list_clusters(user) [status, clusterlist] = G_vclustermgr.list_clusters(user)
if status: if status:
for cluster in clusterlist: for cluster in clusterlist:
G_vclustermgr.stop_cluster(cluster,user) G_vclustermgr.stop_cluster(cluster,user)
G_ulockmgr.release(user)
return json.dumps({'success':'true', 'action':'stop all cluster'}) return json.dumps({'success':'true', 'action':'stop all cluster'})
else: else:
G_ulockmgr.release(user)
return json.dumps({'success':'false', 'action':'stop all cluster', 'message':clusterlist}) return json.dumps({'success':'false', 'action':'stop all cluster', 'message':clusterlist})
@app.route("/cluster/flush/", methods=['POST']) @app.route("/cluster/flush/", methods=['POST'])
@ -421,6 +425,7 @@ def deleteproxy(user, beans, form):
@login_required @login_required
def add_port_mapping(user, beans, form): def add_port_mapping(user, beans, form):
global G_vclustermgr global G_vclustermgr
global G_ulockmgr
logger.info ("handle request : add port mapping") logger.info ("handle request : add port mapping")
node_name = form.get("node_name",None) node_name = form.get("node_name",None)
node_ip = form.get("node_ip", None) node_ip = form.get("node_ip", None)
@ -429,7 +434,9 @@ def add_port_mapping(user, beans, form):
if node_name is None or node_ip is None or node_port is None or clustername is None: if node_name is None or node_ip is None or node_port is None or clustername is None:
return json.dumps({'success':'false', 'message': 'Illegal form.'}) return json.dumps({'success':'false', 'message': 'Illegal form.'})
user_info = post_to_user("/user/selfQuery/", data = {"token": form.get("token")}) user_info = post_to_user("/user/selfQuery/", data = {"token": form.get("token")})
G_ulockmgr.acquire(user)
[status, message] = G_vclustermgr.add_port_mapping(user,clustername,node_name,node_ip,node_port,user_info['data']['groupinfo']) [status, message] = G_vclustermgr.add_port_mapping(user,clustername,node_name,node_ip,node_port,user_info['data']['groupinfo'])
G_ulockmgr.release(user)
if status is True: if status is True:
return json.dumps({'success':'true', 'action':'addproxy'}) return json.dumps({'success':'true', 'action':'addproxy'})
else: else:
@ -439,13 +446,16 @@ def add_port_mapping(user, beans, form):
@login_required @login_required
def delete_port_mapping(user, beans, form): def delete_port_mapping(user, beans, form):
global G_vclustermgr global G_vclustermgr
global G_ulockmgr
logger.info ("handle request : delete port mapping") logger.info ("handle request : delete port mapping")
node_name = form.get("node_name",None) node_name = form.get("node_name",None)
clustername = form.get("clustername", None) clustername = form.get("clustername", None)
node_port = form.get("node_port", None) node_port = form.get("node_port", None)
if node_name is None or clustername is None: if node_name is None or clustername is None:
return json.dumps({'success':'false', 'message': 'Illegal form.'}) return json.dumps({'success':'false', 'message': 'Illegal form.'})
G_ulockmgr.acquire(user)
[status, message] = G_vclustermgr.delete_port_mapping(user,clustername,node_name,node_port) [status, message] = G_vclustermgr.delete_port_mapping(user,clustername,node_name,node_port)
G_ulockmgr.release(user)
if status is True: if status is True:
return json.dumps({'success':'true', 'action':'addproxy'}) return json.dumps({'success':'true', 'action':'addproxy'})
else: else:
@ -557,7 +567,7 @@ def listphynodes_monitor(user, beans, form):
return json.dumps({'success':'true', 'monitor':res}) return json.dumps({'success':'true', 'monitor':res})
@app.route("/billing/beans/", methods=['POST']) @app.route("/billing/beans/", methods=['POST'])
#@auth_key_required @auth_key_required
def billing_beans(): def billing_beans():
form = request.form form = request.form
res = post_to_user("/billing/beans/",data=form) res = post_to_user("/billing/beans/",data=form)