Ejemplo n.º 1
0
def get_balancer_for_app(appname, entrypoint):
    records = BalanceRecord.get_by_appname_and_entrypoint(appname, entrypoint)
    if not records:
        return None
    data = {'backend_name': records[0].backend_name}
    data['balancers'] = list(set([r.balancer for r in records]))
    return data
Ejemplo n.º 2
0
def delete_record(record_id):
    r = BalanceRecord.get(record_id)
    if not r:
        return {'msg': 'not found'}, 404

    if g.user.id != r.balancer.user_id:
        return {'msg': 'forbidden'}, 403

    r.delete()

    log = OPLog.create(g.user.id, OPLOG_ACTION.delete_lb_record)
    log.balancer_id = r.balancer_id
    log.record_id = record_id
    log.data = {'domain': r.domain, 'appname': r.appname, 'entrypoint': r.entrypoint}
Ejemplo n.º 3
0
def record_analysis(record_id):
    r = BalanceRecord.get(record_id)
    if not r:
        return {'msg': 'not found'}, 404

    if g.user.id != r.balancer.user_id:
        return {'msg': 'forbidden'}, 403

    if request.method == 'PUT':
        add_record_analysis(r)
    elif request.method == 'DELETE':
        delete_record_analysis(r)

    r.analysis_switch = request.method == 'PUT'
    return {'msg': 'ok'}