示例#1
0
def cluster_node_post(group_id):
    group_id = int(group_id)
    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    numerator = request.form['numerator'].strip()
    denominator = request.form['denominator'].strip()
    endpoint = request.form['endpoint'].strip()
    metric = request.form['metric'].strip()
    tags = request.form['tags'].strip()
    ds_type = 'GAUGE'
    step = request.form['step'].strip()

    msg = required_chk({
        'numerator': numerator,
        'denominator': denominator,
        'endpoint': endpoint,
        'metric': metric,
        'ds_type': ds_type,
        'step': step,
    })

    if msg:
        return jsonify(msg=msg)

    if Cluster.exists('endpoint=%s and metric=%s and tags=%s',
                      [endpoint, metric, tags]):
        return jsonify(msg='%s/%s/%s is already existent' %
                       (endpoint, metric, tags))

    last_id = Cluster.insert({
        'grp_id': group_id,
        'numerator': numerator,
        'denominator': denominator,
        'endpoint': endpoint,
        'metric': metric,
        'tags': tags,
        'ds_type': ds_type,
        'step': step,
        'creator': g.user_name,
    })

    if last_id > 0:
        return jsonify(msg='')
    else:
        return jsonify(msg='occur error')
示例#2
0
文件: cluster.py 项目: Cepave/portal
def cluster_node_post(group_id):
    group_id = int(group_id)
    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    numerator = request.form['numerator'].strip()
    denominator = request.form['denominator'].strip()
    endpoint = request.form['endpoint'].strip()
    metric = request.form['metric'].strip()
    tags = request.form['tags'].strip()
    ds_type = 'GAUGE'
    step = request.form['step'].strip()

    msg = required_chk({
        'numerator': numerator,
        'denominator': denominator,
        'endpoint': endpoint,
        'metric': metric,
        'ds_type': ds_type,
        'step': step,
    })

    if msg:
        return jsonify(msg=msg)

    if Cluster.exists('endpoint=%s and metric=%s and tags=%s', [endpoint, metric, tags]):
        return jsonify(msg='%s/%s/%s is already existent' % (endpoint, metric, tags))

    last_id = Cluster.insert({
        'grp_id': group_id,
        'numerator': numerator,
        'denominator': denominator,
        'endpoint': endpoint,
        'metric': metric,
        'tags': tags,
        'ds_type': ds_type,
        'step': step,
        'creator': g.user_name,
    })

    if last_id > 0:
        return jsonify(msg='')
    else:
        return jsonify(msg='occur error')
示例#3
0
def cluster_edit_post(cluster_id):
    cluster_id = int(cluster_id)
    numerator = request.form['numerator'].strip()
    denominator = request.form['denominator'].strip()
    endpoint = request.form['endpoint'].strip()
    metric = request.form['metric'].strip()
    tags = request.form['tags'].strip()
    ds_type = 'GAUGE'
    step = request.form['step'].strip()
    grp_id = request.form['grp_id'].strip()
    if cluster_id:
        # edit
        if Cluster.exists('endpoint=%s and metric=%s and tags=%s and id<>%s',
                          [endpoint, metric, tags, cluster_id]):
            return jsonify(msg='%s/%s/%s has already existent' %
                           (endpoint, metric, tags))
        Cluster.update_dict(
            {
                'numerator': numerator,
                'denominator': denominator,
                'endpoint': endpoint,
                'metric': metric,
                'tags': tags,
                'ds_type': ds_type,
                'step': step,
            }, 'id=%s', [cluster_id])
    else:
        # clone
        last_id = Cluster.insert({
            'numerator': numerator,
            'denominator': denominator,
            'endpoint': endpoint,
            'metric': metric,
            'tags': tags,
            'ds_type': ds_type,
            'step': step,
            'creator': g.user_name,
            'grp_id': grp_id,
        })

        if last_id <= 0:
            return jsonify(msg='occur error')

    return jsonify(msg='')
示例#4
0
文件: cluster.py 项目: Cepave/portal
def cluster_edit_post(cluster_id):
    cluster_id = int(cluster_id)
    numerator = request.form['numerator'].strip()
    denominator = request.form['denominator'].strip()
    endpoint = request.form['endpoint'].strip()
    metric = request.form['metric'].strip()
    tags = request.form['tags'].strip()
    ds_type = 'GAUGE'
    step = request.form['step'].strip()
    grp_id = request.form['grp_id'].strip()
    if cluster_id:
        # edit
        if Cluster.exists('endpoint=%s and metric=%s and tags=%s and id<>%s', [endpoint, metric, tags, cluster_id]):
            return jsonify(msg='%s/%s/%s has already existent' % (endpoint, metric, tags))
        Cluster.update_dict({
            'numerator': numerator,
            'denominator': denominator,
            'endpoint': endpoint,
            'metric': metric,
            'tags': tags,
            'ds_type': ds_type,
            'step': step,
        }, 'id=%s', [cluster_id])
    else:
        # clone
        last_id = Cluster.insert({
            'numerator': numerator,
            'denominator': denominator,
            'endpoint': endpoint,
            'metric': metric,
            'tags': tags,
            'ds_type': ds_type,
            'step': step,
            'creator': g.user_name,
            'grp_id': grp_id,
        })

        if last_id <= 0:
            return jsonify(msg='occur error')

    return jsonify(msg='')