From dcb0b91302c7611d9a5246939a5103eb08851227 Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Thu, 18 Aug 2016 18:09:05 +0800 Subject: [PATCH] System will prevent user from creating,starting and scaleouting when beans are less than or equal to zero. --- src/httprest.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/httprest.py b/src/httprest.py index 5fcff40..640af2f 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -53,6 +53,17 @@ def login_required(func): return wrapper +def beans_check(func): + @wraps(func) + def wrapper(*args, **kwargs): + user = args[0] + if user.beans <= 0: + return json.dumps({'success':'false','message':'user\'s beans are less than or equal to zero!'}) + else: + return func(*args, **kwargs) + + return wrapper + @app.route("/login/", methods=['POST']) def login(): global G_usermgr @@ -128,6 +139,7 @@ def register(): @app.route("/cluster/create/", methods=['POST']) @login_required +@beans_check def create_cluster(cur_user, user, form): global G_usermgr global G_vclustermgr @@ -158,6 +170,7 @@ def create_cluster(cur_user, user, form): @app.route("/cluster/scaleout/", methods=['POST']) @login_required +@beans_check def scaleout_cluster(cur_user, user, form): global G_usermgr global G_vclustermgr @@ -204,6 +217,7 @@ def scalein_cluster(cur_user, user, form): @app.route("/cluster/start/", methods=['POST']) @login_required +@beans_check def start_cluster(cur_user, user, form): global G_vclustermgr clustername = form.get('clustername', None)