def resource_update(rid=None): dbproxy = DbProxy() res = dbproxy.get_resource(rid) if res: turn = request.form['turnon'] turnon = False if turn == 'ON': turnon = True status = request.form['status'] href = request.form['href'] dbproxy.update_resource(rid=rid, turnon=turnon, status=status, href=href) flash("Item: ID=[{}] has been updated. {}".format(rid, request.form['status'])) return redirect(url_for('resource_list_page'))
def pc_resource_edit(rid=None): dbproxy = DbProxy() res = dbproxy.get_pc_resource(rid) if res.turnon: res.turnon = 'ON' else: res.turnon = 'OFF' if res: context = { 'resource': res, 'statuses': STATUSES, 'turnon': ['ON', 'OFF'] } return render_template('edit_pc.html', data=context)
def resource_add(): if request.method == 'POST': dbproxy = DbProxy() name = request.form['name'] turn = request.form['turnon'] turnon = False if turn == 'ON': turnon = True status = request.form['status'] href = request.form['href'] dbproxy.add_resource(name=name, turnon=turnon, status=status, href=href) flash("Item: ID=[{}] has been created".format('NA')) return redirect(url_for('resource_list_page'))
def pc_resource_update(rid=None): dbproxy = DbProxy() res = dbproxy.get_pc_resource(rid) if res: turn = request.form['turnon'] turnon = False if turn == 'ON': turnon = True status = request.form['status'] disk_free = request.form['disk_free'] cpu_u = request.form['cpu_u'] dbproxy.update_pc_resource(rid=rid, turnon=turnon, status=status, disk_free=disk_free, cpu_u=cpu_u) flash("Item: ID=[{}] has been updated. {}".format(rid, request.form['status'])) return redirect(url_for('pc_resource_list_page'))
def pc_resource_add(): if request.method == 'POST': dbproxy = DbProxy() ip = request.form['ip'] name = request.form['name'] turn = request.form['turnon'] turnon = False if turn == 'ON': turnon = True status = request.form['status'] disk_free = request.form['disk_free'] cpu_u = request.form['cpu_u'] #date = request.form['date'] #time = request.form['time'] dbproxy.add_pc_resource(ip=ip, name=name, turnon=turnon, status=status, disk_free=disk_free, cpu_u=cpu_u) flash("Item: ID=[{}] has been created".format('NA')) return redirect(url_for('pc_resource_list_page'))
def do_subscribe(): def save_results(queue, steps=1000): subscriber = ZMQSubscriber(queue=queue) while True: if not queue.empty(): raw_msg = queue.get() message = raw_msg # json.loads(raw_msg[6:-1]) logger.debug('message through queue={}'.format(message)) dbproxy.add_web_check(message) else: logger.debug('queue is empty') time.sleep(0.2) dbproxy = DbProxy() subscriber_queue = Queue() subscriber_process = Process(target=save_results, args=(subscriber_queue, )) subscriber_process.start()
def resource_del(rid=None): dbproxy = DbProxy() res = dbproxy.delete_resource(rid=rid) flash("Item: ID=[{}] has been deleted".format(rid)) return redirect(url_for('resource_list_page'))
def resource_list_page(): dbproxy = DbProxy() resources = dbproxy.get_all() # resources = Resource.query.all() context = {'resource': resources} return render_template('index.html', data=context)
def pc_resource_list_page(): dbproxy = DbProxy() resources = dbproxy.get_pc_all() context = {'pc_resource': resources} return render_template('index_pc.html', data=context)
def temperature_list_page(): dbproxy = DbProxy() tempr = dbproxy.get_all() context = {'temperature': tempr} return render_template('index.html', data=context)