def add_worker(): if 'authorized' in session and session[ 'authorized'] is True and 'type' in session and session[ 'type'] == 'admin': ScalingTool.spawn_one_instance() dbm = DataBaseManager() uth, dth, ex_ratio, s_ratio, mode = dbm.get_scaling_settings() mode = 'manual' dbm.scaling(str(int(uth)), str(int(dth)), str(int(ex_ratio)), str(int(s_ratio)), mode) return redirect(url_for('admin_main_landing')) return redirect(url_for('index'))
def size_scaling(): if 'authorized' in session and session[ 'authorized'] is True and 'type' in session and session[ 'type'] == 'admin': scale_up_load = request.form.get('uth') scale_down_load = request.form.get('dth') expand_ratio = request.form.get('ex_ratio') shrink_ratio = request.form.get('s_ratio') scale_mode = 'auto' err_msg = [] dbm = DataBaseManager() cpu_metrics = ScalingTool.get_instances_load() if scale_up_load == "" or scale_down_load == "" or expand_ratio == "" or shrink_ratio == "": msg = "Fields cannot be empty" err_msg.append(msg) return render_template('adminhome.html', cpu_metrics=cpu_metrics, err_msg=err_msg, uth=scale_up_load, dth=scale_down_load, ex_ratio=expand_ratio, s_ratio=shrink_ratio) else: if float(scale_up_load) < 0: msg = 'Scale Up Load Should be Greater than 0' err_msg.append(msg) if float(scale_down_load) < 0: msg = 'Scale Down Load Should be Greater than 0' err_msg.append(msg) if float(scale_up_load) < float(scale_down_load): msg = 'Scale Up Load should be Greater than Scale Down Load' err_msg.append(msg) if float(expand_ratio) <= 1: msg = 'Expand Ratio should be Greater than 1' err_msg.append(msg) if float(shrink_ratio) <= 1: msg = 'Shrink Ratio should be Greater than 1' err_msg.append(msg) if not err_msg: dbm.scaling(scale_up_load, scale_down_load, expand_ratio, shrink_ratio, scale_mode) return redirect(url_for('admin_main_landing')) return render_template('adminhome.html', cpu_metrics=cpu_metrics, error=err_msg, uth=scale_up_load, dth=scale_down_load, ex_ratio=expand_ratio, s_ratio=shrink_ratio) return redirect(url_for('index'))